From patchwork Mon Aug 19 19:46:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 19332 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f197.google.com (mail-vc0-f197.google.com [209.85.220.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 418DB2469E for ; Mon, 19 Aug 2013 19:46:46 +0000 (UTC) Received: by mail-vc0-f197.google.com with SMTP id ha11sf5991157vcb.4 for ; Mon, 19 Aug 2013 12:46:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; 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=chCdsvLm3cS6Df5tDlTvyEvAEGRg4o3R2Wh8rJm9mm8=; b=CyomNL9Tfyalbx6dP7yrFHCAkzSYN2Hg26fLoQpDQs4Iw9F2zb/F2Z/9OJ+SwsqQqu 7U8j53e72TXRqfzUatJsDQhXx2MbY+aFqc3RC03ezgUCMPilLL9nKQuPEeSMXGaP9xqg TP51OgEMcQs4Q5NUzVlqIDClqh4QxXXUD9NLh9tsa8BJYMze2BoT8hvccKdNHWpm1S+n nQoAGVDvCnRAQNdFgwj+z663DlYG6nokoUHQqP86gL7wyJWYRlFLnS1K6fM8k3F+jG6S +SMWI1NSSMHtMgL5gKTFZynUt4fBiStmHbCq0SJVWsqesNUKtE6Cv5P0mRS2DTuFuePP WTSw== X-Received: by 10.236.77.135 with SMTP id d7mr1507896yhe.49.1376941605664; Mon, 19 Aug 2013 12:46:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.4.41 with SMTP id h9ls506755qeh.79.gmail; Mon, 19 Aug 2013 12:46:45 -0700 (PDT) X-Received: by 10.52.120.114 with SMTP id lb18mr6520234vdb.23.1376941605542; Mon, 19 Aug 2013 12:46:45 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id ix2si2715813vdb.150.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 Aug 2013 12:46:45 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.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.220.172; Received: by mail-vc0-f172.google.com with SMTP id m17so3428530vca.3 for ; Mon, 19 Aug 2013 12:46:45 -0700 (PDT) X-Gm-Message-State: ALoCoQn+oMspDDe0IF0okcKMRj7ucwgZrqavmK266W5HruSBfwXc2ktq6u2x0IpyLpWcJWyRxMLn X-Received: by 10.58.137.167 with SMTP id qj7mr14772239veb.1.1376941605433; Mon, 19 Aug 2013 12:46:45 -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 u4csp114167vcz; Mon, 19 Aug 2013 12:46:44 -0700 (PDT) X-Received: by 10.14.183.2 with SMTP id p2mr15401055eem.44.1376941604526; Mon, 19 Aug 2013 12:46:44 -0700 (PDT) Received: from mail-ea0-f180.google.com (mail-ea0-f180.google.com [209.85.215.180]) by mx.google.com with ESMTPS id z8si11028678eee.293.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 19 Aug 2013 12:46:44 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.180 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.215.180; Received: by mail-ea0-f180.google.com with SMTP id h10so2517926eaj.11 for ; Mon, 19 Aug 2013 12:46:43 -0700 (PDT) X-Received: by 10.15.94.201 with SMTP id bb49mr25511620eeb.23.1376941603846; Mon, 19 Aug 2013 12:46:43 -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 m54sm19532818eex.2.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 19 Aug 2013 12:46:42 -0700 (PDT) Message-ID: <52127621.3030106@linaro.org> Date: Mon, 19 Aug 2013 20:46:41 +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 1/7] malloc/malloc.c: 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.220.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 * malloc/malloc.c (__libc_pvalloc): Check the value of bytes does not overflow. --- malloc/malloc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/malloc/malloc.c b/malloc/malloc.c index be472b2..7468758 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3082,6 +3082,10 @@ __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 + 2*pagesz + MINSIZE < bytes) + return 0; + void *(*hook) (size_t, size_t, const void *) = force_reg (__memalign_hook); if (__builtin_expect (hook != NULL, 0))