diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-10-08 09:05:41 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-10-08 09:05:41 +0000 |
commit | 33040064d5ebba69926e42603be268869271dd9f (patch) | |
tree | ed3e7bc9c384fe4154960ff7aaebf37d9bd220f6 /sys/kern/sys_process.c | |
parent | 54458cb4ad3570c34135a7d7301fbe74ed38458f (diff) |
Adjust lock requirements for ps_pptr, ps_ppid and ps_oppid.
ps_pptr, ps_ppid and ps_oppid require the KERNEL_LOCK and the process mutex
to be modified. At the same time either KERNEL_LOCK or process mutex needs
to be taken to read the values.
This is needed to further unlock ptsignal().
OK kettenis@, mvs@
Diffstat (limited to 'sys/kern/sys_process.c')
-rw-r--r-- | sys/kern/sys_process.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 8d9daeb1120..36c402135ae 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_process.c,v 1.100 2024/10/01 08:28:34 claudio Exp $ */ +/* $OpenBSD: sys_process.c,v 1.101 2024/10/08 09:05:40 claudio Exp $ */ /* $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $ */ /*- @@ -288,10 +288,14 @@ ptrace_ctrl(struct proc *p, int req, pid_t pid, caddr_t addr, int data) case PT_TRACE_ME: /* Just set the trace flag. */ tr = p->p_p; - if (ISSET(tr->ps_flags, PS_TRACED)) + mtx_enter(&tr->ps_mtx); + if (ISSET(tr->ps_flags, PS_TRACED)) { + mtx_leave(&tr->ps_mtx); return EBUSY; + } atomic_setbits_int(&tr->ps_flags, PS_TRACED); tr->ps_oppid = tr->ps_ppid; + mtx_leave(&tr->ps_mtx); if (tr->ps_ptstat == NULL) tr->ps_ptstat = malloc(sizeof(*tr->ps_ptstat), M_SUBPROC, M_WAITOK); @@ -489,8 +493,10 @@ ptrace_ctrl(struct proc *p, int req, pid_t pid, caddr_t addr, int data) goto fail; #endif + mtx_enter(&tr->ps_mtx); process_untrace(tr); atomic_clearbits_int(&tr->ps_flags, PS_WAITED); + mtx_leave(&tr->ps_mtx); sendsig: memset(tr->ps_ptstat, 0, sizeof(*tr->ps_ptstat)); @@ -526,9 +532,11 @@ ptrace_ctrl(struct proc *p, int req, pid_t pid, caddr_t addr, int data) * proc gets to see all the action. * Stop the target. */ + mtx_enter(&tr->ps_mtx); atomic_setbits_int(&tr->ps_flags, PS_TRACED); tr->ps_oppid = tr->ps_ppid; process_reparent(tr, p->p_p); + mtx_leave(&tr->ps_mtx); if (tr->ps_ptstat == NULL) tr->ps_ptstat = malloc(sizeof(*tr->ps_ptstat), M_SUBPROC, M_WAITOK); |