Skip to content

Commit

Permalink
ptrace: introduce PTRACE_O_EXITKILL
Browse files Browse the repository at this point in the history
Ptrace jailers want to be sure that the tracee can never escape
from the control. However if the tracer dies unexpectedly the
tracee continues to run in potentially unsafe mode.

Add the new ptrace option PTRACE_O_EXITKILL. If the tracer exits
it sends SIGKILL to every tracee which has this bit set.

Note that the new option is not equal to the last-option << 1.  Because
currently all options have an event, and the new one starts the eventless
group.  It uses the random 20 bit, so we have the room for 12 more events,
but we can also add the new eventless options below this one.

Suggested by Amnon Shiloh.

Signed-off-by: Oleg Nesterov <[email protected]>
Tested-by: Amnon Shiloh <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: Michael Kerrisk <[email protected]>
Cc: Serge Hallyn <[email protected]>
Cc: Chris Evans <[email protected]>
Cc: David Howells <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Dec 18, 2012
1 parent 462e471 commit 992fb6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/linux/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#define PT_TRACE_EXIT PT_EVENT_FLAG(PTRACE_EVENT_EXIT)
#define PT_TRACE_SECCOMP PT_EVENT_FLAG(PTRACE_EVENT_SECCOMP)

#define PT_EXITKILL (PTRACE_O_EXITKILL << PT_OPT_FLAG_SHIFT)

/* single stepping state bits (used on ARM and PA-RISC) */
#define PT_SINGLESTEP_BIT 31
#define PT_SINGLESTEP (1<<PT_SINGLESTEP_BIT)
Expand Down
5 changes: 4 additions & 1 deletion include/uapi/linux/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@
#define PTRACE_O_TRACEEXIT (1 << PTRACE_EVENT_EXIT)
#define PTRACE_O_TRACESECCOMP (1 << PTRACE_EVENT_SECCOMP)

#define PTRACE_O_MASK 0x000000ff
/* eventless options */
#define PTRACE_O_EXITKILL (1 << 20)

#define PTRACE_O_MASK (0x000000ff | PTRACE_O_EXITKILL)

#include <asm/ptrace.h>

Expand Down
3 changes: 3 additions & 0 deletions kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ void exit_ptrace(struct task_struct *tracer)
return;

list_for_each_entry_safe(p, n, &tracer->ptraced, ptrace_entry) {
if (unlikely(p->ptrace & PT_EXITKILL))
send_sig_info(SIGKILL, SEND_SIG_FORCED, p);

if (__ptrace_detach(tracer, p))
list_add(&p->ptrace_entry, &ptrace_dead);
}
Expand Down

0 comments on commit 992fb6e

Please sign in to comment.