Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp867301pxb; Tue, 14 Sep 2021 10:23:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8NNhEZLEwTzvwyFNl+lQDFSmMOk55uNYlMnzEQ+YBnJ9ijbPHI+EgYXmsuFYcO+gNPxtf X-Received: by 2002:a05:6e02:2145:: with SMTP id d5mr12831524ilv.214.1631640183834; Tue, 14 Sep 2021 10:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631640183; cv=none; d=google.com; s=arc-20160816; b=o+JlOTM0X4z2rj0+VUWQIjRC8HeepwKftxMX3GMtfePYd6Y1hS0eX7m/AYEM6+VBfd ZyHvX5qtnL3V4jOeNieNZ58Ur2wu5C79xbpTnwHmZHoqgQffics5CboTScpe1n10X83A YAMtq/2O9Ksu2xSy2NDQ38gG4Lb/R+IOtDBOUoEYjLvSWkUJhYM7IsrStwaHtFqWvxjB 03/FHH1E0mjEX6qimWKGbqdJFipsSygk3BdZ4YrQ/z472woi88VVjebbzIOB+UK8R1Vf j6OI4SXOdYskVYdPXI/3eg8PZK2QS0KrPVwDlmDjOekxCDkKgZP9mk8o1ebjYXcyRJ5I M9pA== 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=3KcfDuI+vgr3UdYnojYVnwtddmopW4ZL19RdmRiChyg=; b=aQSB7RMy72LNr/lOkwYFMxozwzeOCfwCv0qNkFUmz8CJsAdb/JfSLn/xkFRmjBdYpZ Ywm4HUEVctnGyOOIbwU1gOLfhru+4FQQc0pdEUKDsYzOeoNziA75U+OdGOlwuZERA/nH hDsTKpeAMipoqc3gidCSV7D+PCkmFwXWAYzJg9kWMRmyD8KIvvxJV0fxesjLcxeUIIRP YZg+geOGclZ7sJQj9ep0AhKEVfEAwi+mGEDpHMM1Er1lC5r4MgeGLjWQJdhqRnA4FAFT cZviKwa9+0agfOXI/xYN2I8RuqE5RXTFMQxlClG5WjCQDzQXWllnQwrVy4+mVE9u2OqZ O1lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OEn7CkGq; 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 t6si1025215jaa.130.2021.09.14.10.22.48; Tue, 14 Sep 2021 10:23:03 -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=OEn7CkGq; 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 S231171AbhINRWy (ORCPT + 99 others); Tue, 14 Sep 2021 13:22:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbhINRWx (ORCPT ); Tue, 14 Sep 2021 13:22:53 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB577C061762 for ; Tue, 14 Sep 2021 10:21:35 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id n30so10263819pfq.5 for ; Tue, 14 Sep 2021 10:21:35 -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=3KcfDuI+vgr3UdYnojYVnwtddmopW4ZL19RdmRiChyg=; b=OEn7CkGqtIQ1V2B5tVX1veXUmmJU/H8x6RbgAohTflrWRul98mmNl8/moi95Kw9cvQ CwG7tgc07l5WqRDxKEc37+CzXebBe4tw46muukaX9mqpdImVEoPRlpWStg2aHP7MOlqQ pWnoDLtr4tIkPdKUve41e/nyUnxGWdeZ99Euc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3KcfDuI+vgr3UdYnojYVnwtddmopW4ZL19RdmRiChyg=; b=8Gdvq++rILssrLv1Lx6683eWSMfoRAHTVTQ1Tq/vLeQJ1jU/8EHaIItPG6EEBQBorm EFgFU3ui3BRtNwe/8iv6nlXvuLm8Cs7CLnobG7KMOxhug4fzXeHGWnDS2v61QaIwzgkG DyhbYQdzsNtm+H+Upp+86bD2t3t+NWq1hgn7rWXyprB/Rc3Xj28MfwxqQdsi57EN5kbJ Z6UmFoep6w5eYOytDt+/q7en13O7WbvSyez/yfud8oD3J3KJgHvo7TiCtPA6DCMguVcy a8ByT4RVlwckgcGP0EpwhsdXtuqqQ23IHzsbzX7Fl0x05taYsPyBgbnDGUa6kk4+ukIr d4lg== X-Gm-Message-State: AOAM5321A5ydjJk+5c83RVfd2JdUgrEgghHSkJ2jyX95oZV2Q1MLrtcE KXWTKC2LypPRM+AONa712xw5a0aL6a/KRw== X-Received: by 2002:a63:ea58:: with SMTP id l24mr16568444pgk.334.1631640095450; Tue, 14 Sep 2021 10:21:35 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x19sm12074192pgk.37.2021.09.14.10.21.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 10:21:34 -0700 (PDT) Date: Tue, 14 Sep 2021 10:21:33 -0700 From: Kees Cook To: Nathan Chancellor Cc: Will Deacon , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Nick Desaulniers , "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: <202109140958.11DCC6B6@keescook> References: <20210914102837.6172-1-will@kernel.org> <01f572ab-bea2-f246-2f77-2f119056db84@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <01f572ab-bea2-f246-2f77-2f119056db84@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 14, 2021 at 08:58:12AM -0700, Nathan Chancellor wrote: > On 9/14/2021 3:28 AM, Will Deacon wrote: > > CC_HAS_AUTO_VAR_INIT_ZERO requires a supported set of compiler options > > distinct from those needed by CC_HAS_AUTO_VAR_INIT_PATTERN, Fix up > > the Kconfig dependency for INIT_STACK_ALL_ZERO to test for the former > > instead of the latter, as these are the options passed by the top-level > > Makefile. > > > > Cc: Kees Cook > > Cc: Nathan Chancellor > > Cc: Nick Desaulniers > > Cc: Gustavo A. R. Silva > > Cc: Greg Kroah-Hartman > > Fixes: dcb7c0b9461c ("hardening: Clarify Kconfig text for auto-var-init") > > Signed-off-by: Will Deacon > > Reviewed-by: Nathan Chancellor > > One comment below. > > > --- > > > > I just noticed this while reading the code and I suspect it doesn't really > > matter in practice. > > > > security/Kconfig.hardening | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening > > index 90cbaff86e13..341e2fdcba94 100644 > > --- a/security/Kconfig.hardening > > +++ b/security/Kconfig.hardening > > @@ -29,7 +29,7 @@ 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 > > > > While I think this change is correct in and of itself, > CONFIG_INIT_STACK_ALL_ZERO is broken with GCC 12.x, as > CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO won't be set even though GCC now supports > -ftrivial-auto-var-init=zero because GCC does not implement the > -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang > flag for obvious reasons ;) the cc-option call probably needs to be > adjusted. GCC silently ignores the -enable flag, so things actually work correctly as-is. But, yes, it makes the command line long and doesn't make sense. How about we do this instead: diff --git a/Makefile b/Makefile index 34a0afc3a8eb..34439deac939 100644 --- a/Makefile +++ b/Makefile @@ -831,12 +831,11 @@ 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_HAS_AUTO_VAR_INIT_ZERO_WITH_ENABLE 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..beea81df3081 100644 --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -22,14 +22,22 @@ menu "Memory initialization" config CC_HAS_AUTO_VAR_INIT_PATTERN def_bool $(cc-option,-ftrivial-auto-var-init=pattern) +config CC_HAS_AUTO_VAR_INIT_ZERO_WITHOUT_ENABLE + def_bool $(cc-option,-ftrivial-auto-var-init=zero) + +config CC_HAS_AUTO_VAR_INIT_ZERO_WITH_ENABLE + # https://bugs.llvm.org/show_bug.cgi?id=45497 + def_bool !CC_HAS_AUTO_VAR_INIT_ZERO_WITHOUT_ENABLE && \ + $(cc-option,-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang) + config CC_HAS_AUTO_VAR_INIT_ZERO - def_bool $(cc-option,-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang) + def_bool CC_HAS_AUTO_VAR_INIT_ZERO_WITHOUT_ENABLE || CC_HAS_AUTO_VAR_INIT_ZERO_WITH_ENABLE 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