Skip to content

Commit d10b554

Browse files
arunarKAGA-KOKO
authored andcommitted
x86/pkeys: Restore altstack access in sigreturn()
A process can disable access to the alternate signal stack by not enabling the altstack's PKEY in the PKRU register. Nevertheless, the kernel updates the PKRU temporarily for signal handling. However, in sigreturn(), restore_sigcontext() will restore the PKRU to the user-defined PKRU value. This will cause restore_altstack() to fail with a SIGSEGV as it needs read access to the altstack which is prohibited by the user-defined PKRU value. Fix this by restoring altstack before restoring PKRU. Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20240802061318.2140081-5-aruna.ramakrishna@oracle.com
1 parent 70044df commit d10b554

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

arch/x86/kernel/signal_64.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,13 @@ SYSCALL_DEFINE0(rt_sigreturn)
260260

261261
set_current_blocked(&set);
262262

263-
if (!restore_sigcontext(regs, &frame->uc.uc_mcontext, uc_flags))
263+
if (restore_altstack(&frame->uc.uc_stack))
264264
goto badframe;
265265

266-
if (restore_signal_shadow_stack())
266+
if (!restore_sigcontext(regs, &frame->uc.uc_mcontext, uc_flags))
267267
goto badframe;
268268

269-
if (restore_altstack(&frame->uc.uc_stack))
269+
if (restore_signal_shadow_stack())
270270
goto badframe;
271271

272272
return regs->ax;

0 commit comments

Comments
 (0)