aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/ptrace.h
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@chromium.org>2014-06-06 17:36:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-06 19:08:11 -0400
commit4e52365f279564cef0ddd41db5237f0471381093 (patch)
tree6f9b4c19ea6bd5b80c22f59340923174ac4dee3c /include/linux/ptrace.h
parent615cc2c9cf9529846fbc342560d6787c2ccaaeea (diff)
ptrace: fix fork event messages across pid namespaces
When tracing a process in another pid namespace, it's important for fork event messages to contain the child's pid as seen from the tracer's pid namespace, not the parent's. Otherwise, the tracer won't be able to correlate the fork event with later SIGTRAP signals it receives from the child. We still risk a race condition if a ptracer from a different pid namespace attaches after we compute the pid_t value. However, sending a bogus fork event message in this unlikely scenario is still a vast improvement over the status quo where we always send bogus fork event messages to debuggers in a different pid namespace than the forking process. Signed-off-by: Matthew Dempsky <mdempsky@chromium.org> Acked-by: Oleg Nesterov <oleg@redhat.com> Cc: Kees Cook <keescook@chromium.org> Cc: Julien Tinnes <jln@chromium.org> Cc: Roland McGrath <mcgrathr@chromium.org> Cc: Jan Kratochvil <jan.kratochvil@redhat.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/ptrace.h')
-rw-r--r--include/linux/ptrace.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
index 07d0df6bf768..077904c8b70d 100644
--- a/include/linux/ptrace.h
+++ b/include/linux/ptrace.h
@@ -5,6 +5,7 @@
5#include <linux/sched.h> /* For struct task_struct. */ 5#include <linux/sched.h> /* For struct task_struct. */
6#include <linux/err.h> /* for IS_ERR_VALUE */ 6#include <linux/err.h> /* for IS_ERR_VALUE */
7#include <linux/bug.h> /* For BUG_ON. */ 7#include <linux/bug.h> /* For BUG_ON. */
8#include <linux/pid_namespace.h> /* For task_active_pid_ns. */
8#include <uapi/linux/ptrace.h> 9#include <uapi/linux/ptrace.h>
9 10
10/* 11/*
@@ -129,6 +130,37 @@ static inline void ptrace_event(int event, unsigned long message)
129} 130}
130 131
131/** 132/**
133 * ptrace_event_pid - possibly stop for a ptrace event notification
134 * @event: %PTRACE_EVENT_* value to report
135 * @pid: process identifier for %PTRACE_GETEVENTMSG to return
136 *
137 * Check whether @event is enabled and, if so, report @event and @pid
138 * to the ptrace parent. @pid is reported as the pid_t seen from the
139 * the ptrace parent's pid namespace.
140 *
141 * Called without locks.
142 */
143static inline void ptrace_event_pid(int event, struct pid *pid)
144{
145 /*
146 * FIXME: There's a potential race if a ptracer in a different pid
147 * namespace than parent attaches between computing message below and
148 * when we acquire tasklist_lock in ptrace_stop(). If this happens,
149 * the ptracer will get a bogus pid from PTRACE_GETEVENTMSG.
150 */
151 unsigned long message = 0;
152 struct pid_namespace *ns;
153
154 rcu_read_lock();
155 ns = task_active_pid_ns(rcu_dereference(current->parent));
156 if (ns)
157 message = pid_nr_ns(pid, ns);
158 rcu_read_unlock();
159
160 ptrace_event(event, message);
161}
162
163/**
132 * ptrace_init_task - initialize ptrace state for a new child 164 * ptrace_init_task - initialize ptrace state for a new child
133 * @child: new child task 165 * @child: new child task
134 * @ptrace: true if child should be ptrace'd by parent's tracer 166 * @ptrace: true if child should be ptrace'd by parent's tracer