Skip to content

Commit

Permalink
OS-3882 lxbrand execing processes not stopping for PTRACE_O_TRACEEXEC
Browse files Browse the repository at this point in the history
  • Loading branch information
jjelinek committed Mar 17, 2015
1 parent 2feca3b commit 0905c01
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
10 changes: 10 additions & 0 deletions usr/src/uts/common/brand/lx/os/lx_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ lx_exec()
struct lx_lwp_data *lwpd = lwptolxlwp(lwp);
proc_t *p = ttoproc(curthread);
lx_proc_data_t *pd = ptolxproc(p);
struct regs *rp = lwptoregs(lwp);
int err;

/*
Expand Down Expand Up @@ -145,6 +146,15 @@ lx_exec()
kpreempt_disable();
lx_restore(lwp);
kpreempt_enable();

/*
* The exec syscall doesn't return (so we don't call lx_syscall_return)
* but for our ptrace emulation we need to do this so that a tracer
* does not get out of sync. We know that by the time this lx_exec
* function is called that the exec has succeeded.
*/
rp->r_r0 = 0;
lx_ptrace_stop(LX_PR_SYSEXIT);
}

void
Expand Down
28 changes: 25 additions & 3 deletions usr/src/uts/common/brand/lx/os/lx_ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,17 @@ lx_ptrace_getregs(lx_lwp_data_t *remote, void *uregsp)
*/
return (lx_regs_to_userregs(remote, uregsp));
} else if (remote->br_stack_mode == LX_STACK_MODE_PREINIT &&
remote->br_ptrace_whatstop == LX_PR_SIGNALLED) {
(remote->br_ptrace_whatstop == LX_PR_SIGNALLED ||
remote->br_ptrace_whatstop == LX_PR_SYSEXIT)) {
/*
* The LWP was stopped by tracing on exec. br_ptrace_stopucp
* is NULL. Return the LWP register state.
* The LWP was stopped by tracing on exec.
*/
return (lx_regs_to_userregs(remote, uregsp));
} else if (remote->br_stack_mode == LX_STACK_MODE_NATIVE &&
remote->br_ptrace_whystop == PR_BRAND &&
remote->br_ptrace_whatstop == LX_PR_EVENT) {
/*
* Called while we're ptrace event stopped by lx_exec.
*/
return (lx_regs_to_userregs(remote, uregsp));
} else if (remote->br_ptrace_stopucp != NULL) {
Expand Down Expand Up @@ -1398,15 +1405,30 @@ lx_ptrace_traceme(void)
static boolean_t
lx_ptrace_stop_common(proc_t *p, lx_lwp_data_t *lwpd, ushort_t what)
{
boolean_t reset_nostop = B_FALSE;

VERIFY(MUTEX_HELD(&p->p_lock));

/*
* Mark this LWP as stopping and call stop() to enter "ptrace-stop".
*/
VERIFY0(lwpd->br_ptrace_flags & LX_PTRACE_STOPPING);
lwpd->br_ptrace_flags |= LX_PTRACE_STOPPING;

if (lwpd->br_lwp->lwp_nostop == 1 &&
lwpd->br_ptrace_event == LX_PTRACE_EVENT_EXEC) {
/* We need to clear this to get the signal delivered. */
lwpd->br_lwp->lwp_nostop = 0;
reset_nostop = B_TRUE;
}

stop(PR_BRAND, what);

if (reset_nostop) {
VERIFY(lwpd->br_lwp->lwp_nostop == 0);
lwpd->br_lwp->lwp_nostop = 1;
}

/*
* We are back from "ptrace-stop" with our process lock held.
*/
Expand Down

0 comments on commit 0905c01

Please sign in to comment.