Re: [PATCH] x86/fpu: Put non-enabled dynamic features into init state on sigreturn

From: Andrei Vagin

Date: Fri Nov 20 2026 - 18:35:11 EST


On Tue, Nov 17, 2026 at 3:27 AM Daniel Wade <danjwade95@xxxxxxxxx> wrote:
>
> 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.
>

I think you can add this step sequence to demonstrate how the issue
can be triggered:

A: rt_sigreturn() AMX permitted, XTILE_DATA not enabled
sleeps / is preempted A's state saved, TIF_NEED_FPU_LOAD set
B: runs, uses AMX B's tile data is now in the registers
A: back in rt_sigreturn()
restore_fpregs_from_user()
xfd_update_state() XFD[18] set: B's tiles hidden, not cleared
XRSTOR(frame) XTILE_DATA in neither mask: left untouched
fpregs_mark_activate() registers now marked as A's
A: exit to user space no reload, B's tile data still there
A: AMX instruction -> #NM
fpstate_realloc() XFD cleared, registers not touched
A: instruction restarts e.g. TILESTORED reads B's tile data

> Fixes: 5509cc78080d ("x86/fpu/signal: Use fpstate for size and features")
> Signed-off-by: Daniel Wade <danjwade95@xxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx

The change looks good to me. You can consider to cherry-pick the
selftest from here:
https://github.com/avagin/linux-task-diag/commits/wip/fpu-sigreturn-init-xtiledata/

Reviewed-by: Andrei Vagin <avagin@xxxxxxxxx>
Tested-by: Andrei Vagin <avagin@xxxxxxxxx>

Thanks,
Andrei