exploit: ptrace POKETEXT code patching#29
Open
nataliakokoromyti wants to merge 3 commits intogpu-mode:masterfrom
Open
exploit: ptrace POKETEXT code patching#29nataliakokoromyti wants to merge 3 commits intogpu-mode:masterfrom
nataliakokoromyti wants to merge 3 commits intogpu-mode:masterfrom
Conversation
Fork child process that uses ptrace(PTRACE_ATTACH) + PTRACE_POKETEXT to patch cudaEventElapsedTime .text code. PTRACE_POKETEXT uses FOLL_FORCE internally, bypassing read-only page protections. Bypasses PR_SET_DUMPABLE=0 by re-enabling dumpable via prctl (no seccomp filter prevents this). Uses PR_SET_PTRACER for Yama LSM. Defense: block ptrace() syscall (SYS_ptrace=101).
Updated docstring to clarify ptrace exploit details and defenses.
Merged
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.
The benchmark harness sets PR_SET_DUMPABLE=0 to block ptrace, but has no seccomp filters, so you just call prctl(PR_SET_DUMPABLE, 1) to undo it. Then fork a child, PTRACE_ATTACH the parent, PTRACE_POKETEXT 9 bytes of shellcode over cudaEventElapsedTime. POKETEXT uses FOLL_FORCE internally so it writes straight through read-only .text pages. Reports 1.0us (or any other float of our choice since shellcode is just mov dword [rdi], <ieee754_bits>; xor eax,eax; ret so we can change the 4 bytes and get whatever timing we want).
Mechanism
prctl(PR_SET_DUMPABLE, 1)— re-enable ptrace attach (harness disables this but has no seccomp)prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY)— bypass Yama LSMPTRACE_ATTACH→PTRACE_POKETEXT(writes 9-byte shellcode)mov dword [rdi], 0x3A83126F; xor eax,eax; ret— sets*ms = 0.001f, returnscudaSuccessResults