summaryrefslogtreecommitdiffstats
path: root/sys/compat
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2015-07-31 10:21:58 +0000
committered <ed@FreeBSD.org>2015-07-31 10:21:58 +0000
commit4495c371251050b14823207dcc34631edc6d4d99 (patch)
tree3af076b2b6a63198d599f44bbb24b732d181ad1e /sys/compat
parente531f93218eb20b5cc257f92063eb1034dacd004 (diff)
downloadFreeBSD-src-4495c371251050b14823207dcc34631edc6d4d99.zip
FreeBSD-src-4495c371251050b14823207dcc34631edc6d4d99.tar.gz
Limit rights on process descriptors.
On CloudABI, the rights bits returned by cap_rights_get() match up with the operations that you can actually perform on the file descriptor. Limiting the rights is good, because it makes it easier to get uniform behaviour across different operating systems. If process descriptors on FreeBSD would suddenly gain support for any new file operation, this wouldn't become exposed to CloudABI processes without first extending the rights. Extend fork1() to gain a 'struct filecaps' argument that allows you to construct process descriptors with custom rights. Use this in cloudabi_sys_proc_fork() to limit the rights to just fstat() and pdwait(). Obtained from: https://github.com/NuxiNL/freebsd
Diffstat (limited to 'sys/compat')
-rw-r--r--sys/compat/cloudabi/cloudabi_proc.c6
-rw-r--r--sys/compat/linux/linux_fork.c8
2 files changed, 9 insertions, 5 deletions
diff --git a/sys/compat/cloudabi/cloudabi_proc.c b/sys/compat/cloudabi/cloudabi_proc.c
index 1f4418f..b071aa3 100644
--- a/sys/compat/cloudabi/cloudabi_proc.c
+++ b/sys/compat/cloudabi/cloudabi_proc.c
@@ -27,6 +27,8 @@
__FBSDID("$FreeBSD$");
#include <sys/param.h>
+#include <sys/capsicum.h>
+#include <sys/filedesc.h>
#include <sys/imgact.h>
#include <sys/lock.h>
#include <sys/mutex.h>
@@ -67,10 +69,12 @@ int
cloudabi_sys_proc_fork(struct thread *td,
struct cloudabi_sys_proc_fork_args *uap)
{
+ struct filecaps fcaps = {};
struct proc *p2;
int error, fd;
- error = fork1(td, RFFDG | RFPROC | RFPROCDESC, 0, &p2, &fd, 0);
+ cap_rights_init(&fcaps.fc_rights, CAP_FSTAT, CAP_PDWAIT);
+ error = fork1(td, RFFDG | RFPROC | RFPROCDESC, 0, &p2, &fd, 0, &fcaps);
if (error != 0)
return (error);
/* Return the file descriptor to the parent process. */
diff --git a/sys/compat/linux/linux_fork.c b/sys/compat/linux/linux_fork.c
index 6b37490..a8bf720 100644
--- a/sys/compat/linux/linux_fork.c
+++ b/sys/compat/linux/linux_fork.c
@@ -73,8 +73,8 @@ linux_fork(struct thread *td, struct linux_fork_args *args)
printf(ARGS(fork, ""));
#endif
- if ((error = fork1(td, RFFDG | RFPROC | RFSTOPPED, 0, &p2, NULL, 0))
- != 0)
+ if ((error = fork1(td, RFFDG | RFPROC | RFSTOPPED, 0, &p2, NULL, 0,
+ NULL)) != 0)
return (error);
td2 = FIRST_THREAD_IN_PROC(p2);
@@ -108,7 +108,7 @@ linux_vfork(struct thread *td, struct linux_vfork_args *args)
/* Exclude RFPPWAIT */
if ((error = fork1(td, RFFDG | RFPROC | RFMEM | RFSTOPPED, 0, &p2,
- NULL, 0)) != 0)
+ NULL, 0, NULL)) != 0)
return (error);
@@ -179,7 +179,7 @@ linux_clone_proc(struct thread *td, struct linux_clone_args *args)
if (args->parent_tidptr == NULL)
return (EINVAL);
- error = fork1(td, ff, 0, &p2, NULL, 0);
+ error = fork1(td, ff, 0, &p2, NULL, 0, NULL);
if (error)
return (error);
OpenPOWER on IntegriCloud