From: John Stultz <john.stultz@linaro.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Colin Cross <ccross@android.com>,
Greg KH <gregkh@linuxfoundation.org>,
Android Kernel Team <kernel-team@android.com>,
John Stultz <john.stultz@linaro.org>
Subject: [PATCH 5/7] staging: ion: Fix overflow and list bugs in system heap
Date: Tue, 4 Feb 2014 16:08:38 -0800 [thread overview]
Message-ID: <1391558920-31590-6-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1391558920-31590-1-git-send-email-john.stultz@linaro.org>
From: Colin Cross <ccross@android.com>
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: Greg KH <gregkh@linuxfoundation.org>
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>
---
drivers/staging/android/ion/ion_system_heap.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/staging/android/ion/ion_system_heap.c b/drivers/staging/android/ion/ion_system_heap.c
index 7f07291..9849f39 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,
info->page = page;
info->order = orders[i];
+ INIT_LIST_HEAD(&info->list);
return info;
}
kfree(info);
@@ -145,12 +146,15 @@ static int ion_system_heap_allocate(struct ion_heap *heap,
struct list_head pages;
struct page_info *info, *tmp_info;
int i = 0;
- long size_remaining = PAGE_ALIGN(size);
+ unsigned long size_remaining = PAGE_ALIGN(size);
unsigned int max_order = orders[0];
if (align > PAGE_SIZE)
return -EINVAL;
+ if (size / PAGE_SIZE > totalram_pages / 2)
+ return -ENOMEM;
+
INIT_LIST_HEAD(&pages);
while (size_remaining > 0) {
info = alloc_largest_available(sys_heap, buffer, size_remaining,
--
1.8.3.2
next prev parent reply other threads:[~2014-02-05 0:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-05 0:08 [PATCHv2 0/7] Staging fixes from the Android tree (for 3.14) John Stultz
2014-02-05 0:08 ` [PATCH 1/7] staging: sw_sync: Add stubs for kernels without CONFIG_SW_SYNC John Stultz
2014-02-05 0:08 ` [PATCH 2/7] staging: sync: Signal pt before sync_timeline object gets destroyed John Stultz
2014-02-05 0:08 ` [PATCH 3/7] staging: sync: Fix a race condition between release_obj and print_obj John Stultz
2014-02-05 0:08 ` [PATCH 4/7] staging: ashmem: Avoid deadlock between read and mmap calls John Stultz
2014-02-05 0:08 ` John Stultz [this message]
2014-02-05 0:08 ` [PATCH 6/7] staging: ion: Fix ION_IOC_FREE compat ioctl John Stultz
2014-02-05 0:08 ` [PATCH 7/7] staging: ion: Fix build warning John Stultz
2014-02-07 17:03 ` [PATCHv2 0/7] Staging fixes from the Android tree (for 3.14) Greg KH
2014-02-07 17:16 ` John Stultz
2014-02-07 17:35 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1391558920-31590-6-git-send-email-john.stultz@linaro.org \
--to=john.stultz@linaro.org \
--cc=ccross@android.com \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®