Skip to content

Commit 44cad52

Browse files
amlutosuryasaimadhu
authored andcommitted
x86/ptrace: Fix xfpregs_set()'s incorrect xmm clearing
xfpregs_set() handles 32-bit REGSET_XFP and 64-bit REGSET_FP. The actual code treats these regsets as modern FX state (i.e. the beginning part of XSTATE). The declarations of the regsets thought they were the legacy i387 format. The code thought they were the 32-bit (no xmm8..15) variant of XSTATE and, for good measure, made the high bits disappear by zeroing the wrong part of the buffer. The latter broke ptrace, and everything else confused anyone trying to understand the code. In particular, the nonsense definitions of the regsets confused me when I wrote this code. Clean this all up. Change the declarations to match reality (which shouldn't change the generated code, let alone the ABI) and fix xfpregs_set() to clear the correct bits and to only do so for 32-bit callers. Fixes: 6164331 ("x86/fpu: Rewrite xfpregs_set()") Reported-by: Luís Ferreira <[email protected]> Signed-off-by: Andy Lutomirski <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Cc: <[email protected]> Link: https://bugzilla.kernel.org/show_bug.cgi?id=215524 Link: https://lore.kernel.org/r/[email protected]
1 parent e5733d8 commit 44cad52

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

arch/x86/kernel/fpu/regset.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
9191
const void *kbuf, const void __user *ubuf)
9292
{
9393
struct fpu *fpu = &target->thread.fpu;
94-
struct user32_fxsr_struct newstate;
94+
struct fxregs_state newstate;
9595
int ret;
9696

97-
BUILD_BUG_ON(sizeof(newstate) != sizeof(struct fxregs_state));
98-
9997
if (!cpu_feature_enabled(X86_FEATURE_FXSR))
10098
return -ENODEV;
10199

@@ -116,9 +114,10 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
116114
/* Copy the state */
117115
memcpy(&fpu->fpstate->regs.fxsave, &newstate, sizeof(newstate));
118116

119-
/* Clear xmm8..15 */
117+
/* Clear xmm8..15 for 32-bit callers */
120118
BUILD_BUG_ON(sizeof(fpu->__fpstate.regs.fxsave.xmm_space) != 16 * 16);
121-
memset(&fpu->fpstate->regs.fxsave.xmm_space[8], 0, 8 * 16);
119+
if (in_ia32_syscall())
120+
memset(&fpu->fpstate->regs.fxsave.xmm_space[8*4], 0, 8 * 16);
122121

123122
/* Mark FP and SSE as in use when XSAVE is enabled */
124123
if (use_xsave())

arch/x86/kernel/ptrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ static struct user_regset x86_64_regsets[] __ro_after_init = {
12241224
},
12251225
[REGSET_FP] = {
12261226
.core_note_type = NT_PRFPREG,
1227-
.n = sizeof(struct user_i387_struct) / sizeof(long),
1227+
.n = sizeof(struct fxregs_state) / sizeof(long),
12281228
.size = sizeof(long), .align = sizeof(long),
12291229
.active = regset_xregset_fpregs_active, .regset_get = xfpregs_get, .set = xfpregs_set
12301230
},
@@ -1271,7 +1271,7 @@ static struct user_regset x86_32_regsets[] __ro_after_init = {
12711271
},
12721272
[REGSET_XFP] = {
12731273
.core_note_type = NT_PRXFPREG,
1274-
.n = sizeof(struct user32_fxsr_struct) / sizeof(u32),
1274+
.n = sizeof(struct fxregs_state) / sizeof(u32),
12751275
.size = sizeof(u32), .align = sizeof(u32),
12761276
.active = regset_xregset_fpregs_active, .regset_get = xfpregs_get, .set = xfpregs_set
12771277
},

0 commit comments

Comments
 (0)