From: Jiaming Zhang <r772577952@gmail.com>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
Eric Biggers <ebiggers@kernel.org>,
"Chang S. Bae" <chang.seok.bae@intel.com>,
Andrei Vagin <avagin@google.com>,
linux-kernel@vger.kernel.org,
Jiaming Zhang <r772577952@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] x86/fpu: Disable shadow stack when xstate support is missing
Date: Sun, 6 Dec 2026 12:55:05 +0800 [thread overview]
Message-ID: <20261206045505.4051381-1-r772577952@gmail.com> (raw)
On x86-64, user shadow stacks keep their settings and stack pointer in
supervisor registers saved across context switches via XSAVES under the
XFEATURE_CET_USER xstate component. Callers reading that state, such as
ssp_get() on core dump or ptrace(), expect XFEATURE_CET_USER to be
enabled whenever a task has shadow stacks on, and call get_xsave_addr():
if (WARN_ON_ONCE(!xfeature_enabled(xfeature_nr)))
return NULL;
During boot, however, identify_boot_cpu() runs before
fpu__init_system(). Since commit 0dc2a76092d9 ("x86/cpufeatures: Enable
CET CR4 bit for shadow stack"), setup_cet() sets X86_FEATURE_USER_SHSTK
from X86_FEATURE_SHSTK before fpu__init_system_xstate() reads the CPU's
XSAVE state mask from CPUID leaf 0xD.
When fpu__init_system_xstate() checks that mask, it disables AVX and
AVX-512 if their xstate bits are missing, but leaves X86_FEATURE_SHSTK
set when XSAVES or XFEATURE_MASK_CET_USER is absent. Also, cpuid_deps[]
lacks a dependency from X86_FEATURE_USER_SHSTK to X86_FEATURE_SHSTK, so
clearing SHSTK or XSAVE later leaves X86_FEATURE_USER_SHSTK enabled.
On a CPU or VM guest advertising SHSTK without XFEATURE_MASK_CET_USER
or XSAVES, any unprivileged 64-bit task can turn on shadow stacks via
arch_prctl(). Context switches then neither save nor restore the
shadow-stack MSRs, leaking them to other tasks, while core dumps, thread
clones, or ptrace() hit the warning in get_xsave_addr().
Record X86_FEATURE_USER_SHSTK as depending on X86_FEATURE_SHSTK in
cpuid_deps[], and clear X86_FEATURE_SHSTK in fpu__init_system_xstate()
when XSAVES or XFEATURE_MASK_CET_USER is missing, matching the AVX and
AVX-512 checks. Placing this check before the xsave_cpuid_features[]
loop also masks out XFEATURE_CET_KERNEL if present.
Fixes: 0dc2a76092d9 ("x86/cpufeatures: Enable CET CR4 bit for shadow stack")
Closes: https://lore.kernel.org/lkml/CANypQFbh+s+dORvfGnJ=Wp-2VDQPCJ7_wFWiVkVacdJA_U=6Ww@mail.gmail.com/
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:Gemini
Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
---
arch/x86/kernel/cpu/cpuid-deps.c | 1 +
arch/x86/kernel/fpu/xstate.c | 9 +++++++++
2 files changed, 10 insertions(+)
diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c
index acbcec394ef1..a1a7b2c1b2f0 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 da303714379c..6982913f2f00 100644
--- a/arch/x86/kernel/fpu/xstate.c
+++ b/arch/x86/kernel/fpu/xstate.c
@@ -861,6 +861,15 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
}
}
+ if (boot_cpu_has(X86_FEATURE_SHSTK)) {
+ if (!boot_cpu_has(X86_FEATURE_XSAVES) ||
+ !(fpu_kernel_cfg.max_features & XFEATURE_MASK_CET_USER)) {
+ pr_err(FW_BUG
+ "x86/fpu: Disabling shadow stack support due to missing xstate features\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)) {
/*
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.43.0
next reply other threads:[~2026-12-06 4:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 4:55 Jiaming Zhang [this message]
2026-12-06 5:20 ` Eric Biggers
2026-12-06 5:30 ` Eric Biggers
2026-12-06 5:22 ` Borislav Petkov
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=20261206045505.4051381-1-r772577952@gmail.com \
--to=r772577952@gmail.com \
--cc=avagin@google.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=ebiggers@kernel.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=stable@vger.kernel.org \
--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
all inboxes | Powered by JetHome®