From 95dd193fd6134519a4c41e399273851c54a005f4 Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Tue, 30 Sep 2014 13:27:37 +0900 Subject: [PATCH] Fix reporting of having done execve to ptracer --- kernel/process.c | 2 +- kernel/syscall.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/kernel/process.c b/kernel/process.c index aa193c01..790423ad 100644 --- a/kernel/process.c +++ b/kernel/process.c @@ -344,7 +344,7 @@ int ptrace_traceme(void){ ihk_mc_spinlock_lock_noirq(&proc->ftn->lock); - proc->ftn->ptrace = PT_TRACED; + proc->ftn->ptrace = PT_TRACED | PT_TRACE_EXEC; proc->ftn->ppid_parent = proc->ftn->parent; ihk_mc_spinlock_lock_noirq(&proc->ftn->parent->lock); diff --git a/kernel/syscall.c b/kernel/syscall.c index 771b4564..7bbc9b59 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -1381,6 +1381,7 @@ SYSCALL_DECLARE(arch_prctl) static int ptrace_report_exec(struct process *proc) { + dkprintf("ptrace_report_exec,enter\n"); int error = 0; long rc; struct siginfo info; @@ -1388,8 +1389,8 @@ static int ptrace_report_exec(struct process *proc) if (!(proc->ftn->ptrace & PT_TRACE_EXEC)) { goto out; } - - /* Save reason why stopped and process state for wait to reap */ + + /* Save reason why stopped and process state for wait4() to reap */ ihk_mc_spinlock_lock_noirq(&proc->ftn->lock); memset(&info, '\0', sizeof info); info.si_signo = SIGTRAP; @@ -1399,12 +1400,16 @@ static int ptrace_report_exec(struct process *proc) proc->ftn->status = PS_TRACED; ihk_mc_spinlock_unlock_noirq(&proc->ftn->lock); +#if 0 // ??? b48da86357c4853f7dea94f67ec65d75d0502f08 /* Signal myself so that my parent can wait for me */ rc = do_kill(proc->ftn->pid, -1, SIGTRAP, &info); if (rc < 0) { kprintf("ptrace_report_exec,do_kill failed\n"); } +#else + dkprintf("ptrace_report_exec,kill SIGCHLD\n"); +#endif if (proc->ftn->parent) { /* kill SIGCHLD */ ihk_mc_spinlock_lock_noirq(&proc->ftn->parent->lock); @@ -1416,7 +1421,7 @@ static int ptrace_report_exec(struct process *proc) info._sifields._sigchld.si_status = PS_TRACED; rc = do_kill(proc->ftn->parent->owner->pid, -1, SIGCHLD, &info); if(rc < 0) { - kprintf("ptrace_report_exec,do_kill failed\n"); + dkprintf("ptrace_report_exec,do_kill failed\n"); } } ihk_mc_spinlock_unlock_noirq(&proc->ftn->parent->lock); @@ -1424,6 +1429,13 @@ static int ptrace_report_exec(struct process *proc) /* Wake parent (if sleeping in wait4()) */ waitq_wakeup(&proc->ftn->parent->waitpid_q); } + + /* Sleep */ + dkprintf("ptrace_report_exec,sleeping\n"); + proc->status = PS_TRACED; + + schedule(); + dkprintf("ptrace_report_exec,woken up\n"); out: return error;