From patchwork Wed Feb 5 00:08:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 24152 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B2EFF202FA for ; Wed, 5 Feb 2014 00:09:21 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id h16sf41565049oag.4 for ; Tue, 04 Feb 2014 16:09:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=KvQhBpHzgn1ZLL2jt+2+DGPRLOb55Z16wGSa/y5q7yM=; b=NG1sp09kEgQMAARLqMTpPY80TO1844wifhZFQ92As1CT3bE7zO/KWAh4WccJnRnGMv v0LOYYlqBjEAhsD+kPYDIRkHjLrn149DDqQT0/U7ZAgXzdOhTGuAOcAO0DFQIIikRAWX 1TGbvCXt/etpCUqP90jmXCyk/sRdBJcj8GPtPWvItnHJd9gwWlnvEJPwDlbFqtLp2Us0 JKwF0rM354nU3eKRdwp5h4aSJ4+mF4kPTFbInGMrvZJ/HHqzf0ocFhgamofa5BsXuAhs Wv15PclaWT1ERrhF2nf7gd/aZqfaTuCzLG0fao2UMtYfUpyrKtvX7ao5h7SfPivt1vc5 R+1w== X-Gm-Message-State: ALoCoQmjFJxZehhNmnykvIdNXHip48kTlKkj1TxZ1/Ei0VCThRAj9UTCWlDSKfx7e9ZY3+bTWjiX X-Received: by 10.182.118.194 with SMTP id ko2mr17439138obb.32.1391558960780; Tue, 04 Feb 2014 16:09:20 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.43.201 with SMTP id e67ls2448424qga.32.gmail; Tue, 04 Feb 2014 16:09:20 -0800 (PST) X-Received: by 10.52.227.193 with SMTP id sc1mr15919797vdc.1.1391558960690; Tue, 04 Feb 2014 16:09:20 -0800 (PST) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id n8si8972840vdv.42.2014.02.04.16.09.20 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 16:09:20 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id hq11so6598453vcb.28 for ; Tue, 04 Feb 2014 16:09:20 -0800 (PST) X-Received: by 10.58.170.69 with SMTP id ak5mr3160873vec.28.1391558960581; Tue, 04 Feb 2014 16:09:20 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp4088vcz; Tue, 4 Feb 2014 16:09:20 -0800 (PST) X-Received: by 10.66.160.195 with SMTP id xm3mr46691384pab.93.1391558959620; Tue, 04 Feb 2014 16:09:19 -0800 (PST) Received: from mail-pd0-f172.google.com (mail-pd0-f172.google.com [209.85.192.172]) by mx.google.com with ESMTPS id fb4si2054544pbb.22.2014.02.04.16.09.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 16:09:19 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.172 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.172; Received: by mail-pd0-f172.google.com with SMTP id p10so8839290pdj.17 for ; Tue, 04 Feb 2014 16:09:19 -0800 (PST) X-Received: by 10.66.145.166 with SMTP id sv6mr47616395pab.31.1391558959224; Tue, 04 Feb 2014 16:09:19 -0800 (PST) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id g6sm181483447pat.2.2014.02.04.16.09.18 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Feb 2014 16:09:18 -0800 (PST) From: John Stultz To: LKML Cc: Colin Cross , Greg KH , Android Kernel Team , John Stultz Subject: [PATCH 5/7] staging: ion: Fix overflow and list bugs in system heap Date: Tue, 4 Feb 2014 16:08:38 -0800 Message-Id: <1391558920-31590-6-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391558920-31590-1-git-send-email-john.stultz@linaro.org> References: <1391558920-31590-1-git-send-email-john.stultz@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Colin Cross 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 Cc: Colin Cross Cc: Android Kernel Team Signed-off-by: Colin Cross [jstultz: Minor commit subject tweak] Signed-off-by: John Stultz --- 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,