You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/fspy-linux-sigsys-research.md
+12-9Lines changed: 12 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,8 +21,9 @@ The preferred ptrace bridge is:
21
21
2. The handler asks the existing fspy supervisor to attach to that thread with `PTRACE_SEIZE` and `PTRACE_O_TRACEEXEC`.
22
22
3. The handler reissues the original syscall through a trusted gateway.
23
23
4. Linux performs the requested exec and stops at `PTRACE_EVENT_EXEC` before target code runs.
24
-
5. The supervisor maps the handler island into the new address space, reinstalls the physical `SIGSYS` action, and detaches.
25
-
6. File-system syscalls run with no tracer attached. Their `SIGSYS` handling stays in process.
24
+
5. The supervisor advances once to the pending exec syscall-exit stop.
25
+
6. The supervisor maps the handler island into the new address space, reinstalls the physical `SIGSYS` action, and detaches.
26
+
7. File-system syscalls run with no tracer attached. Their `SIGSYS` handling stays in process.
26
27
27
28
Keep the custom loader in-house. The reference loaders were useful for finding requirements, but neither is suitable for production. Current esbuild 0.28.1, Node, shells, glibc, static musl, and static Go all passed a pure userland handoff after correcting reference-loader defects.
K --> L["Map handler, install SIGSYS action, detach"]
49
+
L --> P["Target starts with no active tracer"]
48
50
49
51
G -->|"ptrace denied or occupied"| M["Real exec of static fspy_host"]
50
52
M --> N["Earliest-entry handler bootstrap"]
@@ -130,18 +132,19 @@ Copy target pointers with bounded self `process_vm_readv`. Direct loads can turn
130
132
131
133
## Real exec with a temporary ptrace attachment
132
134
133
-
`PTRACE_EVENT_EXEC` occurs after Linux has installed the new image and reset exec-owned state, but before the new program executes an instruction. The ordering is visible in [`fs/exec.c`](https://github.com/torvalds/linux/blob/master/fs/exec.c#L1747).
135
+
`PTRACE_EVENT_EXEC` occurs after Linux has installed the new image and reset exec-owned state, but before the new program executes an instruction. It also occurs before the pending exec syscall finishes returning. The ordering is visible in [`fs/exec.c`](https://github.com/torvalds/linux/blob/master/fs/exec.c#L1747) and the [x86-64 syscall return path](https://github.com/torvalds/linux/blob/master/arch/x86/entry/syscall_64.c).
134
136
135
137
The exec handler can use this sequence:
136
138
137
139
1. Write an exec request containing the current TID and logical signal state to a preinitialized channel.
138
140
2. Wait for the supervisor to call `PTRACE_SEIZE` with `PTRACE_O_TRACEEXEC`.
139
141
3. Reissue the original `execve` or `execveat` with the sixth-argument gateway marker. Preserve the original path, argv, environment, fd, and flags.
140
142
4. On success, handle the exec event under the post-exec thread-group-leader TID. `PTRACE_GETEVENTMSG` reports the former TID for a nonleader exec.
141
-
5. Remote-map a sealed, position-independent handler artifact and its state mapping.
142
-
6. Install the physical `SIGSYS` action and force the physical mask to unblock `SIGSYS`.
143
-
7. Restore the target's entry registers and any instruction bytes overwritten for injection.
144
-
8. Detach with no delivered signal.
143
+
5. Resume once with `PTRACE_SYSCALL` and `PTRACE_O_TRACESYSGOOD`, then require the pending exec syscall-exit stop. This prevents the late exec return from overwriting registers prepared for the first injected syscall; x86-64 uses `rax` for both the syscall number and return value.
144
+
6. Remote-map a sealed, position-independent handler artifact and its state mapping.
145
+
7. Install the physical `SIGSYS` action and force the physical mask to unblock `SIGSYS`.
146
+
8. Restore the target's entry registers and any instruction bytes overwritten for injection.
147
+
9. Detach with no delivered signal.
145
148
146
149
Remote injection syscalls are also evaluated by inherited seccomp filters. Set the gateway marker on remote `mmap`, `mprotect`, and `rt_sigaction` calls that fspy itself traps. A stronger target or outer filter can still reject an operation.
0 commit comments