From patchwork Tue Sep 10 13:16:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 19901 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2028325A72 for ; Tue, 10 Sep 2013 13:16:34 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id c14sf7939435vea.9 for ; Tue, 10 Sep 2013 06:16:33 -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=bd8DPwzVivpj7MXM1jFVwCG/Np+4bLwuizKMGHknm/I=; b=a4L6CFa1XqykFj7EdhZ86MPYEEGkWcP4+ZXq7suiv7Iwc0LFlsaOtdPQj8cYGT8Pzf dI5dl46W4UEt/0LTxSTFul2mFbW8QBKPsozANV9+0oqyreEADmXrvpf14JViHfafddfN k96wuVm7iYoXipIGyMk2Dl0S70b8Kkmws6klZUfCITCqOs2yyZ0ttyfoxDB96jxyYYFw VU64O36O3so2p7Dq7OgdvQPk98sjMZiOu07JE3bY6ZS5ebfPo5fJXILZVuz4yDKvM9Vn obNFnJacvfpxYYn3MZc2I56MmSFygFHvAuKeTY0UJ/pk6ue5Yd8tllRlkM/JGcXKp95e yBDQ== X-Received: by 10.236.176.1 with SMTP id a1mr2882264yhm.10.1378818993769; Tue, 10 Sep 2013 06:16:33 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.119.9 with SMTP id kq9ls2105215qeb.48.gmail; Tue, 10 Sep 2013 06:16:33 -0700 (PDT) X-Received: by 10.52.165.131 with SMTP id yy3mr1445672vdb.25.1378818993533; Tue, 10 Sep 2013 06:16:33 -0700 (PDT) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id dr1si4437563ved.1.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Sep 2013 06:16:33 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.177 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.177; Received: by mail-ve0-f177.google.com with SMTP id db12so4444939veb.36 for ; Tue, 10 Sep 2013 06:16:33 -0700 (PDT) X-Gm-Message-State: ALoCoQmc5NwrVexfoSaSLT/oQvMGy+/aPU33dFo5m+dbNiyenZ/s1NeoQLEP9/ojIgyzFNOA9AQW X-Received: by 10.58.44.37 with SMTP id b5mr22980325vem.4.1378818993454; Tue, 10 Sep 2013 06:16:33 -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 u4csp825vcz; Tue, 10 Sep 2013 06:16:32 -0700 (PDT) X-Received: by 10.194.123.8 with SMTP id lw8mr2498765wjb.40.1378818992274; Tue, 10 Sep 2013 06:16:32 -0700 (PDT) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by mx.google.com with ESMTPS id y2si1555001wia.33.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Sep 2013 06:16:32 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.177 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.212.177; Received: by mail-wi0-f177.google.com with SMTP id cb5so665797wib.4 for ; Tue, 10 Sep 2013 06:16:31 -0700 (PDT) X-Received: by 10.180.74.164 with SMTP id u4mr12817788wiv.17.1378818991578; Tue, 10 Sep 2013 06:16:31 -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 mb7sm3499499wic.10.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 10 Sep 2013 06:16:30 -0700 (PDT) Message-ID: <522F1BAD.7070502@linaro.org> Date: Tue, 10 Sep 2013 14:16:29 +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-ports@sourceware.org CC: patches@linaro.org Subject: [PATCH v3] [BZ #15856] malloc: Check for integer overflow in valloc. 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.177 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 valloc could cause an integer overflow and corrupt allocator internals. Check the overflow does not occur before continuing with the allocation. ChangeLog: 2013-08-16 Will Newton [BZ #15856] * malloc/malloc.c (__libc_valloc): 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 7f43ba3..3148c5f 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3046,6 +3046,13 @@ __libc_valloc(size_t bytes) size_t pagesz = GLRO(dl_pagesize); + /* Check for overflow. */ + if (bytes > SIZE_MAX - 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))