From: Daniel Wade <danjwade95@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>,
"Chang S . Bae" <chang.seok.bae@intel.com>,
Andrei Vagin <avagin@google.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] x86/fpu: Put non-enabled dynamic features into init state on sigreturn
Date: Tue, 17 Nov 2026 21:56:40 +1030 [thread overview]
Message-ID: <20261117112640.1435-1-danjwade95@gmail.com> (raw)
On sigreturn restore_fpregs_from_user() restores the features the signal
frame carries and inits the rest, but both masks are limited to
fpstate::user_xfeatures. If the task lost the registers earlier in the
syscall, a dynamic feature it has not enabled yet -- XTILE_DATA before
its first AMX use -- still holds the previous task state, and
fpregs_mark_activate() makes the registers current's. The first AMX
instruction then raises #NM and fpstate_realloc() clears XFD without
reloading, so the task reads another task's tile data, including that of
a KVM vCPU thread whose guest used AMX.
Init the user features that are not enabled for current as well, as
restore_fpregs_from_fpstate() documents and fpu__clear_user_states()
already does on every signal delivery.
Fixes: 5509cc78080d ("x86/fpu/signal: Use fpstate for size and features")
Signed-off-by: Daniel Wade <danjwade95@gmail.com>
Cc: stable@vger.kernel.org
---
No AMX hardware was available, so this was not reproduced. Tested in KVM
guests on an AMD Ryzen 7 7700X (AVX-512, XSAVEC and XSAVES, no AMX and no
XFD), mainline b3dfbde62cf1 with KASAN, PROVE_LOCKING and X86_DEBUG_FPU.
Stable: the hunk does not apply to v6.12.117 or v7.2-rc5, where the
function still uses the older variable names. There the same two lines go
after "int ret;" with ~ufeatures in place of ~task_xfeatures.
arch/x86/kernel/fpu/signal.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/x86/kernel/fpu/signal.c b/arch/x86/kernel/fpu/signal.c
index 164255d..757a831 100644
--- a/arch/x86/kernel/fpu/signal.c
+++ b/arch/x86/kernel/fpu/signal.c
@@ -267,6 +267,11 @@ static int __restore_fpregs_from_user(void __user *buf, u64 task_xfeatures,
/* Restore enabled features only. */
xrestore_mask &= task_xfeatures;
init_bv = task_xfeatures & ~xrestore_mask;
+
+ /* The previous task's state can linger in disabled features. */
+ if (test_thread_flag(TIF_NEED_FPU_LOAD))
+ init_bv |= fpu_user_cfg.max_features & ~task_xfeatures;
+
if (likely(!fx_only))
ret = xrstor_from_user_sigframe(buf, xrestore_mask);
else
reply other threads:[~2026-11-17 11:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261117112640.1435-1-danjwade95@gmail.com \
--to=danjwade95@gmail.com \
--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=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®