Skip to content

Commit 9301982

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/fpu: Preserve supervisor states in sanitize_restored_user_xstate()
sanitize_restored_user_xstate() preserves the supervisor states only when the fx_only argument is zero, which allows unprivileged user space to put supervisor states back into init state. Preserve them unconditionally. [ bp: Fix a typo or two in the text. ] Fixes: 5d6b6a6 ("x86/fpu/xstate: Update sanitize_restored_xstate() for supervisor xstates") Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 13311e7 commit 9301982

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

arch/x86/kernel/fpu/signal.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,18 @@ sanitize_restored_user_xstate(union fpregs_state *state,
221221

222222
if (use_xsave()) {
223223
/*
224-
* Note: we don't need to zero the reserved bits in the
225-
* xstate_header here because we either didn't copy them at all,
226-
* or we checked earlier that they aren't set.
224+
* Clear all feature bits which are not set in
225+
* user_xfeatures and clear all extended features
226+
* for fx_only mode.
227227
*/
228+
u64 mask = fx_only ? XFEATURE_MASK_FPSSE : user_xfeatures;
228229

229230
/*
230-
* 'user_xfeatures' might have bits clear which are
231-
* set in header->xfeatures. This represents features that
232-
* were in init state prior to a signal delivery, and need
233-
* to be reset back to the init state. Clear any user
234-
* feature bits which are set in the kernel buffer to get
235-
* them back to the init state.
236-
*
237-
* Supervisor state is unchanged by input from userspace.
238-
* Ensure supervisor state bits stay set and supervisor
239-
* state is not modified.
231+
* Supervisor state has to be preserved. The sigframe
232+
* restore can only modify user features, i.e. @mask
233+
* cannot contain them.
240234
*/
241-
if (fx_only)
242-
header->xfeatures = XFEATURE_MASK_FPSSE;
243-
else
244-
header->xfeatures &= user_xfeatures |
245-
xfeatures_mask_supervisor();
235+
header->xfeatures &= mask | xfeatures_mask_supervisor();
246236
}
247237

248238
if (use_fxsr()) {

0 commit comments

Comments
 (0)