summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_descrip.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_descrip.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_descrip.c')
-rw-r--r--sys/kern/kern_descrip.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 85f866c..4aaed1f 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
#include "opt_compat.h"
#include "opt_ddb.h"
#include "opt_ktrace.h"
+#include "opt_procdesc.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -65,6 +66,7 @@ __FBSDID("$FreeBSD$");
#include <sys/pipe.h>
#include <sys/priv.h>
#include <sys/proc.h>
+#include <sys/procdesc.h>
#include <sys/protosw.h>
#include <sys/racct.h>
#include <sys/resourcevar.h>
@@ -120,6 +122,8 @@ static int fill_vnode_info(struct vnode *vp, struct kinfo_file *kif);
static int fill_socket_info(struct socket *so, struct kinfo_file *kif);
static int fill_pts_info(struct tty *tp, struct kinfo_file *kif);
static int fill_pipe_info(struct pipe *pi, struct kinfo_file *kif);
+static int fill_procdesc_info(struct procdesc *pdp,
+ struct kinfo_file *kif);
/*
* A process is initially started out with NDFILE descriptors stored within
@@ -3056,6 +3060,12 @@ sysctl_kern_proc_ofiledesc(SYSCTL_HANDLER_ARGS)
tp = fp->f_data;
break;
+#ifdef PROCDESC
+ case DTYPE_PROCDESC:
+ kif->kf_type = KF_TYPE_PROCDESC;
+ break;
+#endif
+
default:
kif->kf_type = KF_TYPE_UNKNOWN;
break;
@@ -3218,6 +3228,9 @@ export_fd_for_sysctl(void *data, int type, int fd, int fflags, int refcnt,
case KF_TYPE_PTS:
error = fill_pts_info((struct tty *)data, kif);
break;
+ case KF_TYPE_PROCDESC:
+ error = fill_procdesc_info((struct procdesc *)data, kif);
+ break;
default:
error = 0;
}
@@ -3391,6 +3404,13 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER_ARGS)
data = fp->f_data;
break;
+#ifdef PROCDESC
+ case DTYPE_PROCDESC:
+ type = KF_TYPE_PROCDESC;
+ data = fp->f_data;
+ break;
+#endif
+
default:
type = KF_TYPE_UNKNOWN;
break;
@@ -3586,6 +3606,16 @@ fill_pipe_info(struct pipe *pi, struct kinfo_file *kif)
return (0);
}
+static int
+fill_procdesc_info(struct procdesc *pdp, struct kinfo_file *kif)
+{
+
+ if (pdp == NULL)
+ return (1);
+ kif->kf_un.kf_proc.kf_pid = pdp->pd_pid;
+ return (0);
+}
+
static SYSCTL_NODE(_kern_proc, KERN_PROC_FILEDESC, filedesc, CTLFLAG_RD,
sysctl_kern_proc_filedesc, "Process filedesc entries");
OpenPOWER on IntegriCloud