Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp200091rwd; Wed, 17 May 2023 17:10:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7pC2uwAAeDH/j4VugC0LwKHhAb98JGz6Mk83mszwQzwoYYkHoVt0izZctoCU8xQ4kEmIMh X-Received: by 2002:a17:902:fe18:b0:1ac:93ba:a5ec with SMTP id g24-20020a170902fe1800b001ac93baa5ecmr580807plj.52.1684368608794; Wed, 17 May 2023 17:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684368608; cv=none; d=google.com; s=arc-20160816; b=LoI+edxohnJt8ZrWZ5nozDBAo7Sui/9O7WYwjao2HBV62fkwTkoT7jqBHOjScmcl90 QpeHwZQRRfsUYXtyEm5qceegRBE7Pfy9NIp/Ow2faS86Er4OADzMrBojgAZeWC1RYugc n2TQytA2RWz5x2XhHw+AUeO2zb1dWP7DZCfPEiHkSFkVwtLFFi+ikPbSwx0auqH8UGmM PPGoveRWtxLim3o4A0yYKEdputLtweHDXdpNRWsAO9pK/z2jra07ooM9Ytc4u7/nN4QV ltSElLKtR8tVy7tKTwOL2ekakN5LENnV3SV0sUF6FrYHj1FaEqoQqi7gX08RowE1GpRb Zljw== 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=XNoYyJS/daFy5bbi4AKXuYq1NRM7YZTeNIf9dVYO+40=; b=yrBw5lIRm4Vp55d/kUw/CM8km47eV83mx2tQ+asV5qZdk35XMjG3gIy9sxEQPHk4sV /j5BRoXzwS5nyejwOJUR7+qJKB+fm3FggJxy3dekHcUPh8ez5HtNT4CqB6WZehTSHbXS UxwURhohHrxBO9L0/3IYSQpmWAV0sRjgM1AqHWXnJGkYnTNKYs5Huqf0mweoJklywvsd c3JL3lWrq2UL1WFUkDWeC4KzB6nniKXL07DhvcB9yNs2Mft9D+jbgrFnjGz93bcYa0Pe MY8Z+xv55wz3QzwOJroE9rYkzwMh9BxDlKqp0I3rDOXQH6qTBxF972a7PKdlH4iQ7f/W WF5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fdm8yrzS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ju20-20020a170903429400b001ab0498403fsi21313219plb.169.2023.05.17.17.09.56; Wed, 17 May 2023 17:10:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fdm8yrzS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbjEQXoP (ORCPT + 99 others); Wed, 17 May 2023 19:44:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjEQXoN (ORCPT ); Wed, 17 May 2023 19:44:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61E1849ED; Wed, 17 May 2023 16:44:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DC35A63EAF; Wed, 17 May 2023 23:44:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1E14C433D2; Wed, 17 May 2023 23:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684367051; bh=0vx+j9sbSOwjNIuMmnkABfC9dJnsjhkc0ILcXufRB8Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Fdm8yrzSGlQZA3SDrwgi6BBkkQG6j1pl+ywhXqOT+jEkcm8biQhBR3cN77/nLzwAM dLRyxPgJz743yxWr7WM76cbcJj9XoylVSikGiwFNEZnf+UzLLt7cjDBwVj43Q4YzGQ LTvzPaWUhq9Lo1U9UCmDFYC7wAa12FMGLM0AcPWCIfvhkclUI4HCPL0xL3dQ3BYhdl 5oTO6Kk5ap+2fiDIBhc/k5SX9Vud52xjaXHX7T4qYBrusAZpOLEGTSFehqXJqCckBp 4UUvzqAwziotGGZAf/g1Zzo50mkfwEROxnGG3PNXnmoklJLwptZlb+oCmiEVsOdlyI 9MedMpsXOIk8A== Date: Wed, 17 May 2023 17:45:00 -0600 From: "Gustavo A. R. Silva" To: Kees Cook Cc: Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-kbuild@vger.kernel.org, Tom Rix , linux-kernel@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: Re: [PATCH] kbuild: Enable -fstrict-flex-arrays=3 Message-ID: References: <20230517232801.never.262-kees@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230517232801.never.262-kees@kernel.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 17, 2023 at 04:28:04PM -0700, Kees Cook wrote: > The -fstrict-flex-arrays=3 option is now available with the release > of GCC 13[1] and Clang 16[2]. This feature instructs the compiler to > treat only C99 flexible arrays as dynamically sized for the purposes of > object size calculations. In other words, the ancient practice of using > 1-element arrays, or the GNU extension of using 0-sized arrays, as a > dynamically sized array is disabled. This allows CONFIG_UBSAN_BOUNDS, > CONFIG_FORTIFY_SOURCE, and other object-size aware features to behave > unambiguously in the face of trailing arrays: only C99 flexible arrays > are considered to be dynamically sized. It's happening! :'-) > > Enabling this will help track down any outstanding cases of fake > flexible arrays that need attention in kernel code. > > [1] https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-fstrict-flex-arrays > [2] https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fstrict-flex-arrays > > Cc: Masahiro Yamada > Cc: "Gustavo A. R. Silva" > Cc: Nathan Chancellor > Cc: Nick Desaulniers > Cc: Nicolas Schier > Cc: linux-kbuild@vger.kernel.org > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks! -- Gustavo > --- > Makefile | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/Makefile b/Makefile > index f836936fb4d8..07e5aec1daf5 100644 > --- a/Makefile > +++ b/Makefile > @@ -1026,6 +1026,12 @@ KBUILD_CFLAGS += -Wno-pointer-sign > # globally built with -Wcast-function-type. > KBUILD_CFLAGS += $(call cc-option, -Wcast-function-type) > > +# To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, > +# the kernel uses only C99 flexible arrays for dynamically sized trailing > +# arrays. Enforce this for everything that may examine structure sizes and > +# perform bounds checking. > +KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3) > + > # disable stringop warnings in gcc 8+ > KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) > > -- > 2.34.1 >