From patchwork Tue Aug 20 08:24:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Newton X-Patchwork-Id: 19345 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gh0-f197.google.com (mail-gh0-f197.google.com [209.85.160.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B51DE2468F for ; Tue, 20 Aug 2013 08:24:44 +0000 (UTC) Received: by mail-gh0-f197.google.com with SMTP id r20sf113811ghr.0 for ; Tue, 20 Aug 2013 01:24:44 -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=nN12wvz/Ka2xCQI3aCypcRl2YpTOoGhzjVJKn49IoTk=; b=PuDIsGhnfrEwQ20VNtoq8aYQeY9PBGFofRsWUyFfrYM6fBbUdkapV/FBWXkQY2TQnx TH3LGyGQw33uUCW2QWCc+raAN5L+SAJeDAaRjYarfL+YfJgOoDVo1NLDq2kLCU4DVTlx MtOePTfXqZv48hjhiZdHz99Pc3Nuhuc1i/Af0ziZO8uOjyTtvvtgJ1PsK6m37GSTgT+d Mig/kw7cfMMtYO1FTo+WdPnFqJllsgaJ6xcDx24a29/skWuPSdHjy9syW79soXLEYUOF vzadTvr746Ux6zxDZmXQzjbiLsKmePUcN/ggGzziygaKyyTqttfLqjFVzpSxUKFCpStf ln2w== X-Received: by 10.236.45.102 with SMTP id o66mr166622yhb.47.1376987084198; Tue, 20 Aug 2013 01:24:44 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.25.2 with SMTP id y2ls128526qef.91.gmail; Tue, 20 Aug 2013 01:24:44 -0700 (PDT) X-Received: by 10.220.74.69 with SMTP id t5mr139793vcj.18.1376987084061; Tue, 20 Aug 2013 01:24:44 -0700 (PDT) Received: from mail-vb0-f48.google.com (mail-vb0-f48.google.com [209.85.212.48]) by mx.google.com with ESMTPS id fb4si97685veb.12.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Aug 2013 01:24:44 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.48 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.48; Received: by mail-vb0-f48.google.com with SMTP id w16so65420vbf.35 for ; Tue, 20 Aug 2013 01:24:44 -0700 (PDT) X-Gm-Message-State: ALoCoQnZsqdfAJioOaFHgU1/4uDZ8JQf9EfsRqLldWFs+1M1A7Fcq5E1s22elOqc5fhfPviwTCto X-Received: by 10.58.152.3 with SMTP id uu3mr137094veb.16.1376987083988; Tue, 20 Aug 2013 01:24:43 -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 u4csp143127vcz; Tue, 20 Aug 2013 01:24:43 -0700 (PDT) X-Received: by 10.14.223.1 with SMTP id u1mr586961eep.10.1376987083075; Tue, 20 Aug 2013 01:24:43 -0700 (PDT) Received: from mail-ea0-f173.google.com (mail-ea0-f173.google.com [209.85.215.173]) by mx.google.com with ESMTPS id f3si379593eet.59.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 20 Aug 2013 01:24:43 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.215.173 is neither permitted nor denied by best guess record for domain of will.newton@linaro.org) client-ip=209.85.215.173; Received: by mail-ea0-f173.google.com with SMTP id g10so58117eak.4 for ; Tue, 20 Aug 2013 01:24:42 -0700 (PDT) X-Received: by 10.14.241.74 with SMTP id f50mr559353eer.29.1376987082426; Tue, 20 Aug 2013 01:24:42 -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 z12sm636944eev.6.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 20 Aug 2013 01:24:41 -0700 (PDT) Message-ID: <521327C7.3020501@linaro.org> Date: Tue, 20 Aug 2013 09:24:39 +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 v2] [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.212.48 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 | 4 ++++ 1 file changed, 4 insertions(+) Changes in v2: - Add BZ number 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))