Re: [PATCH 1/4] x86/fpu: Check for missing CET_USER xstate component

From: Jiaming Zhang

Date: Sun Dec 06 2026 - 12:07:14 EST


Eric Biggers <ebiggers@xxxxxxxxxx> 于2026年12月6日周日 13:12写道:
>
> 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@xxxxxxxxx>
> Closes: https://lore.kernel.org/r/CANypQFbh+s+dORvfGnJ=Wp-2VDQPCJ7_wFWiVkVacdJA_U=6Ww@xxxxxxxxxxxxxx
> Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
> ---
> 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
>

After 10 minutes execution with the reproducer, the issue didn't trigger again.

Tested-by: Jiaming Zhang <r772577952@xxxxxxxxx>