From patchwork Tue Sep 10 13:16:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 19899 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 ABD6925A72 for ; Tue, 10 Sep 2013 13:16:23 +0000 (UTC) Received: by mail-qc0-f198.google.com with SMTP id l13sf4396865qcy.9 for ; Tue, 10 Sep 2013 06:16:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:date:from:user-agent :mime-version:to:cc:subject:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=4wDZzGT8Xs8XrASXbHKa42Ri+K9sGkNVOIgMZCFs2+Q=; b=lzFu/gACnGhiELXgQ+V1d0yu2YIJOgFqQJqmmDgRMFr88NXPfYgk9bv/jefRs10nYC rrvsIqssEtXzp3k7Rh9NL5E59eHFyRRA95LEXaE4OPff2ebdAFd9nNWsiD6iwOwEEwkS Po3XL/wwFaGYoLW2czi0tM46Rv+PdLXA1NlnHSO6aJYv6gxrQ0yxnQkjyPDxPRdcHjn4 D57Mvfv8J0TBBJrKxhmiujSv7FrZyG0488RVLLFuGmcood3GId9WsEMJGlzjzW79vom+ h77oVJJftSZtuZiArjJn3Zphgs2wlxhyH1Cn2zDI9rFddjjEBSdMagaJULa2yHMmxhCA cmrA== X-Received: by 10.236.66.244 with SMTP id h80mr8438943yhd.30.1378818983211; Tue, 10 Sep 2013 06:16:23 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.58.244 with SMTP id u20ls2048380qeq.74.gmail; Tue, 10 Sep 2013 06:16:23 -0700 (PDT) X-Received: by 10.58.19.162 with SMTP id g2mr23224616vee.12.1378818982967; Tue, 10 Sep 2013 06:16:22 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id tq4si3867400vdc.155.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Sep 2013 06:16:22 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id oz11so4642407veb.3 for ; Tue, 10 Sep 2013 06:16:22 -0700 (PDT) X-Gm-Message-State: ALoCoQnEssc55A6BJl2eO0uAH9xiHx0VIaiQMucfaQQFb41Esn4TmbYPgNcZr9fKG4KhEp/7e2UT X-Received: by 10.52.164.16 with SMTP id ym16mr151792vdb.39.1378818982901; Tue, 10 Sep 2013 06:16:22 -0700 (PDT) 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 u4csp818vcz; Tue, 10 Sep 2013 06:16:22 -0700 (PDT) X-Received: by 10.194.85.198 with SMTP id j6mr1609885wjz.51.1378818981682; Tue, 10 Sep 2013 06:16:21 -0700 (PDT) Received: from mail-we0-f174.google.com (mail-we0-f174.google.com [74.125.82.174]) by mx.google.com with ESMTPS id c9si6919906wjb.134.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Sep 2013 06:16:21 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.174 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=74.125.82.174; Received: by mail-we0-f174.google.com with SMTP id q58so5438827wes.5 for ; Tue, 10 Sep 2013 06:16:20 -0700 (PDT) X-Received: by 10.180.98.105 with SMTP id eh9mr12766952wib.56.1378818980749; Tue, 10 Sep 2013 06:16:20 -0700 (PDT) Received: from localhost.localdomain (cpc6-seac21-2-0-cust453.7-2.cable.virginmedia.com. [82.1.113.198]) by mx.google.com with ESMTPSA id b13sm3488646wic.9.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 10 Sep 2013 06:16:19 -0700 (PDT) Message-ID: <522F1BA2.9070301@linaro.org> Date: Tue, 10 Sep 2013 14:16:18 +0100 From: Will Newton User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8 MIME-Version: 1.0 To: libc-alpha@sourceware.org CC: patches@linaro.org Subject: [PATCH v3] [BZ #15855] malloc: Check for integer overflow in pvalloc. X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: will.newton@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.172 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: , A large bytes parameter to pvalloc could cause an integer overflow and corrupt allocator internals. Check the overflow does not occur before continuing with the allocation. ChangeLog: 2013-08-12 Will Newton [BZ #15855] * malloc/malloc.c (__libc_pvalloc): Check the value of bytes does not overflow. --- malloc/malloc.c | 7 +++++++ 1 file changed, 7 insertions(+) Changes in v3: - Reorder if condition - Set errno appropriately diff --git a/malloc/malloc.c b/malloc/malloc.c index dd295f5..7f43ba3 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3082,6 +3082,13 @@ __libc_pvalloc(size_t bytes) size_t page_mask = GLRO(dl_pagesize) - 1; size_t rounded_bytes = (bytes + page_mask) & ~(page_mask); + /* Check for overflow. */ + if (bytes > SIZE_MAX - 2*pagesz - MINSIZE) + { + __set_errno (ENOMEM); + return 0; + } + void *(*hook) (size_t, size_t, const void *) = force_reg (__memalign_hook); if (__builtin_expect (hook != NULL, 0))