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=unavailable 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 3BC38C432BE for ; Thu, 19 Aug 2021 07:06:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D88C61042 for ; Thu, 19 Aug 2021 07:06:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231945AbhHSHGx (ORCPT ); Thu, 19 Aug 2021 03:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231722AbhHSHGv (ORCPT ); Thu, 19 Aug 2021 03:06:51 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88719C061575 for ; Thu, 19 Aug 2021 00:06:15 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id o2so4999630pgr.9 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=WHmXBqEoDHJVUCRYmTZ9OJuMnrt+5nN63ZEU5Vju3M4/C1qPNnD5FyGkwS2AX0sLj8 PoeKQXOmFcRYHF3g2qsXmVcYwX4gsM0rq8NkjRm0iGnh8AcxN3H3Ercd1MXqRxl8HVCY 3OUjg7deML8DqUt5dNw9o/tVfIxr4AiDEWZukmj+Y39JIheLpkIODYmVp/09cwhpD0Q8 hVJvAe1VpR6E+6VS/GlVbsQW++U9t4hVDqM7QqF9ZTeEX8y7HOPepX8p3a/pS6w43e5R nxS4ZTJDTXn//TD7zyyH/2tsmvf765YymdjA7PBVWnUorh67h6xBYiR6r4G+x/URuTft vwvQ== X-Gm-Message-State: AOAM531viIprvl/OAfq6fajORdZSjvo7XjPKUQLpaF1HwlG5wcHRtFQ6 pj622GFPD4A5u7PpeMZ6T0jdnA== 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> Precedence: bulk List-ID: X-Mailing-List: linux-hardening@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