From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: Andrei Vagin <avagin@google.com>, Borislav Petkov <bp@alien8.de>
Cc: <linux-kernel@vger.kernel.org>, <criu@lists.linux.dev>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Dave Hansen <dave.hansen@linux.intel.com>, <x86@kernel.org>,
Alexander Mikhalitsyn <alexander@mihalicyn.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH 1/2] x86/fpu: Allow restoring signal frames with larger xstate_size
Date: Wed, 2 Dec 2026 10:12:45 -0800 [thread overview]
Message-ID: <0131d36a-c5f2-4c3e-8559-998ef25f5efd@intel.com> (raw)
In-Reply-To: <20260929232621.3745312-2-avagin@google.com>
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
next prev parent reply other threads:[~2026-12-02 18:12 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 23:26 [PATCH 0/2] " Andrei Vagin
2026-09-29 23:26 ` [PATCH 1/2] " Andrei Vagin
2026-12-02 18:12 ` Chang S. Bae [this message]
2026-09-29 23:26 ` [PATCH 2/2] selftests/x86: Check restoring FPU state " Andrei Vagin
2026-12-02 18:12 ` Chang S. Bae
2026-09-29 23:57 ` [PATCH 0/2] x86/fpu: Allow restoring signal frames " Borislav Petkov
2026-09-30 0:02 ` Andrei Vagin
2026-09-30 2:51 ` Borislav Petkov
2026-09-30 19:37 ` Andrei Vagin
2026-10-01 1:56 ` Borislav Petkov
2026-10-21 17:50 ` Andrei Vagin
2026-12-01 16:14 ` Andrei Vagin
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=0131d36a-c5f2-4c3e-8559-998ef25f5efd@intel.com \
--to=chang.seok.bae@intel.com \
--cc=alexander@mihalicyn.com \
--cc=avagin@google.com \
--cc=bp@alien8.de \
--cc=criu@lists.linux.dev \
--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®