Skip to content

Commit bb188d7

Browse files
vda-linuxoleg-nesterov
authored andcommitted
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: Denys Vlasenko <vda.linux@googlemail.com> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
1 parent 479bf98 commit bb188d7

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎fs/exec.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
13581358
unsigned int depth = bprm->recursion_depth;
13591359
int try,retval;
13601360
struct linux_binfmt *fmt;
1361+
pid_t old_pid;
13611362

13621363
retval = security_bprm_check(bprm);
13631364
if (retval)
@@ -1371,6 +1372,11 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
13711372
if (retval)
13721373
return retval;
13731374

1375+
/* Need to fetch pid before load_binary changes it */
1376+
rcu_read_lock();
1377+
old_pid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
1378+
rcu_read_unlock();
1379+
13741380
retval = -ENOENT;
13751381
for (try=0; try<2; try++) {
13761382
read_lock(&binfmt_lock);
@@ -1390,7 +1396,8 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
13901396
bprm->recursion_depth = depth;
13911397
if (retval >= 0) {
13921398
if (depth == 0)
1393-
ptrace_event(PTRACE_EVENT_EXEC, 0);
1399+
ptrace_event(PTRACE_EVENT_EXEC,
1400+
old_pid);
13941401
put_binfmt(fmt);
13951402
allow_write_access(bprm->file);
13961403
if (bprm->file)

0 commit comments

Comments
 (0)