From patchwork Mon Oct 24 11:27:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp615896wru; Mon, 24 Oct 2022 12:27:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5vAiXxek2RF8huTHqGkltJfeeZ76L4DK20QUDev/tuyEapACBlbGqvEhmnmeWag8ArLdau X-Received: by 2002:a05:6402:2687:b0:45d:3a94:348f with SMTP id w7-20020a056402268700b0045d3a94348fmr32019626edd.48.1666639649602; Mon, 24 Oct 2022 12:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666639649; cv=none; d=google.com; s=arc-20160816; b=vhsBcczmRGwwiFdvvjsJiKb8QrbhmTdQRY59VZYOZO+QynYQ/GQpBH4k6PFmMrdhmi 75evjhgFsP6KG5isY5fUzyoXuAYtJf4T51Wa6Bs6PJ5KgklNp1zm5iS7YerpG480En5Z e1Gob8D8nbiaVS4cWz8BX7IhlkZ2u56SmIp/6gfjZXcNWRh2OZ25NcplDidVgWSPvIkL 7TSkyZ0ZeqNBjoPmgDFqrEP3x0Fc5DLWOYu53xXXJThcqD6n7golFJiObh6z1UDgqpHo 2t30DKxzy73+tuzEp9GxDmPiphZJREb7MoqiwQMrPZZelWhJDQfJbdNAChgozL7gnTj0 2zpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nQOgj4goGyp3T1fozmT47OvTKMGzR+aMExeSOuxtUQE=; b=n+HmxeGlKyxOZ5D3OlNaBeJ9mNyPUYBTDgglJ3Fb0JtFkBmZYdI+ILH6dN6PmqXJJi K5MYUD99SUnJ8U+s8wD68CN8mhWajqSvims1LqZYqxlpA36MrJZg9n4qC9y5bD72ezmp xTEvbi72dfKSGPliZEX4Q8LasTerhTyoYqTRkeMaoYS7lDfgB9guxaSNysyXFT0yIRvv 7zdn2wGGHvZw4xQotN1CpwBlsNDaVECn2tPkeMxkkNhChCrFSFgJfSmXyhZ1sUI+Yf70 8KiHxy94ism6uV0+OQtqTosxBzkmsdZKf/g+RgtRhiwXGELQ3CZrs6GvZ3/5xlPWH5sV yNNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y0CzeDKy; 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=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b22-20020a170906709600b0078d4b605b71si541792ejk.338.2022.10.24.12.27.05; Mon, 24 Oct 2022 12:27:29 -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=@linuxfoundation.org header.s=korg header.b=Y0CzeDKy; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232384AbiJXTZX (ORCPT + 99 others); Mon, 24 Oct 2022 15:25:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231863AbiJXTXJ (ORCPT ); Mon, 24 Oct 2022 15:23:09 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAB7C20351; Mon, 24 Oct 2022 10:57:47 -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 sin.source.kernel.org (Postfix) with ESMTPS id 6F661CE13BF; Mon, 24 Oct 2022 12:19:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B34AC433D6; Mon, 24 Oct 2022 12:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613976; bh=6w1m8oTCk9uzWFr7+T1Vk2k2FAMBopqrgJZpxzytLWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y0CzeDKyCSEmCuUMjLnd+gUt73PzT0Ht9NdPR6jnPko1Ue8xaeegCz9kwvv7mlz06 MpQw7p9BWqPXm+lsN+P/Cc4h2YNSx+yGZWNk+0LgPJEKEJIaJP6FgFSG88jSbJNPw9 dJSunFrfrEvKwc/px0O9O+zOqRczaCBS9f5P3BlM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , Masahiro Yamada , Nick Desaulniers , linux-kbuild@vger.kernel.org, llvm@lists.linux.dev, Kees Cook Subject: [PATCH 5.10 055/390] hardening: Remove Clangs enable flag for -ftrivial-auto-var-init=zero Date: Mon, 24 Oct 2022 13:27:32 +0200 Message-Id: <20221024113024.968446156@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747598336922901807?= X-GMAIL-MSGID: =?utf-8?q?1747598336922901807?= From: Kees Cook commit 607e57c6c62c00965ae276902c166834ce73014a upstream. Now that Clang's -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang option is no longer required, remove it from the command line. Clang 16 and later will warn when it is used, which will cause Kconfig to think it can't use -ftrivial-auto-var-init=zero at all. Check for whether it is required and only use it when so. Cc: Nathan Chancellor Cc: Masahiro Yamada Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Cc: llvm@lists.linux.dev Cc: stable@vger.kernel.org Fixes: f02003c860d9 ("hardening: Avoid harmless Clang option under CONFIG_INIT_STACK_ALL_ZERO") Signed-off-by: Kees Cook Signed-off-by: Nathan Chancellor Signed-off-by: Greg Kroah-Hartman --- Makefile | 4 ++-- security/Kconfig.hardening | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) --- a/Makefile +++ b/Makefile @@ -817,8 +817,8 @@ endif # Initialize all stack variables with a zero value. ifdef CONFIG_INIT_STACK_ALL_ZERO KBUILD_CFLAGS += -ftrivial-auto-var-init=zero -ifdef CONFIG_CC_IS_CLANG -# https://bugs.llvm.org/show_bug.cgi?id=45497 +ifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER +# https://github.com/llvm/llvm-project/issues/44842 KBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang endif endif --- a/security/Kconfig.hardening +++ b/security/Kconfig.hardening @@ -22,11 +22,17 @@ 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 - # 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. +config CC_HAS_AUTO_VAR_INIT_ZERO_BARE + def_bool $(cc-option,-ftrivial-auto-var-init=zero) + +config CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER + # Clang 16 and later warn about using the -enable flag, but it + # is required before then. def_bool $(cc-option,-ftrivial-auto-var-init=zero -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang) + depends on !CC_HAS_AUTO_VAR_INIT_ZERO_BARE + +config CC_HAS_AUTO_VAR_INIT_ZERO + def_bool CC_HAS_AUTO_VAR_INIT_ZERO_BARE || CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER choice prompt "Initialize kernel stack variables at function entry"