diff options
author | Colin Cross <ccross@android.com> | 2014-02-04 19:08:38 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-07 12:03:16 -0500 |
commit | c9e8440eca61298ecccbb27f53036124a7a3c6c8 (patch) | |
tree | 1c29263f6a2ecc828b98293646d8c18381965bed /drivers/staging | |
parent | 077f6db9731673753ca41a5c3acbb5ead142658a (diff) |
staging: ion: Fix overflow and list bugs in system heap
Fix a few bugs in ion_system_heap:
Initialize the list node in the info block.
Don't store size_remaining in a signed long, allocating >2GB
could overflow, resulting in a call to sg_alloc_table with
nents=0 which panics. alloc_largest_available will never
return a block larger than size_remanining, so it can never
go negative.
Limit a single allocation to half of all memory. Prevents a
large allocation from taking down the whole system.
Cc: Colin Cross <ccross@android.com>
Cc: Android Kernel Team <kernel-team@android.com>
Signed-off-by: Colin Cross <ccross@android.com>
[jstultz: Minor commit subject tweak]
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/android/ion/ion_system_heap.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c index 7f0729130d65..9849f3963e75 100644 --- a/drivers/staging/android/ion/ion_system_heap.c +++ b/drivers/staging/android/ion/ion_system_heap.c | |||
@@ -124,6 +124,7 @@ static struct page_info *alloc_largest_available(struct ion_system_heap *heap, | |||
124 | 124 | ||
125 | info->page = page; | 125 | info->page = page; |
126 | info->order = orders[i]; | 126 | info->order = orders[i]; |
127 | INIT_LIST_HEAD(&info->list); | ||
127 | return info; | 128 | return info; |
128 | } | 129 | } |
129 | kfree(info); | 130 | kfree(info); |
@@ -145,12 +146,15 @@ static int ion_system_heap_allocate(struct ion_heap *heap, | |||
145 | struct list_head pages; | 146 | struct list_head pages; |
146 | struct page_info *info, *tmp_info; | 147 | struct page_info *info, *tmp_info; |
147 | int i = 0; | 148 | int i = 0; |
148 | long size_remaining = PAGE_ALIGN(size); | 149 | unsigned long size_remaining = PAGE_ALIGN(size); |
149 | unsigned int max_order = orders[0]; | 150 | unsigned int max_order = orders[0]; |
150 | 151 | ||
151 | if (align > PAGE_SIZE) | 152 | if (align > PAGE_SIZE) |
152 | return -EINVAL; | 153 | return -EINVAL; |
153 | 154 | ||
155 | if (size / PAGE_SIZE > totalram_pages / 2) | ||
156 | return -ENOMEM; | ||
157 | |||
154 | INIT_LIST_HEAD(&pages); | 158 | INIT_LIST_HEAD(&pages); |
155 | while (size_remaining > 0) { | 159 | while (size_remaining > 0) { |
156 | info = alloc_largest_available(sys_heap, buffer, size_remaining, | 160 | info = alloc_largest_available(sys_heap, buffer, size_remaining, |