Re: [PATCH] x86/fpu: Put non-enabled dynamic features into init state on sigreturn
From: Chang S. Bae
Date: Sat Nov 21 2026 - 17:08:30 EST
On 11/17/2026 3:26 AM, Daniel Wade wrote:
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
Hmm, since this missing ran into the issue, I suppose some fatty comment here is needed and also with some clear distinction between two. Perhaps, something like:
/* Restore enabled features only. */
xrestore_mask &= task_xfeatures;
- init_bv = task_xfeatures & ~xrestore_mask;
+ /*
+ * If the FPU registers do not belong to current, they may still
+ * contain state from a previous task with features beyond
+ * current's enabled features. Clear up to max_features to
+ * prevent state leakage.
+ */
+ if (test_thread_flag(TIF_NEED_FPU_LOAD))
+ init_bv = fpu_user_cfg.max_features & ~xrestore_mask;
+ else
+ init_bv = task_xfeatures & ~xrestore_mask;
Thanks,
Chang