From patchwork Tue Oct 30 10:55:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard Earnshaw \(lists\)" X-Patchwork-Id: 149736 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5290217ljp; Tue, 30 Oct 2018 03:55:47 -0700 (PDT) X-Google-Smtp-Source: AJdET5dCX8ELrCfg20b6yHqiRyuSS2t2TTQtYtv1ZMj/+cNkvPirqmm2qRhZR6oqISfysv6xZHu/ X-Received: by 2002:a63:c54a:: with SMTP id g10-v6mr17145722pgd.201.1540896947066; Tue, 30 Oct 2018 03:55:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540896947; cv=none; d=google.com; s=arc-20160816; b=UH5c5G+pD0gXCtQW9yVrxwlyKF1I4r/yEUb3YQaIE2lmYNZ0rCjrSK8uiXpYWwvPQm qsmbc/6n67+LXHr3IMREEnlGIKIM3+4FTlyviGA5ZvAikMkm/YO4GU3fprMmxRJGLxz2 q/N0YsHyTQCP8ogBA/7BxjPmaosGaMSI2KcBx/zJhDG2ddpDBPyP4APbBAepsJlvpEQV odyzFBeB7VQoRUh9eN5bjaQVjTY/d+gPCWYI+1TJ3cvi2unVj7I+8wir5JuJJ0p37jtx aalHKe5IzV85MPjfYOqPPBz1IVIeGeZVHE6HPXRdwxDATR8LbFiXsc/Zcm4LPWPXRe9Z E5/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:date:message-id:openpgp:subject:from:to :delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature; bh=qrNdvuBlWuhf71x7kS8HUuOLLtNFByiFMAgFdrYqjrM=; b=vm1ovYZHe3DSR2XPA5fIbOYuFstRtqWpB1ZYAoA7/3set080GzsRYaAuFEQCshLDRH wZm7gLsSfVmZuaSoxbLcq79jSjB3ou4W5oopr24Zt4eXHJnxacDFiV9EC1fbO/hkWs+W G/9cHc4NE/iC0ebVoAuGa6ij4wgroHNaKXmkSqXkPk5vmXAQfIfonG3vEmMtfOe8GlaT CHRIyoQcWj3UUGZFlOUwnFGERyw9lCsECnlA2b5QHZMBky/T/3QpzPVvypqSj8m06GOv eoT2mLag7vVZ6/HmBlHllwlfI0za4jDKmfblp9AF5LTC9El141OQfW88kyRaaF79h4hw 5CSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XeXID1WD; spf=pass (google.com: domain of gcc-patches-return-488590-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-488590-patch=linaro.org@gcc.gnu.org" Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id w22-v6si24296384plk.377.2018.10.30.03.55.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Oct 2018 03:55:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-488590-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XeXID1WD; spf=pass (google.com: domain of gcc-patches-return-488590-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="gcc-patches-return-488590-patch=linaro.org@gcc.gnu.org" DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=gwX1jFMktJNEEvch0Ggwbi2GYDnDXlzzNmUr+4zOlAyza3fNHW ZehdtZv1VPYruzSHapmvZ2YO4imcm3j3CBpFhVBTUp89ALrAkfxqBUSjTyBaT6+Y 9+WavqoGtjeftKLrEsoJLtHcxb+MpMzdOh+gC07+/6CWldyYDn+OvumqM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=edxEljA10RfjZR0kDASzVZ7iOrU=; b=XeXID1WDG2PD5FeDBCOj 1SlZjjgkiio7XAfHd5+utU29s67ONOUtqGvM64w16LwHai3w6qoq1X2ipGlYUYXh fZ/Xe3a+LGcwfPgB0TOsc2Nc4TDr/xWbnmaildzdqfpPYn7HTFrZ5537H2RtbQpJ leMwd+6bggfHjkf46EaZ0/w= Received: (qmail 91245 invoked by alias); 30 Oct 2018 10:55:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 91227 invoked by uid 89); 30 Oct 2018 10:55:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 30 Oct 2018 10:55:33 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F13E341; Tue, 30 Oct 2018 03:55:32 -0700 (PDT) Received: from e120077-lin.cambridge.arm.com (e120077-lin.cambridge.arm.com [10.2.206.194]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AD3E33F5D3; Tue, 30 Oct 2018 03:55:31 -0700 (PDT) To: gcc-patches From: "Richard Earnshaw (lists)" Subject: [patch] Don't allow the pool allocator to be configured to allocate zero-sized objects Openpgp: preference=signencrypt Message-ID: <6e5f2b4e-a21b-274a-6bbf-5980ef4d46a8@arm.com> Date: Tue, 30 Oct 2018 10:55:29 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 PR bootstrap/87747 would have been significantly easier to track down if the pool allocator had faulted an attempt to configure it to allocate zero-sized objects. Instead, this slipped through and we later hit memory corruption when the assumed size turned out to be different to the configured size. While, theoretically, there might be a use case for this, it seems unlikely to me that GCC would have such a use. So this patch adds a checking assert that the object size is not zero. * alloc-pool.h (base_pool_allocator ::initialize): Assert that the allocation size is not zero. OK? diff --git a/gcc/alloc-pool.h b/gcc/alloc-pool.h index c0a12920558..d2ee0005761 100644 --- a/gcc/alloc-pool.h +++ b/gcc/alloc-pool.h @@ -256,6 +256,7 @@ base_pool_allocator ::initialize () size_t size = m_size; gcc_checking_assert (m_name); + gcc_checking_assert (m_size); /* Make size large enough to store the list header. */ if (size < sizeof (allocation_pool_list*))