From 48ce43499ce953b232ae9c96e4362a122610f87d Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Wed, 28 Oct 2015 19:36:29 +0000 Subject: OS-4899 lxbrand signal ignorance impossible in former ptracees Reviewed by: Jerry Jelinek Reviewed by: Joshua M. Clulow --- usr/src/uts/common/brand/lx/os/lx_ptrace.c | 29 +++++++++++++++++++++-------- usr/src/uts/common/brand/lx/sys/lx_brand.h | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'usr/src') diff --git a/usr/src/uts/common/brand/lx/os/lx_ptrace.c b/usr/src/uts/common/brand/lx/os/lx_ptrace.c index 5728ea2736..ae697c33d4 100644 --- a/usr/src/uts/common/brand/lx/os/lx_ptrace.c +++ b/usr/src/uts/common/brand/lx/os/lx_ptrace.c @@ -898,9 +898,7 @@ static int lx_ptrace_detach(lx_ptrace_accord_t *accord, lx_lwp_data_t *remote, int signo, boolean_t *release_hold) { - klwp_t *rlwp; - - rlwp = remote->br_lwp; + klwp_t *rlwp = remote->br_lwp; /* * The tracee LWP was in "ptrace-stop" and we now hold its p_lock. @@ -917,6 +915,11 @@ lx_ptrace_detach(lx_ptrace_accord_t *accord, lx_lwp_data_t *remote, int signo, remote->br_ptrace_flags = 0; *release_hold = B_TRUE; + /* + * Decrement traced-lwp count for the process. + */ + VERIFY(ptolxproc(rlwp->lwp_procp)->l_ptrace-- >= 1); + /* * The tracer may, as described in lx_ptrace_cont(), choose to suppress * or modify the delivered signal. @@ -1054,10 +1057,10 @@ lx_ptrace_attach(pid_t lx_pid) sigtoproc(rproc, rthr, SIGSTOP); /* - * Set the in-kernel process-wide ptrace(2) enable flag. + * Bump traced-lwp count for the remote process. */ rprocd = ttolxproc(rthr); - rprocd->l_ptrace = 1; + rprocd->l_ptrace++; error = 0; } @@ -1326,10 +1329,9 @@ lx_ptrace_traceme(void) lx_ptrace_accord_exit(accord); /* - * Set the in-kernel process-wide ptrace(2) enable - * flag. + * Bump traced-lwp count for the process. */ - procd->l_ptrace = 1; + procd->l_ptrace++; return (0); } @@ -1787,6 +1789,11 @@ lx_ptrace_exit_tracer(proc_t *p, lx_lwp_data_t *lwpd, */ mutex_exit(&accord->lxpa_tracees_lock); + /* + * Decrement traced-lwp count for the remote process. + */ + VERIFY(ptolxproc(rproc)->l_ptrace-- >= 1); + /* * Ensure that the LWP is not stopped on our account. */ @@ -1857,6 +1864,12 @@ lx_ptrace_exit_tracee(proc_t *p, lx_lwp_data_t *lwpd, * Wake up any tracers waiting for us to detach from the accord. */ cv_broadcast(&lx_ptrace_busy_cv); + + /* + * Decrement traced-lwp count for the process. + */ + VERIFY(ptolxproc(p)->l_ptrace-- >= 1); + mutex_exit(&p->p_lock); mutex_exit(&accord->lxpa_tracees_lock); diff --git a/usr/src/uts/common/brand/lx/sys/lx_brand.h b/usr/src/uts/common/brand/lx/sys/lx_brand.h index 1b00691ba5..a7c4ee9320 100644 --- a/usr/src/uts/common/brand/lx/sys/lx_brand.h +++ b/usr/src/uts/common/brand/lx/sys/lx_brand.h @@ -282,7 +282,7 @@ typedef struct { typedef struct lx_proc_data { uintptr_t l_handler; /* address of user-space handler */ pid_t l_ppid; /* pid of originating parent proc */ - uint64_t l_ptrace; /* process being observed with ptrace */ + int64_t l_ptrace; /* count of process lwps observed by ptrace */ lx_elf_data_t l_elf_data; /* ELF data for linux executable */ /* signal to deliver to parent when this thread group dies */ int l_signal; -- cgit v1.2.3