Commit bb188d7e authored by Denys Vlasenko's avatar Denys Vlasenko Committed by Oleg Nesterov

ptrace: make former thread ID available via PTRACE_GETEVENTMSG after PTRACE_EVENT_EXEC stop

When multithreaded program execs under ptrace,
all traced threads report WIFEXITED status, except for
thread group leader and the thread which execs.

Unless tracer tracks thread group relationship between tracees,
which is a nontrivial task, it will not detect that
execed thread no longer exists.

This patch allows tracer to figure out which thread
performed this exec, by requesting PTRACE_GETEVENTMSG
in PTRACE_EVENT_EXEC stop.

Another, samller problem which is solved by this patch
is that tracer now can figure out which of the several
concurrent execs in multithreaded program succeeded.
Signed-off-by: default avatarDenys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
parent 479bf98c
...@@ -1358,6 +1358,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs) ...@@ -1358,6 +1358,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
unsigned int depth = bprm->recursion_depth; unsigned int depth = bprm->recursion_depth;
int try,retval; int try,retval;
struct linux_binfmt *fmt; struct linux_binfmt *fmt;
pid_t old_pid;
retval = security_bprm_check(bprm); retval = security_bprm_check(bprm);
if (retval) if (retval)
...@@ -1371,6 +1372,11 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs) ...@@ -1371,6 +1372,11 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
if (retval) if (retval)
return retval; return retval;
/* Need to fetch pid before load_binary changes it */
rcu_read_lock();
old_pid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
rcu_read_unlock();
retval = -ENOENT; retval = -ENOENT;
for (try=0; try<2; try++) { for (try=0; try<2; try++) {
read_lock(&binfmt_lock); read_lock(&binfmt_lock);
...@@ -1390,7 +1396,8 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs) ...@@ -1390,7 +1396,8 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
bprm->recursion_depth = depth; bprm->recursion_depth = depth;
if (retval >= 0) { if (retval >= 0) {
if (depth == 0) if (depth == 0)
ptrace_event(PTRACE_EVENT_EXEC, 0); ptrace_event(PTRACE_EVENT_EXEC,
old_pid);
put_binfmt(fmt); put_binfmt(fmt);
allow_write_access(bprm->file); allow_write_access(bprm->file);
if (bprm->file) if (bprm->file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment