Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp73955pxb; Wed, 18 Aug 2021 16:21:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxspYj0748Ijm6TMOcEyPzeSKqgiUmA9n0H5gkdf+/JrzIyo4xQQ/LvkGHF1hDE4p1cqNwP X-Received: by 2002:a6b:f114:: with SMTP id e20mr1079656iog.41.1629328901647; Wed, 18 Aug 2021 16:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629328901; cv=none; d=google.com; s=arc-20160816; b=Bonk3YcAfkcDx0w3kH0oSxloC9fbJUuOsiB46HYtjBcFgUJLYPFxAaRKOTTMefcuoA ZbFG4tcdfb1/viPlH+PfnNhqnHlo8YqqGK46ApRdBm74Q5mUSxvBQtmnHpM3X0uvdFkV Ht7NTzR0XPx3DOM5oNbJpfKPZ+/GVA9OUUwnFe7LDHKf7IJaoULo+r/EMOl2T129sENo /fBQmsAdWC/OWuUXGYKRVUB+LW83IwObn3ausZIZkMdrHp5mC7PGRyv+pQdEBWbxg6rj H2bCUr3GE7s7xE4xhFSTeFBR4uFFzH5nMtP1Ue8Ay5FqKIQbYJfDu1CuORnqekfGLgia e+aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=6tkB20YyNzz/ZA8WcnKUWHNzQp7OKISJkQLIJOLRw/8=; b=xymv5/CdtaZqR3UPo3ppwhFMgwv490JSFu93Y9NE9qgbiztdPybI8jCPV+kn8PnNg4 lF4cOY2g0/nbdwssVD/y3ldQcwrnT1XbyL8tF6oL/6CoGoKeb/6o6WEP9mMjAgxVGQbX lAbM7JXhQt1ZWzHOkBTEebyHCTLQnuTNDM4SgA3Kx2iR+mc+J4DymbbFPYPToKudXtdT qsUoHBEg/0uz1onGreKK1X3waIfUSrJDUwBN49u7xvVvs109f9mtvVLICDHKopz5Vesx zqyPZ8dpGivyTF/RADkKkIS/QKA1H6kmCICbREJ0d4a84tTAzcj54p9Fz8baLEzbJZsX dSbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=g5WQ5XEK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b41si1171520jav.121.2021.08.18.16.21.29; Wed, 18 Aug 2021 16:21:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=g5WQ5XEK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234794AbhHRXTt (ORCPT + 99 others); Wed, 18 Aug 2021 19:19:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:36082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234791AbhHRXTs (ORCPT ); Wed, 18 Aug 2021 19:19:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 80EE36109F; Wed, 18 Aug 2021 23:19:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1629328753; bh=yTnTdUc2FJ+hnloFknl4xzYCBGT0SKFtOXGmR2H+Gcc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=g5WQ5XEKuqNkZvg501/hNDfCi1BlX7V+Oxm7YQsoC9u8SKDmi2hIfJkyZ7Dw5bByJ aRsxrH+mToBBVxnAGWKoYrAU/Vb6aVRdYbk6Em/zj3tKecYvijnejNzbMKVLIWeX3A 6Ddg2jhv+0FOyxn8lVSeWg3SHzSJsJIIdT+d8NkI= Date: Wed, 18 Aug 2021 16:19:12 -0700 From: Andrew Morton To: Kees Cook Cc: linux-kernel@vger.kernel.org, Miguel Ojeda , Nathan Chancellor , Nick Desaulniers , clang-built-linux@googlegroups.com, Joe Perches , Andy Whitcroft , Dwaipayan Ray , Lukas Bulwahn , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , Daniel Micay , Dennis Zhou , Tejun Heo , Masahiro Yamada , Michal Marek , linux-mm@kvack.org, linux-kbuild@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 1/7] Compiler Attributes: Add __alloc_size() for better bounds checking Message-Id: <20210818161912.f14722707e06de1f046e948d@linux-foundation.org> In-Reply-To: <20210818214021.2476230-2-keescook@chromium.org> References: <20210818214021.2476230-1-keescook@chromium.org> <20210818214021.2476230-2-keescook@chromium.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 18 Aug 2021 14:40:15 -0700 Kees Cook wrote: > GCC and Clang can use the "alloc_size" attribute to better inform the > results of __builtin_object_size() (for compile-time constant values). > Clang can additionally use alloc_size to inform the results of > __builtin_dynamic_object_size() (for run-time values). > > Because GCC sees the frequent use of struct_size() as an allocator size > argument, and notices it can return SIZE_MAX (the overflow indication), > it complains about these call sites may overflow (since SIZE_MAX is > greater than the default -Walloc-size-larger-than=PTRDIFF_MAX). This > isn't helpful since we already know a SIZE_MAX will be caught at run-time > (this was an intentional design). Instead, just disable this check as > it is both a false positive and redundant. (Clang does not have this > warning option.) > > ... > > --- a/Makefile > +++ b/Makefile > @@ -1078,9 +1078,13 @@ KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow) > # Another good warning that we'll want to enable eventually > KBUILD_CFLAGS += $(call cc-disable-warning, restrict) > > -# Enabled with W=2, disabled by default as noisy > ifdef CONFIG_CC_IS_GCC > +# Enabled with W=2, disabled by default as noisy > KBUILD_CFLAGS += -Wno-maybe-uninitialized > + > +# The allocators already balk at large sizes, so silence the compiler > +# warnings for bounds checks involving those possible values. > +KBUILD_CFLAGS += -Wno-alloc-size-larger-than > endif > > # disable invalid "can't wrap" optimizations for signed / pointers Makefile has changed. I did this: --- a/Makefile~compiler-attributes-add-__alloc_size-for-better-bounds-checking +++ a/Makefile @@ -1003,6 +1003,12 @@ KBUILD_CFLAGS += $(call cc-disable-warni # Enabled with W=2, disabled by default as noisy KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized) +ifdef CONFIG_CC_IS_GCC +# The allocators already balk at large sizes, so silence the compiler +# warnings for bounds checks involving those possible values. +KBUILD_CFLAGS += -Wno-alloc-size-larger-than +endif + # disable invalid "can't wrap" optimizations for signed / pointers KBUILD_CFLAGS += -fno-strict-overflow _