The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: x86@kernel.org, Thomas Gleixner <tglx@kernel.org>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>
Cc: linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Dapeng Mi <dapeng1.mi@linux.intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Jiaming Zhang <r772577952@gmail.com>,
	Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH 1/4] x86/fpu: Check for missing CET_USER xstate component
Date: Sat,  5 Dec 2026 21:12:22 -0800	[thread overview]
Message-ID: <20261206051225.298193-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20261206051225.298193-1-ebiggers@kernel.org>

If the CPU enumerates shadow stack support, verify that the CET_USER
xstate component is also enumerated.  If not, warn and clear
X86_FEATURE_SHSTK.  Also make X86_FEATURE_USER_SHSTK depend on
X86_FEATURE_SHSTK so that X86_FEATURE_USER_SHSTK gets cleared as well
(both here and if XSAVE is later disabled).

Previously, on a buggy CPU or hypervisor that enumerated SHSTK and
XSAVES without enumerating the CET_USER xstate component,
X86_FEATURE_USER_SHSTK remained enabled even though XFEATURE_CET_USER
was absent from the kernel's xstate mask.  An unprivileged process could
then enable shadow stacks via arch_prctl() and trigger a WARNING in
get_xsave_addr() (e.g. via ssp_get() during a core dump or ptrace()).

This fixes the warning and allows kernel code to assume that
X86_FEATURE_USER_SHSTK (or X86_FEATURE_SHSTK) together with
X86_FEATURE_XSAVES implies XFEATURE_MASK_CET_USER.

Reported-by: Jiaming Zhang <r772577952@gmail.com>
Closes: https://lore.kernel.org/r/CANypQFbh+s+dORvfGnJ=Wp-2VDQPCJ7_wFWiVkVacdJA_U=6Ww@mail.gmail.com
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 arch/x86/kernel/cpu/cpuid-deps.c | 1 +
 arch/x86/kernel/fpu/xstate.c     | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index acbcec394ef16..a1a7b2c1b2f07 100644
--- a/arch/x86/kernel/cpu/cpuid-deps.c
+++ b/arch/x86/kernel/cpu/cpuid-deps.c
@@ -89,6 +89,7 @@ static const struct cpuid_dep cpuid_deps[] = {
 	{ X86_FEATURE_AMX_BF16,			X86_FEATURE_AMX_TILE  },
 	{ X86_FEATURE_AMX_INT8,			X86_FEATURE_AMX_TILE  },
 	{ X86_FEATURE_SHSTK,			X86_FEATURE_XSAVES    },
+	{ X86_FEATURE_USER_SHSTK,		X86_FEATURE_SHSTK     },
 	{ X86_FEATURE_FRED,			X86_FEATURE_LKGS      },
 	{ X86_FEATURE_SPEC_CTRL_SSBD,		X86_FEATURE_SPEC_CTRL },
 	{ X86_FEATURE_LASS,			X86_FEATURE_SMAP      },
diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c
index da303714379cd..346aa126e1730 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -861,6 +861,13 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
 		}
 	}
 
+	if (boot_cpu_has(X86_FEATURE_SHSTK) &&
+	    !(fpu_kernel_cfg.max_features & XFEATURE_MASK_CET_USER)) {
+		pr_err(FW_BUG
+		       "x86/fpu: Disabling SHSTK support due to missing xstate feature\n");
+		setup_clear_cpu_cap(X86_FEATURE_SHSTK);
+	}
+
 	if (fpu_kernel_cfg.max_features & XFEATURE_MASK_APX &&
 	    fpu_kernel_cfg.max_features & (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR)) {
 		/*
-- 
2.56.1


  reply	other threads:[~2026-12-06  5:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  5:12 [PATCH 0/4] x86/fpu: Complete the removal of cpu_has_xfeatures() Eric Biggers
2026-12-06  5:12 ` Eric Biggers [this message]
2026-12-06  5:12 ` [PATCH 2/4] x86/fpu: Check for missing APX xstate component Eric Biggers
2026-12-06  5:12 ` [PATCH 3/4] perf/x86/intel: Remove redundant cpu_has_xfeatures() checks Eric Biggers
2026-12-06  5:12 ` [PATCH 4/4] x86/fpu: Remove cpu_has_xfeatures() Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261206051225.298193-2-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=bp@alien8.de \
    --cc=dapeng1.mi@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hch@lst.de \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=r772577952@gmail.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox