Re: [PATCH 1/2] x86/fpu: Allow restoring signal frames with larger xstate_size
From: Chang S. Bae
Date: Wed Dec 02 2026 - 13:13:09 EST
On 9/29/2026 4:26 PM, Andrei Vagin wrote:
check_xstate_in_sigframe() currently enforces that fx_sw->xstate_size in
the signal frame must not exceed the current task's fpstate->user_size.
This prevents checkpoint/restore tools (such as CRIU) from migrating a
process that was saved on a CPU with a larger set of enabled xstate
features to a CPU with fewer features, even if the process did not
actively use any of the unsupported features.
Commit fd14edd82077 ("x86/fpu: Pre-fault only required size of xstate
buffer") introduced validation in check_xstate_in_sigframe() to
calculate the required buffer size from the intersection of
fx_sw->xfeatures and fpstate->user_xfeatures, and to shrink
fx_sw->xstate_size to that required size.
Remove the fx_sw->xstate_size > fpstate->user_size check so that signal
frames with a larger xstate_size can be restored when all active
features are supported. Because fx_sw->xstate_size is no longer bounded
by fpstate->user_size before reading the trailing FP_XSTATE_MAGIC2
marker, check for unsigned overflow when comparing fx_sw->xstate_size
against fx_sw->extended_size and use get_user() instead of __get_user()
when reading FP_XSTATE_MAGIC2.
I think this patch does three pieces of things:
1. __get_user() => get_user()
Looks like 22a78a25438d2 ("Merge __{get,put}_user() removal branch")
has already made in mainline
2. Tighten the validation to reject untouched dynamic states as below
3. Then, relax the checker to allow a larger sigframe as explained
above
Logically, the stricter validation (2) prepares the ground for the
relaxation in (3). Would it make sense to split these changes?
When allowing a larger xstate_size, the kernel must still reject the...
signal frame (resulting in SIGSEGV) if the XSAVE header (xstate_bv)
marks any unsupported feature as active. On the direct restore path,
XRSTOR raises #GP if any bit in xstate_bv is 1 while the corresponding
bit in XCR0 is 0, but this does not cover dynamically enabled features
(such as AMX XFEATURE_XTILE_DATA) that are enabled in XCR0 while
disabled for the task via MSR_IA32_XFD and fpstate->user_xfeatures.
Because __restore_fpregs_from_user() masks xrestore_mask (EDX:EAX) with
fpstate->user_xfeatures before executing XRSTOR (as kernel-mode XRSTOR
must not trigger an XFD #NM trap), XRSTOR would ignore XFD-disabled
components and silently drop their active state.
Therefore, explicitly validate in check_xstate_in_sigframe() that
xbuf->header.xfeatures (xstate_bv) only contains features present in the
intersection of fx_sw->xfeatures and fpstate->user_xfeatures. A
concurrent user-space modification of xbuf->header.xfeatures between
this check and XRSTOR cannot compromise the kernel: the restore mask
(EDX:EAX) is derived from the kernel copy of fx_sw and masked with
fpstate->user_xfeatures, so XRSTOR will either fault with #GP (if a bit
outside XCR0 is set) or ignore any bit not enabled in the restore mask
without touching its memory area or raising a kernel-mode #NM.
+ /*
+ * Reject XFD-disabled features present in XCR0 that XRSTOR
+ * would otherwise ignore when masked out of EDX:EAX, as well
+ * as any other active features not in xfeatures. Concurrent
+ * user-space changes after this check cannot affect the kernel
+ * because XRSTOR is masked with xfeatures.
+ */
+ if (xstate_bv & ~xfeatures)
+ return false;
I think this makes sense though, let me make sure the implications:
For migration, I remember you mentioned a #GP makes the failure explicit. With this change, however, migration could instead fail through silent state resetting, without a #GP. Then, this looks like effectively establishing silent state loss as the behavior for this type of migration failure going forward.
If so, perhaps better to document this limitation when migrating from a CPU with more features to one with fewer features, including the possibility of state being silently reset instead of #GP.
Another aspect discussed previously was whether userspace could avoid this failure. I suppose one option would be to introduce another arch_prctl() command to let userspace request fpstate expansion explicitly, without #NM from the first touch, which sounds crazy. So you dropped this option, correct?
Thanks,
Chang