systrap: fix TOCTOU on ThreadID in NotifyInterrupt#12935
Merged
copybara-service[bot] merged 2 commits intomasterfrom Apr 13, 2026
Merged
systrap: fix TOCTOU on ThreadID in NotifyInterrupt#12935copybara-service[bot] merged 2 commits intomasterfrom
copybara-service[bot] merged 2 commits intomasterfrom
Conversation
NotifyInterrupt reads ThreadID from guest-writable shared memory twice: once to check for invalidThreadID and again after acquiring the lock for the map lookup. A malicious guest can modify ThreadID between these two reads. If the guest sets ThreadID to a recently-exited thread between the reads, the TGKILL returns ESRCH which marks the subprocess as dead and kills the syscall thread. If the guest engineers a non-ESRCH error, the sentry panics. Read ThreadID exactly once into a local variable and use it for both the early-return check and the map lookup. This eliminates the TOCTOU window.
fa65843 to
7fa279c
Compare
PiperOrigin-RevId: 899174765
7fa279c to
62fb02b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
systrap: fix TOCTOU on ThreadID in NotifyInterrupt
NotifyInterrupt reads ThreadID from guest-writable shared memory twice: once to check for invalidThreadID (line 129) and again after acquiring the lock for the map lookup (line 136). A malicious guest can modify ThreadID between these two reads.
If the guest sets ThreadID to a recently-exited thread, TGKILL returns ESRCH which marks the subprocess as dead and kills the syscall thread. If the guest engineers a non-ESRCH error, the sentry panics (line 157).
Fix: read ThreadID exactly once into a local variable and use it for both the early-return check and the map lookup.
FUTURE_COPYBARA_INTEGRATE_REVIEW=#12927 from ibondarenko1:fix-systrap-threadid-toctou 2a22300