Files
DragonOS/.github
aLinCheandlongjin 5a0707b6b2 feat(ptrace): implement Linux-compatible tracing and remote access (#2198)
feat(ptrace): implement Linux-compatible tracing and remote access

Implement a Linux 6.6-compatible ptrace subsystem and integrate it with
signal delivery, syscall dispatch, seccomp, process lifecycle events,
wait semantics, remote memory access, x86 debug traps, and uprobes.

Replace the original monolithic implementation with ownership-oriented
modules:

- define ptrace ABI types, options, events, and syscall-info separately;
- model active stops, pending events, completed resumes, and request
  freezes as typed state with explicit generation ownership;
- maintain bidirectional tracer relationships with O(1) slot-based
  link and unlink operations;
- centralize attach, seize, detach, wait, exit, fork, group-stop, and
  SIGCONT transactions in the lifecycle layer;
- expose registers, siginfo, sigmask, event messages, and remote memory
  only through a session-and-stop-generation-bound request guard.

Make tracing lifecycle transitions race-safe:

- bind stops, events, waits, debug handoffs, and fork inheritance to the
  exact tracing session that created them;
- wait for the tracee to become inactive before accessing its kernel
  stack TrapFrame;
- revoke request freezes and replay deferred fatal wakeups exactly once;
- preserve group-stop state across detach and tracer exit;
- prevent EXITKILL, EXEC, SECCOMP, SIGCONT, and pending-stop events from
  leaking into a replacement tracing session;
- hand traced zombies from exactly one tracer waiter to the real parent;
- prepare fallible allocations outside IRQ-disabled relation
  transactions and commit only after capacity and ownership revalidation.

Implement the ptrace execution and event ABI, including TRACEME, ATTACH,
SEIZE, DETACH, CONT, SYSCALL, SINGLESTEP, SYSEMU, INTERRUPT, LISTEN,
GET/SETREGS, NT_PRSTATUS GET/SETREGSET, PEEK/POKEUSER, signal and sigmask
access, event messages, syscall information, and fork/clone/vfork,
exec, exit, seccomp, and group-stop events.

Introduce a shared remote-memory engine for ptrace, /proc/<pid>/mem, and
process_vm_readv/writev. Preserve Linux permission checks, precise short
copy results, forced-access COW, MAP_PRIVATE isolation, shared
page-cache dirty accounting, and RISC-V executable-memory I-cache
synchronization. Continue rejecting unsupported special or external-PFN
VMAs instead of adding an unsafe generic provider workaround.

Complete x86_64 tracing state support:

- virtualize and context-switch hardware debug registers;
- coordinate #BP/#DB routing between ptrace and uprobe XOL execution;
- preserve hardware breakpoint, watchpoint, single-step, DR6, and RF
  semantics;
- validate and restore CS, SS, DS, ES, FS, and GS selectors according to
  Linux rules;
- preserve FS/GS selectors and bases across ptrace writes, context
  switches, signal return, and VMX host transitions;
- recover safely from missing data descriptors and preserve the original
  fault frame on invalid iret selectors.

Align siginfo conversion, tracer identity, syscall-number rewriting,
regset partial-copy behavior, dumpability, user-namespace capability
checks, Yama policy, and procfs TracerPid reporting with Linux 6.6.

Add deterministic dunitest and gVisor coverage for ptrace lifecycle,
group-stop, concurrent ownership, EXITKILL, syscall information,
seccomp TRACE, x86 debug state, segment registers, process_vm access,
proc-mem, page-cache persistence, and remote I-cache synchronization.
Remove the ptrace Int3 blocklist and declare only the verified
INT3:TRUE gVisor platform capability.

Validation on the final head includes:

- x86_64, RISC-V, and LoongArch build, format, and static checks;
- successful x86_64 Dunitest and integration workflows;
- 1172 local Ubuntu 24.04 two-vCPU dunitests with 0 failures and
  0 timeouts;
- 12/12 targeted x86 ptrace register/debug tests on both Linux and
  DragonOS;
- successful MM host tests and final adversarial architecture,
  correctness, concurrency, security, and performance review.

PTRACE_O_SUSPEND_SECCOMP and non-NT_PRSTATUS regsets remain explicitly
unsupported. Remote access to special/external-PFN VMAs continues to
require a future safe provider contract.


Signed-off-by: aLinChe <1129332011@qq.com>
Signed-off-by: longjin <longjin@dragonos.org>
Co-authored-by: longjin <longjin@dragonos.org>
2026-08-28 16:42:48 +08:00
..
2024-04-23 19:14:41 +08:00