summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_exit.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2006-02-22 18:57:50 +0000
committerjhb <jhb@FreeBSD.org>2006-02-22 18:57:50 +0000
commitff9c76bccdce7ca4977a4aea65187a8023b391c2 (patch)
tree51c4862ad08a234b42fff5687f7a934be133894b /sys/kern/kern_exit.c
parent4793b3db380bcaac1d396101ed11d3b3001642e5 (diff)
downloadFreeBSD-src-ff9c76bccdce7ca4977a4aea65187a8023b391c2.zip
FreeBSD-src-ff9c76bccdce7ca4977a4aea65187a8023b391c2.tar.gz
Close some races between procfs/ptrace and exit(2):
- Reorder the events in exit(2) slightly so that we trigger the S_EXIT stop event earlier. After we have signalled that, we set P_WEXIT and then wait for any processes with a hold on the vmspace via PHOLD to release it. PHOLD now KASSERT()'s that P_WEXIT is clear when it is invoked, and PRELE now does a wakeup if P_WEXIT is set and p_lock drops to zero. - Change proc_rwmem() to require that the processing read from has its vmspace held via PHOLD by the caller and get rid of all the junk to screw around with the vmspace reference count as we no longer need it. - In ptrace() and pseudofs(), treat a process with P_WEXIT set as if it doesn't exist. - Only do one PHOLD in kern_ptrace() now, and do it earlier so it covers FIX_SSTEP() (since on alpha at least this can end up calling proc_rwmem() to clear an earlier single-step simualted via a breakpoint). We only do one to avoid races. Also, by making the EINVAL error for unknown requests be part of the default: case in the switch, the various switch cases can now just break out to return which removes a _lot_ of duplicated PRELE and proc unlocks, etc. Also, it fixes at least one bug where a LWP ptrace command could return EINVAL with the proc lock still held. - Changed the locking for ptrace_single_step(), ptrace_set_pc(), and ptrace_clear_single_step() to always be called with the proc lock held (it was a mixed bag previously). Alpha and arm have to drop the lock while the mess around with breakpoints, but other archs avoid extra lock release/acquires in ptrace(). I did have to fix a couple of other consumers in kern_kse and a few other places to hold the proc lock and PHOLD. Tested by: ps (1 mostly, but some bits of 2-4 as well) MFC after: 1 week
Diffstat (limited to 'sys/kern/kern_exit.c')
-rw-r--r--sys/kern/kern_exit.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 5785e0b..0738e69 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -175,7 +175,29 @@ retry:
*/
}
+ /*
+ * Wakeup anyone in procfs' PIOCWAIT. They should have a hold
+ * on our vmspace, so we should block below until they have
+ * released their reference to us. Note that if they have
+ * requested S_EXIT stops we will block here until they ack
+ * via PIOCCONT.
+ */
+ _STOPEVENT(p, S_EXIT, rv);
+
+ /*
+ * Note that we are exiting and do another wakeup of anyone in
+ * PIOCWAIT in case they aren't listening for S_EXIT stops or
+ * decided to wait again after we told them we are exiting.
+ */
p->p_flag |= P_WEXIT;
+ wakeup(&p->p_stype);
+
+ /*
+ * Wait for any processes that have a hold on our vmspace to
+ * release their reference.
+ */
+ while (p->p_lock > 0)
+ msleep(&p->p_lock, &p->p_mtx, PWAIT, "exithold", 0);
PROC_LOCK(p->p_pptr);
sigqueue_take(p->p_ksi);
@@ -209,11 +231,6 @@ retry:
mtx_unlock(&ppeers_lock);
}
- PROC_LOCK(p);
- _STOPEVENT(p, S_EXIT, rv);
- wakeup(&p->p_stype); /* Wakeup anyone in procfs' PIOCWAIT */
- PROC_UNLOCK(p);
-
/*
* Check if any loadable modules need anything done at process exit.
* E.g. SYSV IPC stuff
OpenPOWER on IntegriCloud