Skip to content

feat(fspy_elf_loader): add SIGSYS syscall interception, signal virtualization, and /proc/exe rewriting - #1028

Open
wan9chi wants to merge 3 commits into
fspy-linux/2-elf-loader-validation-stackfrom
fspy-linux/3-elf-loader-sigsys
Open

wan9chi wants to merge 3 commits into
fspy-linux/2-elf-loader-validation-stackfrom
fspy-linux/3-elf-loader-sigsys

Conversation

@wan9chi

@wan9chi wan9chi commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Motivation

To track filesystem accesses uniformly across glibc, musl, static binaries, and direct-syscall runtimes on Linux without LD_PRELOAD or seccomp_unotify, the userland ELF loader needs an in-process seccomp-BPF SECCOMP_RET_TRAP (SIGSYS) virtualization runtime that transparently preserves target signal semantics, vfork/posix_spawn, multithreading, and /proc/*/exe identity while exposing a clean syscall-interception hook.

Changes

  • sigsys/filter.rs: seccomp-BPF filter allowlisting the launcher's fixed PF_X range, rejecting io_uring_setup and clone3 with ENOSYS, and trapping signal, exec, /proc/*/exe, and caller-supplied syscalls (with unit tests).
  • sigsys/signal.rs, sigsys/arch.rs, and sigsys/stack_pool.rs: per-thread virtual SIGSYS disposition/mask virtualization, pooled private SIGSYS stacks, vfork/posix_spawn altstack handoff returning via rt_sigreturn (including AArch64 EXTRA_MAGIC/GCS and x86-64 fpregs/CET), and masked-wait deferred-SIGSYS handling (with unit tests).
  • sigsys/proc_exe.rs and sigsys/usermem.rs: /proc/*/exe path rewriting and fault-safe user memory copy/probe helpers with sandbox fallbacks (with unit tests).
  • fspy_elf_loader_test_launcher and fspy_elf_loader_tests: wire --test-interceptor and add the 39-test Linux virtualization integration suite in fixtures/virtualization.c and tests/exec_elf.rs.

Stack created with GitHub Stacks CLI • Give Feedback 💬


Note

High Risk
Large changes to seccomp, signal delivery, vfork/posix_spawn, and exec/syscall interception—bugs here can crash processes, break threading, or mis-report process identity.

Overview
Adds a full in-process SIGSYS + seccomp-BPF runtime to fspy_elf_loader so tracked Linux targets can be intercepted without LD_PRELOAD or seccomp_unotify. exec_elf now validates the launcher's fixed PF_X range, calls sigsys::install before entry, and accepts an optional SyscallInterceptor that can replay, short-circuit, or trigger a replacement execve.

The new sigsys module wires arch-specific trampolines (x86-64 / AArch64), a static BPF program (IP allowlist, idempotent filter probe, conditional clone / masked-wait traps, ENOSYS for clone3 / io_uring_setup), virtual rt_sigaction / rt_sigprocmask / fork / vfork** handling with a pooled private handler stack, **/proc/*/exe rewriting** on path-following syscalls, and **fault-safe user memory** copies. Tests gain a **--test-interceptor` launcher path and virtualization ELF fixtures.

Reviewed by Cursor Bugbot for commit 17f3396. Bugbot is set up for automated code reviews on this repo. Configure here.

@wan9chi
wan9chi added this pull request to stack #1030 November 27, 2026 00:33
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  +0.12%  [ -3.86% ..  +3.77%]  overhead   +58.94%
dynamic/access             change  -0.42%  [ -6.34% ..  +5.87%]  overhead   +16.02%
dynamic/access-relative    change  -0.03%  [ -4.00% ..  +3.15%]  overhead   +66.68%
dynamic/access-contended   change  +2.08%  [ -7.28% ..  +9.04%]  overhead    +4.20%
static/launch              change  -0.25%  [ -3.32% ..  +4.60%]  overhead  +206.27%
static/access              change  -0.09%  [ -2.10% ..  +2.91%]  overhead +1467.45%
static/access-relative     change  +0.57%  [ -1.11% ..  +1.92%]  overhead +1990.26%
static/access-contended    change  +0.28%  [ -1.13% ..  +1.60%]  overhead +1943.88%

macos

dynamic/launch             change  -0.15%  [ -2.57% ..  +2.29%]  overhead  +225.18%
dynamic/access             change  +0.00%  [ -3.13% ..  +2.47%]  overhead    +4.11%
dynamic/access-relative    change  -0.11%  [ -1.94% ..  +2.50%]  overhead  +257.95%
dynamic/access-contended   change  -0.48%  [ -2.79% ..  +1.25%]  overhead    +4.48%

windows

dynamic/launch             change  -0.76%  [ -3.27% ..  +3.32%]  overhead   +27.01%
dynamic/access             change  +0.18%  [ -2.86% ..  +2.34%]  overhead    +1.47%
dynamic/access-relative    change  +0.00%  [ -1.41% ..  +1.62%]  overhead    +1.26%
dynamic/access-contended   change  -0.17%  [ -9.61% ..  +7.95%]  overhead    +2.33%

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

wan9chi and others added 3 commits November 27, 2026 08:45
…lization, and /proc/exe rewriting

Add the in-process SIGSYS syscall virtualization engine to
`fspy_elf_loader`, wire it into the freestanding test launcher, and add
unit and Linux virtualization integration tests:

- `sigsys/filter.rs`: seccomp-BPF filter construction allowlisting the
  launcher's `PF_X` range, rejecting `io_uring_setup` with `ENOSYS`,
  and trapping signal/exec/`/proc/exe` and caller-supplied syscalls.
- `sigsys/signal.rs` & `sigsys/arch.rs`: per-thread virtual `SIGSYS`
  disposition/mask virtualization, pooled SIGSYS stacks, `vfork` /
  `posix_spawn` altstack handoff with `rt_sigreturn` (including AArch64
  `EXTRA_MAGIC`/GCS and x86-64 `fpregs`/CET handling), and masked-wait
  deferred-SIGSYS handling.
- `sigsys/proc_exe.rs` & `sigsys/usermem.rs`: `/proc/*/exe` path
  rewriting and fault-safe user memory copy/probe helpers.
- `fspy_elf_loader_tests`: 39-test Linux integration suite in
  `fixtures/virtualization.c` and `tests/exec_elf.rs`.

Co-authored-by: Gemini 4 Neon <noreply@google.com>
Co-authored-by: Gemini 4 Neon <noreply@google.com>
…lter

Co-authored-by: Gemini 4 Neon <noreply@google.com>
@wan9chi
wan9chi force-pushed the fspy-linux/3-elf-loader-sigsys branch from c34be75 to 17f3396 Compare November 27, 2026 00:46

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 17f3396. Configure here.

Sysno::openat as u32,
Sysno::openat2 as u32,
Sysno::stat as u32,
Sysno::lstat as u32,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary trapping of lstat without rewrite handling

Medium Severity

Sysno::lstat is included in BASE_TRAPPED_SYSCALLS for x86_64 but has no corresponding handler in rewrite_path_arg or dispatch_phase1. Every lstat from outside the launcher's PF_X range triggers a SIGSYS trap, runs through Phase 1 dispatch, falls through all match arms, and gets replayed unchanged via PHASE2_REPLAY. Since lstat never follows symlinks, /proc/*/exe rewriting is intentionally inapplicable, making the trap pure overhead. It's the only path-based syscall in the base set without rewrite logic.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 17f3396. Configure here.

let bump = fspy_nostd_alloc::pooled_bump();
let Ok(Some(base)) = fspy_nostd_alloc::fs::fd_path(&bump, borrowed_dirfd) else {
return (false, Some(raw));
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relative /proc/*/exe paths with AT_FDCWD undetected

Low Severity

The comment at line 406 says "resolve dirfd (or cwd for AT_FDCWD)" but BorrowedFd::try_borrow_raw(AT_FDCWD) returns None for the negative sentinel value -100, causing the function to return (false, Some(raw)) without matching. Relative paths like "../self/exe" from within /proc/ are never detected as /proc/*/exe references when dirfd is AT_FDCWD. A getcwd-based fallback is needed to resolve the working directory for AT_FDCWD, similar to what resolve_exe_path_for_fd already does for relative fallback paths.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 17f3396. Configure here.

This branch has not been deployed

No deployments
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.

1 participant