Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel/x86: Properly restore rflags in the syscall handler #24888

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

spholz
Copy link
Collaborator

@spholz spholz commented Aug 1, 2024

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.

@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Aug 1, 2024
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.
@spholz spholz force-pushed the x86-properly-restore-rflags branch from c3e4684 to f978b93 Compare August 1, 2024 10:32
@timschumi timschumi merged commit ad64243 into SerenityOS:master Aug 1, 2024
12 checks passed
@github-actions github-actions bot removed the 👀 pr-needs-review PR needs review from a maintainer or community member label Aug 1, 2024
@spholz spholz deleted the x86-properly-restore-rflags branch August 1, 2024 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants