Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp331007pxb; Thu, 19 Aug 2021 00:07:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyA2JL9YO88KRPOAvg8cbMB7X/S2kfLZjmXSOnUDxEJQdM9Y/iq/pTpZHG3GsZtoEGkW45U X-Received: by 2002:a6b:ba02:: with SMTP id k2mr10532343iof.164.1629356842935; Thu, 19 Aug 2021 00:07:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629356842; cv=none; d=google.com; s=arc-20160816; b=SopZWP5ptmfMYbYgkUNXp7/G/f5JRfmb/17vGHUq9a0QdNS3xmzPrLH7G4xZ4VTgNo yjgAhpjRIAjknTIXOdDm1mAd9ifoXBKP0M1Qfhrv8eJ7ZrIZ9Let/2zUbNrqqJvJdEXc 2FTBkNa3V07EMAQvE9RxboP8MButH2X1Gt84NHb5gBe6WyePZakCMiBJUZK6PSp7hf6B Eb+gqsBhYu0zPhPuMFhm5j5I+wFL4B+hbo2vfnhhTsapeBnRz7k4OsR8iFhWPlYVId+A 4v7XKmuCjzQ1gh/i5YyDaA1ZWbQSzVjdAItQvAosikxyEAzwLYIcUVea+qccUqqAKZYN Jidw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=d24so6mNChjsewh7oprUNrIXD8v7FslbdYVxKPyqYXE=; b=Sbsc2iqO6vU4WxPgnFUXA9P+r81nMD7CMcnNdYGn2PRUE2k25Wf1Vp5T0+TWk9u9Ed oWxUuyayMm9VJOortIPub3yeONevqL2lYfnGbiUsUGymwfoUoiyYVGUCQvhiKni+ZeR7 ODnW8EuLk/25foLOQPurQUcwKIHHTY25bUeMZl87EIGBGOqeNDPXn0PL/YAN3nDGx6aQ C1SMZSBxpAq8G3rQtEWSdmjQ0WQWpnrT29F9Lb4I/3+tcKO+/Br6gpIb7MqV8V3iUc8V C42hUAeBe2cU2llQNRo2U0C/EDZ2Emul2QIqlZmY50m9+c4Fn5H1A8NQ4cf6QjiXcLeg n5Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DyLqmt9L; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t4si2789798iof.69.2021.08.19.00.07.10; Thu, 19 Aug 2021 00:07:22 -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=@chromium.org header.s=google header.b=DyLqmt9L; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231766AbhHSHGx (ORCPT + 99 others); Thu, 19 Aug 2021 03:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231733AbhHSHGv (ORCPT ); Thu, 19 Aug 2021 03:06:51 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95DFEC061756 for ; Thu, 19 Aug 2021 00:06:15 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id k14so4996520pga.13 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=bYYZaX4lHID47yhsrXRHqYQl5260us0/wJYst7tvjB3bxlrwugFa+BfxL399Xngxny 9nN4NARqUkG6ZQhx/KbaeWDm3+/JA48EistBy05LX2DfzhJBbl09fEhI+fFoCiw3W9iL P0nMwvtMcTPD1kuyxJ6XPBx8GaxhjvQGePctlAh3N1VLsALLAA0etUSK9u9XMocWUMf2 nBwFBoZLjuWnj4+IG2K5Aq6V2T2PbtZA9J2jpsdemROMEgvbymo2QcUT1UnldsOm+8Vf 8fJTKN6t5o4QjZpdUZh3KNv0sPCIc8wg9E9YbdDcpHDOn/E6BUREXRgkBP3TTaaFQLAO rUyQ== X-Gm-Message-State: AOAM532KaaVgU0XqRvgoy07kqdtqXy1rbugyUNpkP6fyzFKU31NY8J3V 003bQQa2JTsHilNkDfAXFgXpsg== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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