summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_exit.c
diff options
context:
space:
mode:
authorjonathan <jonathan@FreeBSD.org>2011-08-18 22:51:30 +0000
committerjonathan <jonathan@FreeBSD.org>2011-08-18 22:51:30 +0000
commit5ecd1c9d4080f3ae8a48c02523542b308b562160 (patch)
treeec80efcada771dd68fe28d71eaf850289af0e772 /sys/kern/kern_exit.c
parentc902e656105666eb86ca08b9d534253d3f831d46 (diff)
downloadFreeBSD-src-5ecd1c9d4080f3ae8a48c02523542b308b562160.zip
FreeBSD-src-5ecd1c9d4080f3ae8a48c02523542b308b562160.tar.gz
Add experimental support for process descriptors
A "process descriptor" file descriptor is used to manage processes without using the PID namespace. This is required for Capsicum's Capability Mode, where the PID namespace is unavailable. New system calls pdfork(2) and pdkill(2) offer the functional equivalents of fork(2) and kill(2). pdgetpid(2) allows querying the PID of the remote process for debugging purposes. The currently-unimplemented pdwait(2) will, in the future, allow querying rusage/exit status. In the interim, poll(2) may be used to check (and wait for) process termination. When a process is referenced by a process descriptor, it does not issue SIGCHLD to the parent, making it suitable for use in libraries---a common scenario when using library compartmentalisation from within large applications (such as web browsers). Some observers may note a similarity to Mach task ports; process descriptors provide a subset of this behaviour, but in a UNIX style. This feature is enabled by "options PROCDESC", but as with several other Capsicum kernel features, is not enabled by default in GENERIC 9.0. Reviewed by: jhb, kib Approved by: re (kib), mentor (rwatson) Sponsored by: Google Inc
Diffstat (limited to 'sys/kern/kern_exit.c')
-rw-r--r--sys/kern/kern_exit.c82
1 files changed, 52 insertions, 30 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 30b94b6..e5d6094 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -40,16 +40,19 @@ __FBSDID("$FreeBSD$");
#include "opt_compat.h"
#include "opt_kdtrace.h"
#include "opt_ktrace.h"
+#include "opt_procdesc.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
+#include <sys/capability.h>
#include <sys/eventhandler.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/procdesc.h>
#include <sys/pioctl.h>
#include <sys/jail.h>
#include <sys/tty.h>
@@ -461,39 +464,54 @@ exit1(struct thread *td, int rv)
knlist_clear(&p->p_klist, 1);
/*
- * Notify parent that we're gone. If parent has the PS_NOCLDWAIT
- * flag set, or if the handler is set to SIG_IGN, notify process
- * 1 instead (and hope it will handle this situation).
+ * If this is a process with a descriptor, we may not need to deliver
+ * a signal to the parent. proctree_lock is held over
+ * procdesc_exit() to serialize concurrent calls to close() and
+ * exit().
*/
- PROC_LOCK(p->p_pptr);
- mtx_lock(&p->p_pptr->p_sigacts->ps_mtx);
- if (p->p_pptr->p_sigacts->ps_flag & (PS_NOCLDWAIT | PS_CLDSIGIGN)) {
- struct proc *pp;
-
- mtx_unlock(&p->p_pptr->p_sigacts->ps_mtx);
- pp = p->p_pptr;
- PROC_UNLOCK(pp);
- proc_reparent(p, initproc);
- p->p_sigparent = SIGCHLD;
- PROC_LOCK(p->p_pptr);
-
+#ifdef PROCDESC
+ if (p->p_procdesc == NULL || procdesc_exit(p)) {
+#endif
/*
- * Notify parent, so in case he was wait(2)ing or
- * executing waitpid(2) with our pid, he will
- * continue.
+ * Notify parent that we're gone. If parent has the
+ * PS_NOCLDWAIT flag set, or if the handler is set to SIG_IGN,
+ * notify process 1 instead (and hope it will handle this
+ * situation).
*/
- wakeup(pp);
+ PROC_LOCK(p->p_pptr);
+ mtx_lock(&p->p_pptr->p_sigacts->ps_mtx);
+ if (p->p_pptr->p_sigacts->ps_flag &
+ (PS_NOCLDWAIT | PS_CLDSIGIGN)) {
+ struct proc *pp;
+
+ mtx_unlock(&p->p_pptr->p_sigacts->ps_mtx);
+ pp = p->p_pptr;
+ PROC_UNLOCK(pp);
+ proc_reparent(p, initproc);
+ p->p_sigparent = SIGCHLD;
+ PROC_LOCK(p->p_pptr);
+
+ /*
+ * Notify parent, so in case he was wait(2)ing or
+ * executing waitpid(2) with our pid, he will
+ * continue.
+ */
+ wakeup(pp);
+ } else
+ mtx_unlock(&p->p_pptr->p_sigacts->ps_mtx);
+
+ if (p->p_pptr == initproc)
+ psignal(p->p_pptr, SIGCHLD);
+ else if (p->p_sigparent != 0) {
+ if (p->p_sigparent == SIGCHLD)
+ childproc_exited(p);
+ else /* LINUX thread */
+ psignal(p->p_pptr, p->p_sigparent);
+ }
+#ifdef PROCDESC
} else
- mtx_unlock(&p->p_pptr->p_sigacts->ps_mtx);
-
- if (p->p_pptr == initproc)
- psignal(p->p_pptr, SIGCHLD);
- else if (p->p_sigparent != 0) {
- if (p->p_sigparent == SIGCHLD)
- childproc_exited(p);
- else /* LINUX thread */
- psignal(p->p_pptr, p->p_sigparent);
- }
+ PROC_LOCK(p->p_pptr);
+#endif
sx_xunlock(&proctree_lock);
/*
@@ -660,7 +678,7 @@ wait4(struct thread *td, struct wait_args *uap)
* rusage. Asserts and will release both the proctree_lock and the process
* lock as part of its work.
*/
-static void
+void
proc_reap(struct thread *td, struct proc *p, int *status, int options,
struct rusage *rusage)
{
@@ -722,6 +740,10 @@ proc_reap(struct thread *td, struct proc *p, int *status, int options,
sx_xunlock(&allproc_lock);
LIST_REMOVE(p, p_sibling);
leavepgrp(p);
+#ifdef PROCDESC
+ if (p->p_procdesc != NULL)
+ procdesc_reap(p);
+#endif
sx_xunlock(&proctree_lock);
/*
OpenPOWER on IntegriCloud