Skip to content

Commit efa1655

Browse files
KAGA-KOKOsuryasaimadhu
authored andcommitted
x86/fpu: Reset state for all signal restore failures
If access_ok() or fpregs_soft_set() fails in __fpu__restore_sig() then the function just returns but does not clear the FPU state as it does for all other fatal failures. Clear the FPU state for these failures as well. Fixes: 72a671c ("x86, fpu: Unify signal handling code paths for x86 and x86_64 kernels") 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 510b80a commit efa1655

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

arch/x86/kernel/fpu/signal.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,17 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size)
307307
return 0;
308308
}
309309

310-
if (!access_ok(buf, size))
311-
return -EACCES;
310+
if (!access_ok(buf, size)) {
311+
ret = -EACCES;
312+
goto out;
313+
}
312314

313-
if (!static_cpu_has(X86_FEATURE_FPU))
314-
return fpregs_soft_set(current, NULL,
315-
0, sizeof(struct user_i387_ia32_struct),
316-
NULL, buf) != 0;
315+
if (!static_cpu_has(X86_FEATURE_FPU)) {
316+
ret = fpregs_soft_set(current, NULL, 0,
317+
sizeof(struct user_i387_ia32_struct),
318+
NULL, buf);
319+
goto out;
320+
}
317321

318322
if (use_xsave()) {
319323
struct _fpx_sw_bytes fx_sw_user;
@@ -396,7 +400,7 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size)
396400
*/
397401
ret = __copy_from_user(&env, buf, sizeof(env));
398402
if (ret)
399-
goto err_out;
403+
goto out;
400404
envp = &env;
401405
}
402406

@@ -426,7 +430,7 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size)
426430

427431
ret = copy_user_to_xstate(&fpu->state.xsave, buf_fx);
428432
if (ret)
429-
goto err_out;
433+
goto out;
430434

431435
sanitize_restored_user_xstate(&fpu->state, envp, user_xfeatures,
432436
fx_only);
@@ -446,7 +450,7 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size)
446450
ret = __copy_from_user(&fpu->state.fxsave, buf_fx, state_size);
447451
if (ret) {
448452
ret = -EFAULT;
449-
goto err_out;
453+
goto out;
450454
}
451455

452456
sanitize_restored_user_xstate(&fpu->state, envp, user_xfeatures,
@@ -464,7 +468,7 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size)
464468
} else {
465469
ret = __copy_from_user(&fpu->state.fsave, buf_fx, state_size);
466470
if (ret)
467-
goto err_out;
471+
goto out;
468472

469473
fpregs_lock();
470474
ret = copy_kernel_to_fregs_err(&fpu->state.fsave);
@@ -475,7 +479,7 @@ static int __fpu__restore_sig(void __user *buf, void __user *buf_fx, int size)
475479
fpregs_deactivate(fpu);
476480
fpregs_unlock();
477481

478-
err_out:
482+
out:
479483
if (ret)
480484
fpu__clear_user_states(fpu);
481485
return ret;

0 commit comments

Comments
 (0)