Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp619574pxb; Tue, 1 Feb 2022 07:07:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPedSCkaHb2hIEtqwVtx3pfS9kQhIhfDMfoPthpWO3NOsS6OeCsVXWDxL0cqSv6HC8WOM2 X-Received: by 2002:a17:906:d555:: with SMTP id cr21mr22396330ejc.458.1643728079471; Tue, 01 Feb 2022 07:07:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643728079; cv=none; d=google.com; s=arc-20160816; b=cq2279C9kPtUdpi9FyibY0fv3KWFb0BkHgcQVD95U+zaaI+dxyV4RZnaCaHThpyFtR ybkvKNP9iJ/bF88vrlYJ03RcaGke2dmF0+LUWXhyTlgngjlP8+w39ZZp2ohl1n45zvMG 5v5U+klNVUcN+wbk6PEi92rwhpbFucDFs+XGg45gpGESE1T+FI28UtID1kjxskVmgdJy uuamk58/rPWtT9MsIWfmzgu6ILmmxeaegpj32OVGdDyEmkBSgv0canbajmxnMonkT9J/ tiVJE36if4O02xpY2kLn6uE2bprJmVNTpgcjLt5h7OgxPq2e9YQiouRnAhhJRR0Nr4Me 0Tbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=lUcgvOY/5Wq5fDxkMq+Fnna7Z9JRCDPrjw7i49GiNWo=; b=Xs97zhbcQvNJ++OK7kzUX3sCbzVtjOZSr8cDd+gE+Nx0ip6PKOZP8pHYlLDK3xBXE/ 76aj4+qsbxB13Krix3NV0S6Gvj4moQJmNRcZq7D1iVY+Ka2VR/xU7bKbg/OdZ/zkAV7u hrZSBfARbIXfswgU7MPT5EAHBM+hmlrFa0gulzVyIJZh7tIGjOGIHGtFaXWnObpS1k32 8nROjicW168KRjABT5ohf38J8DNUVsKn5cSH21opnSu8bNYiYjVbsCdkFz2rCvns1Jhd IUmsD4rbaEqqiEQZYnV5EJpJCdVuLYnIClcjgdssVT98NXgK9ppFM+IDDnq5va2K2wr2 wj4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VbcFbnlG; 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr1si9592026ejc.269.2022.02.01.07.07.33; Tue, 01 Feb 2022 07:07:59 -0800 (PST) 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=@intel.com header.s=Intel header.b=VbcFbnlG; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356575AbiA3VWE (ORCPT + 99 others); Sun, 30 Jan 2022 16:22:04 -0500 Received: from mga06.intel.com ([134.134.136.31]:52019 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356449AbiA3VVu (ORCPT ); Sun, 30 Jan 2022 16:21:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643577710; x=1675113710; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=+CDlU4865vPjzgPm2GtX1jT2wdU+4Zo20LaMpttAL8o=; b=VbcFbnlGghxKZxvv8stR+cIfy1wd+/nLotqkID9ggGt0imGdqdC/M4tk xd2RV6hUxWR6349cmVkfetXorbNzzNlppBeG8OVvm7Tg7figM/CrJ6gwQ P0TU4Dq+ro0R4Yn/jeW2vGI+uH/0Tlt9TahOehvf8+v3LFQYAY8JYKoHJ cSqErhzxbdxn934ZX/J/agfFMxe6iHhizxn2Lg+c8NuajHkGzcpPgvwwC 2slrMBcBkOoTrFRJD6eX2PiuZDNNyJxLOZypCmlhDexFmS4OtCGx2vBhr 5Qh5BU3l6XbK35RbUwn3+mpzwJ9SCbc+0tnAMkQAGBfikUrf9yb+my2s+ g==; X-IronPort-AV: E=McAfee;i="6200,9189,10243"; a="308104892" X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="308104892" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:21:49 -0800 X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="536856682" Received: from avmallar-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.123.171]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:21:48 -0800 From: Rick Edgecombe To: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Dave Martin , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com Cc: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH 04/35] x86/cpufeatures: Introduce CPU setup and option parsing for CET Date: Sun, 30 Jan 2022 13:18:07 -0800 Message-Id: <20220130211838.8382-5-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220130211838.8382-1-rick.p.edgecombe@intel.com> References: <20220130211838.8382-1-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yu-cheng Yu Introduce CPU setup and boot option parsing for CET features. Signed-off-by: Yu-cheng Yu Signed-off-by: Rick Edgecombe Cc: Kees Cook --- v1: - Moved kernel-parameters.txt changes here from patch 1. Yu-cheng v25: - Remove software-defined X86_FEATURE_CET. Yu-cheng v24: - Update #ifdef placement to reflect Kconfig changes of splitting shadow stack and ibt. Documentation/admin-guide/kernel-parameters.txt | 4 ++++ arch/x86/include/uapi/asm/processor-flags.h | 2 ++ arch/x86/kernel/cpu/common.c | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index f5a27f067db9..6c5456c56dbf 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3389,6 +3389,10 @@ noexec=on: enable non-executable mappings (default) noexec=off: disable non-executable mappings + no_user_shstk [X86-64] Disable Shadow Stack for user-mode + applications. Disabling shadow stack also disables + IBT. + nosmap [X86,PPC] Disable SMAP (Supervisor Mode Access Prevention) even if it is supported by processor. diff --git a/arch/x86/include/uapi/asm/processor-flags.h b/arch/x86/include/uapi/asm/processor-flags.h index bcba3c643e63..a8df907e8017 100644 --- a/arch/x86/include/uapi/asm/processor-flags.h +++ b/arch/x86/include/uapi/asm/processor-flags.h @@ -130,6 +130,8 @@ #define X86_CR4_SMAP _BITUL(X86_CR4_SMAP_BIT) #define X86_CR4_PKE_BIT 22 /* enable Protection Keys support */ #define X86_CR4_PKE _BITUL(X86_CR4_PKE_BIT) +#define X86_CR4_CET_BIT 23 /* enable Control-flow Enforcement */ +#define X86_CR4_CET _BITUL(X86_CR4_CET_BIT) /* * x86-64 Task Priority Register, CR8 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 7b8382c11788..9ee339f5b8ca 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -515,6 +515,14 @@ static __init int setup_disable_pku(char *arg) __setup("nopku", setup_disable_pku); #endif /* CONFIG_X86_64 */ +static __always_inline void setup_cet(struct cpuinfo_x86 *c) +{ + if (!cpu_feature_enabled(X86_FEATURE_SHSTK)) + return; + + cr4_set_bits(X86_CR4_CET); +} + /* * Some CPU features depend on higher CPUID levels, which may not always * be available due to CPUID level capping or broken virtualization @@ -1261,6 +1269,9 @@ static void __init cpu_parse_early_param(void) if (cmdline_find_option_bool(boot_command_line, "noxsaves")) setup_clear_cpu_cap(X86_FEATURE_XSAVES); + if (cmdline_find_option_bool(boot_command_line, "no_user_shstk")) + setup_clear_cpu_cap(X86_FEATURE_SHSTK); + arglen = cmdline_find_option(boot_command_line, "clearcpuid", arg, sizeof(arg)); if (arglen <= 0) return; @@ -1632,6 +1643,7 @@ static void identify_cpu(struct cpuinfo_x86 *c) x86_init_rdrand(c); setup_pku(c); + setup_cet(c); /* * Clear/Set all flags overridden by options, need do it -- 2.17.1