diff options
Diffstat (limited to 'include/linux/ptrace.h')
| -rw-r--r-- | include/linux/ptrace.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index 07d0df6bf768..cc79eff4a1ad 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 | */ | ||
| 143 | static 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 |
| @@ -302,6 +334,9 @@ static inline void user_single_step_siginfo(struct task_struct *tsk, | |||
| 302 | * calling arch_ptrace_stop() when it would be superfluous. For example, | 334 | * calling arch_ptrace_stop() when it would be superfluous. For example, |
| 303 | * if the thread has not been back to user mode since the last stop, the | 335 | * if the thread has not been back to user mode since the last stop, the |
| 304 | * thread state might indicate that nothing needs to be done. | 336 | * thread state might indicate that nothing needs to be done. |
| 337 | * | ||
| 338 | * This is guaranteed to be invoked once before a task stops for ptrace and | ||
| 339 | * may include arch-specific operations necessary prior to a ptrace stop. | ||
| 305 | */ | 340 | */ |
| 306 | #define arch_ptrace_stop_needed(code, info) (0) | 341 | #define arch_ptrace_stop_needed(code, info) (0) |
| 307 | #endif | 342 | #endif |
