Skip to content

Commit ad64243

Browse files
spholztimschumi
authored andcommitted
Kernel/x86: Properly restore rflags in the syscall handler
The sysret instruction restores the rflags value from the r11 register. Before, we expected that the value in RegisterState::r11 is still the rflags value saved by syscall and therefore didn't copy RegisterState::rflags to r11 before the sysret. But signal handlers and ptrace can change the value in RegisterState::r11 while we are handling a syscall, so we shouldn't assume that it still contains the saved rflags. While handling a syscall the contents of RegisterState::rflags may also have been updated by e.g. ptrace in which case we should restore the updated rflags, not the original state on syscall entry.
1 parent 3e20c7b commit ad64243

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Kernel/Arch/x86_64/SyscallEntry.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ extern "C" NO_SANITIZE_COVERAGE [[gnu::naked]] void syscall_entry()
8080
" popq %%r15 \n"
8181
" addq $8, %%rsp \n"
8282
" popq %%rcx \n"
83-
" addq $16, %%rsp \n"
83+
" addq $8, %%rsp \n"
84+
" popq %%r11 \n"
8485

8586
// Disable interrupts before we restore the user stack pointer. sysret will re-enable interrupts when it restores
8687
// rflags.

0 commit comments

Comments
 (0)