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=-11.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 A877DC4338F for ; Thu, 19 Aug 2021 07:06:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3C52061056 for ; Thu, 19 Aug 2021 07:06:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3C52061056 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id CF3EE6B006C; Thu, 19 Aug 2021 03:06:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7CEC6B0071; Thu, 19 Aug 2021 03:06:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B44828D0001; Thu, 19 Aug 2021 03:06:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id 97C486B006C for ; Thu, 19 Aug 2021 03:06:16 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 46448180AD83E for ; Thu, 19 Aug 2021 07:06:16 +0000 (UTC) X-FDA: 78490946352.38.71A8DF9 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf27.hostedemail.com (Postfix) with ESMTP id F37707001F48 for ; Thu, 19 Aug 2021 07:06:15 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id n18so4998773pgm.12 for ; Thu, 19 Aug 2021 00:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=d24so6mNChjsewh7oprUNrIXD8v7FslbdYVxKPyqYXE=; b=DyLqmt9LUhYdSkTem3sk80Ub972E9Yc34wRhRboTlhx4Wi197NhVlo9UIczj48j3G/ T8LhjLSvY9bLxUXt5J8rfqL9ww45Z/xfGnuHCc+vO85k9hAriU/EMv40HMdb9qspahzo S2EfzmOod7IkH20hhWfU+uUep+/Q/ov0rdSZc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=d24so6mNChjsewh7oprUNrIXD8v7FslbdYVxKPyqYXE=; b=RlHhyatqVsgJIbbpwqC6oLwnBhOS4FjKYso9kRWad7bD/KXy25cRW6aql28Neerrzs UJUUgcq07MhgstzWugA0ZnHC/RVep+Rp4StE22RvpbQKNfzPOck5j42uyFzK2E1B/2KR uJClb8mRPO/c9uDWIU3Gwv0QRRwjZy8ShWooFcBetRn6XoFViVHgKj48mkFLZDXmbbr+ Ql36a/0A6vj5CSFXTYErDq5HOIz8eDsq3NjaYOQ1iVsYomA9LHHMw8SWY+7MyAxlSiBB K9wxRYSBWIwiuk3GnJfFxiI7RqgxpbKHWYwQNjEnvTNRJ73JZRaUWCaAPUURk2zcdahm 48aQ== X-Gm-Message-State: AOAM531fB3Jus3zO6HuSc/GrkvMPrzkXLdb+lPGFQeicVNLB/xjsDHy3 1Y0shZF2TWx4x/daj7KUyRMdcw== X-Google-Smtp-Source: ABdhPJx1+T7gxYGQvh03cW7Q6zygQHgK4Kd6rH9nkFHFAtaDVXPPqWIrIytEky+POIK2WoZyqkUhwg== X-Received: by 2002:a05:6a00:1a4f:b0:3e2:1f86:3235 with SMTP id h15-20020a056a001a4f00b003e21f863235mr13086054pfv.26.1629356775079; Thu, 19 Aug 2021 00:06:15 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a8sm2027703pfo.79.2021.08.19.00.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 00:06:14 -0700 (PDT) Date: Thu, 19 Aug 2021 00:06:13 -0700 From: Kees Cook To: Andrew Morton 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: <202108190003.37FF2F1D7@keescook> References: <20210818214021.2476230-1-keescook@chromium.org> <20210818214021.2476230-2-keescook@chromium.org> <20210818161912.f14722707e06de1f046e948d@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210818161912.f14722707e06de1f046e948d@linux-foundation.org> Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=DyLqmt9L; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf27.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.169 as permitted sender) smtp.mailfrom=keescook@chromium.org X-Stat-Signature: beiz65mg3eztthrmff1hq6k5wxwhp7do X-Rspamd-Queue-Id: F37707001F48 X-Rspamd-Server: rspam01 X-HE-Tag: 1629356775-909746 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Aug 18, 2021 at 04:19:12PM -0700, Andrew Morton wrote: > 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 Oh, er, where did "Makefile: remove stale cc-option checks" go? Ah, I see now: https://lore.kernel.org/mm-commits/20210814215814.W_qqW%25akpm@linux-foundation.org/T/#u Looks like I just happened to pick the wrong linux-next. ;) Thanks for the fix-up! -- Kees Cook