Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp960396pxb; Tue, 14 Sep 2021 12:37:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhuH3lsZnfneQRu7aYgOtek1s2uQCXx9KYudjP/4FNjSXnp297oZ+ZNVSCwdPVdsGDmDRl X-Received: by 2002:a92:d5c5:: with SMTP id d5mr5884701ilq.36.1631648260777; Tue, 14 Sep 2021 12:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631648260; cv=none; d=google.com; s=arc-20160816; b=RWG00fAbQXDg61qNRveMcy/zySGI1z/ND9Xb4/hbdabz8CE+8pb8oYVEifw2biAqrn NWhSWibHVO40WRUL2BRV8h0jRuIwabCFpAh0SDQWMmNo7nuEo993uOj+ZTBGBNfVL16/ 89Ef5qxZmNGjb4HALtVREDrRYMUe172GbfscVbhc1inB2E4SI9VHAi4VWmH7Q8WI2/Us 4j5k+9A5t65Xnxiaoh+sgSMsD/uaAaiv0JV93DMnh4xq65e39SjNRVkHHj664ShCAr+i KFUEf53XYe0QpzxkDExWd05I7Lr3Jn0erCYr1YDOaqLwf8h071X1NwrJjaUhwU4lZhXu av5w== 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=peJF31oowWYhpyFyVoCP2Y9RM3iiBqsAlLbWRQYvC7U=; b=0V3UY8LMwua0a+1bllxlxO2ovmFu5olKu/CQHRWfGStuFAG085FV7z34hUTHO8SlWC KmO6zuRwcmWlrVIwHETGeHbn9ykm/JZmsrfjQGIT7lXPblUTaWPk+6SxiMer+Mb2k6kQ CI8+3H4b9eoTIy0gaPXTOauA/YXm6hjpyVIoWjaGMF3TJq1vCga710bXvrP/BkDS4XWB YYFjtz7rYJkkZQXcGaeo/0pejAC8t3zFNl4i5aICgMVHhppX/cF62wbLBNG12aS4jE+J KamtN20LE3Dcj5j6OKta2BvRRyeidjabfYprES5seAlb1NEmCBk/V1ny7IpZWWBNBKxN 189w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oEQovUoh; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q35si9662024jac.78.2021.09.14.12.37.26; Tue, 14 Sep 2021 12:37:40 -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=@kernel.org header.s=k20201202 header.b=oEQovUoh; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232832AbhINTiB (ORCPT + 99 others); Tue, 14 Sep 2021 15:38:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:53598 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232252AbhINTiA (ORCPT ); Tue, 14 Sep 2021 15:38:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4759E60F11; Tue, 14 Sep 2021 19:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631648203; bh=EpYP61q3ILFoGQehdJpA1cuxI7Ow2PsbWkjVVP/DSWk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=oEQovUohmeVzk4AWLjKtD13AF1Y5tRPrZOKpzagZjGUnN3IbMkBIw0Eicrm9WeM8W K8mubn2O5qEdscjrdZ8jdXTgecynE8GYPAuw9+NnSgkh7jYtEKzvj1Lye6gdlTkO4L 7OU9QdpQZEIpbOf/Wu1XUR8CWHgdui+L6MC6GWI2lvtedMQZNQN9yEa5XRrqQJjMqh mUaJWv6Ue20zNTtYzc3zm8qgesE08xVjHVgeC49AlCpvMrNhhDbGLtve7eVlAzby3D htT95osIKAV22cd5Y9/wpJkLXHqxEbGctV2tj1FEk06TY3RhMSpXSV8Lvf9xi9hcUz 2XbDuIISb7rOw== Date: Tue, 14 Sep 2021 12:36:37 -0700 From: Nathan Chancellor To: Kees Cook Cc: Nick Desaulniers , Will Deacon , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, "Gustavo A . R . Silva" , Greg Kroah-Hartman Subject: Re: [PATCH] hardening: Default to INIT_STACK_ALL_ZERO if CC_HAS_AUTO_VAR_INIT_ZERO Message-ID: References: <20210914102837.6172-1-will@kernel.org> <01f572ab-bea2-f246-2f77-2f119056db84@kernel.org> <202109140958.11DCC6B6@keescook> <202109141214.630BB3A@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202109141214.630BB3A@keescook> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 14, 2021 at 12:14:47PM -0700, Kees Cook wrote: > On Tue, Sep 14, 2021 at 11:53:38AM -0700, Nick Desaulniers wrote: > > Rather than create 2 new kconfigs with 1 new invocation of the > > compiler via cc-option, how about just adding an `ifdef > > CONFIG_CC_IS_CLANG` guard around adding the obnoxious flag to > > `KBUILD_CFLAGS` in the top level Makefile? > > v2: Thanks for clarifying! (since I did not actually test before making the comment...) Reviewed-by: Nathan Chancellor > diff --git a/Makefile b/Makefile > index 34a0afc3a8eb..72d165ffabdb 100644 > --- a/Makefile > +++ b/Makefile > @@ -831,12 +831,12 @@ endif > > # Initialize all stack variables with a zero value. > ifdef CONFIG_INIT_STACK_ALL_ZERO > -# Future support for zero initialization is still being debated, see > -# https://bugs.llvm.org/show_bug.cgi?id=45497. These flags are subject to being > -# renamed or dropped. > KBUILD_CFLAGS += -ftrivial-auto-var-init=zero > +ifdef CONFIG_CC_IS_CLANG > +# https://bugs.llvm.org/show_bug.cgi?id=45497 > KBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang > endif > +endif > > # While VLAs have been removed, GCC produces unreachable stack probes > # for the randomize_kstack_offset feature. Disable it for all compilers. > diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening > index 90cbaff86e13..ded17b8abce2 100644 > --- a/security/Kconfig.hardening > +++ b/security/Kconfig.hardening > @@ -23,13 +23,16 @@ config CC_HAS_AUTO_VAR_INIT_PATTERN > def_bool $(cc-option,-ftrivial-auto-var-init=pattern) > > config CC_HAS_AUTO_VAR_INIT_ZERO > + # GCC ignores the -enable flag, so we can test for the feature with > + # a single invocation using the flag, but drop it as appropriate in > + # the Makefile, depending on the presence of Clang. > def_bool $(cc-option,-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang) > > choice > prompt "Initialize kernel stack variables at function entry" > default GCC_PLUGIN_STRUCTLEAK_BYREF_ALL if COMPILE_TEST && GCC_PLUGINS > default INIT_STACK_ALL_PATTERN if COMPILE_TEST && CC_HAS_AUTO_VAR_INIT_PATTERN > - default INIT_STACK_ALL_ZERO if CC_HAS_AUTO_VAR_INIT_PATTERN > + default INIT_STACK_ALL_ZERO if CC_HAS_AUTO_VAR_INIT_ZERO > default INIT_STACK_NONE > help > This option enables initialization of stack variables at > > -- > Kees Cook >