From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01B3CC4338F for ; Wed, 18 Aug 2021 23:19:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DCEBA610D2 for ; Wed, 18 Aug 2021 23:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234834AbhHRXTt (ORCPT ); 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-hardening@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 _