As the same user, `strace -p` on another of your own processes fails with 'Operation not permitted'. What is likely restricting it?
Short answer
Most likely the Yama security module's ptrace_scope sysctl. At 0 you can attach to any same-UID dumpable process; at 1 only to descendants (unless the target allows a tracer via prctl PR_SET_PTRACER); at 2 only processes with CAP_SYS_PTRACE may use ptrace; at 3 nobody can attach and the value cannot be changed once set. Same UID is therefore not sufficient on a hardened host.
You are debugging or investigating a process owned by your own account and strace -p or gdb -p says Operation not permitted. Ownership matches, so what else gates ptrace?
Yama and ptrace_scope
The kernel's Yama documentation describes the ptrace_scope sysctl under /proc/sys/kernel/yama (it needs CONFIG_SECURITY_YAMA). It has four values:
- 0 — classic: a process can
PTRACE_ATTACHto any other process with the same UID, provided the target is dumpable. - 1 — restricted: attaching needs a predefined relationship with the target, by default being a descendant (and the classic criteria must hold too). A target can name an allowed debugger with
prctl(PR_SET_PTRACER, ...)or allow any process withPR_SET_PTRACER_ANY. - 2 — admin-only: only processes with
CAP_SYS_PTRACEmay use ptrace. - 3 — no attach: no process may use
PTRACE_ATTACHorPTRACE_TRACEME, and the page states that once set this value cannot be changed.
PTRACE_TRACEME is unchanged in modes 0 and 1, which is why launching a program under a debugger usually still works.
Why defenders care
Under the restricted and stricter modes, a process can no longer attach to arbitrary processes of the same user, which narrows what a compromised process can do to its neighbours. The cost is friction for legitimate debugging and live forensics, which then need privileges (CAP_SYS_PTRACE) or a different setting.
Why the distractors are tempting
The setuid bit and root-only claims sound like classic Unix rules but are not how ptrace permission works here. SIGSTOP is a red herring.
What interviewers want
Mentioning Yama and ptrace_scope, being able to explain 0 through 3, and noting the trade-off between hardening and debugging or IR access.
Likely follow-ups
- What does ptrace_scope 3 mean operationally, and how do you reverse it?
- How does this setting affect incident responders who need to attach to a live suspicious process?
- How do debuggers like gdb still work when you start the program under them instead of attaching?