diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 12:52:12 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 13:00:24 -0300 |
| commit | 8b28a0a5101a62fd55c2d55433e0fa899d4623f9 (patch) | |
| tree | de233408fc45f93e19bbcf637ed66242d569fc56 /README.md | |
| parent | 36d7f642e71207d04f5da80530da552e06447337 (diff) | |
| download | computeranim-8b28a0a5101a62fd55c2d55433e0fa899d4623f9.tar.gz computeranim-8b28a0a5101a62fd55c2d55433e0fa899d4623f9.zip | |
agent: its handlers act with the thread's protection keys and float modes, not a handler's
The kernel starts a signal handler with default PKRU (key 0 only) and
default MXCSR and x87 control word, the thread's own saved in the frame.
The SIGSYS handler makes the thread's syscalls and clones its threads
from there, so under --syscalls:
- a pkey_alloc's new rights were undone when the handler returned;
- a thread was born with no right to keyed memory (V8's compiler
threads fault reading the code space: d8 died of SEGV_PKUERR, and the
35 seconds were its core dump, not a spin);
- a buffer in keyed memory was EFAULT to the kernel, and a fault to the
agent reading it for the event;
- a thread started without its maker's float modes (flush-to-zero).
Both handlers now take the thread's PKRU and control words from the frame
first (signal.adopt), and the SIGSYS one writes PKRU back to the frame
after the syscall. Watched memory is read, and hooked code patched, with
every key open, so a key the thread itself cannot use hides nothing.
test-agent: agent_pkey (a keyed page read, given to syscalls, watched,
read by a later thread; skips itself without keys), and agent_sys's
thread checks its MXCSR. README: --alloc and programs with their own
malloc; the core dump.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -322,7 +322,11 @@ protection makes the kernel refuse syscalls that write there, and soft-dirty bits still need the compare, a page at a time. **Syscalls** go through SIGSYS because the kernel then needs no second process: the cost is two signal frames, on a stack of the agent's so that it works on threads with -almost none. +almost none. A handler starts with the kernel's defaults, not the thread's +rights to memory behind protection keys (PKRU) nor its floating-point +modes; the agent's handlers take the thread's back first, so that a syscall +made for it, a thread cloned for it and a watched page read for it are as +the thread would have them (V8 keeps its code space behind a key). Measured (`zig build bench-agent -Doptimize=ReleaseFast`, an i7-11700, each loop 10^5 to 5 10^6 times; bytes are the recording's): @@ -350,7 +354,11 @@ Limits: a hooked function called with SIGTRAP blocked dies (not under do not unwind through a hooked call; a pointer the kernel would answer with EFAULT faults in the handler; syscalls made from the vDSO never enter the kernel and are not seen, as under ptrace; a target that needs SIGSYS or its -own alternate signal stack is told it has them. +own alternate signal stack is told it has them. `--alloc` sees calls that +reach libc's allocator by name: a program that brings its own `malloc` and +binds it inside itself (d8 does) shows none, and `--hook malloc` is the way +to see those. A target that dies under the agent dumps core like any other, +which for a V8 takes half a minute; `ulimit -c 0` if that is not wanted. ## The kernel's view |
