From patchwork Mon Feb 3 18:16:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 24058 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DAB07202B2 for ; Mon, 3 Feb 2014 18:17:00 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id c9sf18671148qcz.9 for ; Mon, 03 Feb 2014 10:17:00 -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=c2ch8sAXOFUHNmS91gbGZ2Bh91ths7+S4zP3PZap+LdnUjE5Uu+PDo+1x3gosUPvNY w6isCp4bVT8upJsz/5PgivLw4HFwAUlsYVztHxuGjiEy6rIQcoUc74IlBvIRNmkXKW+A NMR7YyyrybIzM+DQSUsIrtCNl7ZiwGvt+zcQmwQDzuuKtGN14AUyYAJdYafsoTFtb2xn p8OwkCWRVJwdLJEGOoidSnxcXnMhsSLbszc8w7hYZGLSdwc3+LkfoLoESH2A8iQxJjeL JBu/ohnFTrJ9ND+YKZ4slCDFJ4YSNcOJaghZS9c5b/lQbTHozpO0YlEZIw9TU86FME5P euvg== X-Gm-Message-State: ALoCoQkSckB5/QoN3ffW2PEA9nGF3k75A4r8i/qiblFon+A/9yuxN9735qFveCWUP2urD0/rxfli X-Received: by 10.236.149.198 with SMTP id x46mr13779369yhj.7.1391451419920; Mon, 03 Feb 2014 10:16:59 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.41.202 with SMTP id z68ls1991833qgz.85.gmail; Mon, 03 Feb 2014 10:16:59 -0800 (PST) X-Received: by 10.52.185.196 with SMTP id fe4mr4910455vdc.27.1391451419839; Mon, 03 Feb 2014 10:16:59 -0800 (PST) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id x5si7033600veb.73.2014.02.03.10.16.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Feb 2014 10:16:59 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.180 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.180; Received: by mail-vc0-f180.google.com with SMTP id ks9so5090944vcb.11 for ; Mon, 03 Feb 2014 10:16:59 -0800 (PST) X-Received: by 10.58.86.230 with SMTP id s6mr29335410vez.16.1391451419758; Mon, 03 Feb 2014 10:16:59 -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 u4csp174199vcz; Mon, 3 Feb 2014 10:16:58 -0800 (PST) X-Received: by 10.66.142.107 with SMTP id rv11mr39064329pab.17.1391451418503; Mon, 03 Feb 2014 10:16:58 -0800 (PST) Received: from mail-pd0-f179.google.com (mail-pd0-f179.google.com [209.85.192.179]) by mx.google.com with ESMTPS id sj5si21527575pab.23.2014.02.03.10.16.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Feb 2014 10:16:58 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.179 is neither permitted nor denied by best guess record for domain of john.stultz@linaro.org) client-ip=209.85.192.179; Received: by mail-pd0-f179.google.com with SMTP id q10so7192748pdj.38 for ; Mon, 03 Feb 2014 10:16:50 -0800 (PST) X-Received: by 10.68.212.10 with SMTP id ng10mr39074699pbc.95.1391451410604; Mon, 03 Feb 2014 10:16:50 -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 y9sm150496099pas.10.2014.02.03.10.16.49 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 03 Feb 2014 10:16:50 -0800 (PST) From: John Stultz To: LKML Cc: Colin Cross , Greg KH , Android Kernel Team , John Stultz Subject: [PATCH 13/16] staging: ion: Fix overflow and list bugs in system heap Date: Mon, 3 Feb 2014 10:16:25 -0800 Message-Id: <1391451388-23906-14-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1391451388-23906-1-git-send-email-john.stultz@linaro.org> References: <1391451388-23906-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.180 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,