diff options
author | Oleg Nesterov <oleg@redhat.com> | 2012-12-17 19:03:07 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-17 20:15:22 -0500 |
commit | 992fb6e170639b0849bace8e49bf31bd37c4123c (patch) | |
tree | 29f54e489ea095aba284fd4b1feb7201347eb70c | |
parent | 462e471107624fe9bd8b6353ac13e06305c3f3fd (diff) |
ptrace: introduce PTRACE_O_EXITKILL
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 <oleg@redhat.com>
Tested-by: Amnon Shiloh <u3557@miso.sublimeip.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Serge Hallyn <serge.hallyn@canonical.com>
Cc: Chris Evans <scarybeasts@gmail.com>
Cc: David Howells <dhowells@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/ptrace.h | 2 | ||||
-rw-r--r-- | include/uapi/linux/ptrace.h | 5 | ||||
-rw-r--r-- | kernel/ptrace.c | 3 |
3 files changed, 9 insertions, 1 deletions
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index a89ff04bddd9..addfbe7c180e 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h | |||
@@ -32,6 +32,8 @@ | |||
32 | #define PT_TRACE_EXIT PT_EVENT_FLAG(PTRACE_EVENT_EXIT) | 32 | #define PT_TRACE_EXIT PT_EVENT_FLAG(PTRACE_EVENT_EXIT) |
33 | #define PT_TRACE_SECCOMP PT_EVENT_FLAG(PTRACE_EVENT_SECCOMP) | 33 | #define PT_TRACE_SECCOMP PT_EVENT_FLAG(PTRACE_EVENT_SECCOMP) |
34 | 34 | ||
35 | #define PT_EXITKILL (PTRACE_O_EXITKILL << PT_OPT_FLAG_SHIFT) | ||
36 | |||
35 | /* single stepping state bits (used on ARM and PA-RISC) */ | 37 | /* single stepping state bits (used on ARM and PA-RISC) */ |
36 | #define PT_SINGLESTEP_BIT 31 | 38 | #define PT_SINGLESTEP_BIT 31 |
37 | #define PT_SINGLESTEP (1<<PT_SINGLESTEP_BIT) | 39 | #define PT_SINGLESTEP (1<<PT_SINGLESTEP_BIT) |
diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h index 1ef6c056a9e4..022ab186a812 100644 --- a/include/uapi/linux/ptrace.h +++ b/include/uapi/linux/ptrace.h | |||
@@ -73,7 +73,10 @@ | |||
73 | #define PTRACE_O_TRACEEXIT (1 << PTRACE_EVENT_EXIT) | 73 | #define PTRACE_O_TRACEEXIT (1 << PTRACE_EVENT_EXIT) |
74 | #define PTRACE_O_TRACESECCOMP (1 << PTRACE_EVENT_SECCOMP) | 74 | #define PTRACE_O_TRACESECCOMP (1 << PTRACE_EVENT_SECCOMP) |
75 | 75 | ||
76 | #define PTRACE_O_MASK 0x000000ff | 76 | /* eventless options */ |
77 | #define PTRACE_O_EXITKILL (1 << 20) | ||
78 | |||
79 | #define PTRACE_O_MASK (0x000000ff | PTRACE_O_EXITKILL) | ||
77 | 80 | ||
78 | #include <asm/ptrace.h> | 81 | #include <asm/ptrace.h> |
79 | 82 | ||
diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 1f5e55dda955..ec8118ab2a47 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c | |||
@@ -457,6 +457,9 @@ void exit_ptrace(struct task_struct *tracer) | |||
457 | return; | 457 | return; |
458 | 458 | ||
459 | list_for_each_entry_safe(p, n, &tracer->ptraced, ptrace_entry) { | 459 | list_for_each_entry_safe(p, n, &tracer->ptraced, ptrace_entry) { |
460 | if (unlikely(p->ptrace & PT_EXITKILL)) | ||
461 | send_sig_info(SIGKILL, SEND_SIG_FORCED, p); | ||
462 | |||
460 | if (__ptrace_detach(tracer, p)) | 463 | if (__ptrace_detach(tracer, p)) |
461 | list_add(&p->ptrace_entry, &ptrace_dead); | 464 | list_add(&p->ptrace_entry, &ptrace_dead); |
462 | } | 465 | } |