From: Eric Biggers <ebiggers@kernel.org>
To: Jiaming Zhang <r772577952@gmail.com>
Cc: 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, "H. Peter Anvin" <hpa@zytor.com>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
"Chang S. Bae" <chang.seok.bae@intel.com>,
Andrei Vagin <avagin@google.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] x86/fpu: Disable shadow stack when xstate support is missing
Date: Sat, 5 Dec 2026 21:20:26 -0800 [thread overview]
Message-ID: <20261206052026.GA2051@sol> (raw)
In-Reply-To: <20261206045505.4051381-1-r772577952@gmail.com>
On Sun, Dec 06, 2026 at 12:55:05PM +0800, Jiaming Zhang wrote:
> 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>
I already had an almost identical diff in a stack of patches that I
hadn't had a chance to send out yet. I've gone ahead and done so:
https://lore.kernel.org/all/20261206051225.298193-1-ebiggers@kernel.org/
I updated the commit message of the first one to include your
Reported-by and the scenario you mentioned, though I had written the
diff earlier before seeing your report since it was needed anyway.
Fixes and Cc stable may be debatable, as this would be a hypervisor bug.
- Eric
next prev parent reply other threads:[~2026-12-06 5:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 4:55 [PATCH] x86/fpu: Disable shadow stack when xstate support is missing Jiaming Zhang
2026-12-06 5:20 ` Eric Biggers [this message]
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=20261206052026.GA2051@sol \
--to=ebiggers@kernel.org \
--cc=avagin@google.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=r772577952@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.