Add some checks to ensure that Capsicum is behaving correctly, and add some
more explicit comments about what's going on and what future maintainers need to do when e.g. adding a new operation to a sys_machdep.c. Approved by: mentor(rwatson), re(bz)
This commit is contained in:
parent
2f39985f00
commit
12bc222e57
@ -182,7 +182,9 @@ sysarch(td, uap)
|
|||||||
|
|
||||||
#ifdef CAPABILITY_MODE
|
#ifdef CAPABILITY_MODE
|
||||||
/*
|
/*
|
||||||
* Whitelist of operations which are safe enough for capability mode.
|
* When adding new operations, add a new case statement here to
|
||||||
|
* explicitly indicate whether or not the operation is safe to
|
||||||
|
* perform in capability mode.
|
||||||
*/
|
*/
|
||||||
if (IN_CAPABILITY_MODE(td)) {
|
if (IN_CAPABILITY_MODE(td)) {
|
||||||
switch (uap->op) {
|
switch (uap->op) {
|
||||||
|
@ -109,7 +109,9 @@ sysarch(td, uap)
|
|||||||
|
|
||||||
#ifdef CAPABILITY_MODE
|
#ifdef CAPABILITY_MODE
|
||||||
/*
|
/*
|
||||||
* Whitelist of operations which are safe enough for capability mode.
|
* When adding new operations, add a new case statement here to
|
||||||
|
* explicitly indicate whether or not the operation is safe to
|
||||||
|
* perform in capability mode.
|
||||||
*/
|
*/
|
||||||
if (IN_CAPABILITY_MODE(td)) {
|
if (IN_CAPABILITY_MODE(td)) {
|
||||||
switch (uap->op) {
|
switch (uap->op) {
|
||||||
|
@ -113,7 +113,9 @@ sysarch(td, uap)
|
|||||||
|
|
||||||
#ifdef CAPABILITY_MODE
|
#ifdef CAPABILITY_MODE
|
||||||
/*
|
/*
|
||||||
* Whitelist of operations which are safe enough for capability mode.
|
* When adding new operations, add a new case statement here to
|
||||||
|
* explicitly indicate whether or not the operation is safe to
|
||||||
|
* perform in capability mode.
|
||||||
*/
|
*/
|
||||||
if (IN_CAPABILITY_MODE(td)) {
|
if (IN_CAPABILITY_MODE(td)) {
|
||||||
switch (uap->op) {
|
switch (uap->op) {
|
||||||
|
@ -31,10 +31,12 @@
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "opt_capsicum.h"
|
||||||
#include "opt_compat.h"
|
#include "opt_compat.h"
|
||||||
#include "opt_core.h"
|
#include "opt_core.h"
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#include <sys/capability.h>
|
||||||
#include <sys/exec.h>
|
#include <sys/exec.h>
|
||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
#include <sys/imgact.h>
|
#include <sys/imgact.h>
|
||||||
@ -578,6 +580,15 @@ __elfN(load_file)(struct proc *p, const char *file, u_long *addr,
|
|||||||
u_long base_addr = 0;
|
u_long base_addr = 0;
|
||||||
int vfslocked, error, i, numsegs;
|
int vfslocked, error, i, numsegs;
|
||||||
|
|
||||||
|
#ifdef CAPABILITY_MODE
|
||||||
|
/*
|
||||||
|
* XXXJA: This check can go away once we are sufficiently confident
|
||||||
|
* that the checks in namei() are correct.
|
||||||
|
*/
|
||||||
|
if (IN_CAPABILITY_MODE(curthread))
|
||||||
|
return (ECAPMODE);
|
||||||
|
#endif
|
||||||
|
|
||||||
tempdata = malloc(sizeof(*tempdata), M_TEMP, M_WAITOK);
|
tempdata = malloc(sizeof(*tempdata), M_TEMP, M_WAITOK);
|
||||||
nd = &tempdata->nd;
|
nd = &tempdata->nd;
|
||||||
attr = &tempdata->attr;
|
attr = &tempdata->attr;
|
||||||
|
@ -27,12 +27,14 @@
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "opt_capsicum.h"
|
||||||
#include "opt_hwpmc_hooks.h"
|
#include "opt_hwpmc_hooks.h"
|
||||||
#include "opt_kdtrace.h"
|
#include "opt_kdtrace.h"
|
||||||
#include "opt_ktrace.h"
|
#include "opt_ktrace.h"
|
||||||
#include "opt_vm.h"
|
#include "opt_vm.h"
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#include <sys/capability.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
#include <sys/eventhandler.h>
|
#include <sys/eventhandler.h>
|
||||||
#include <sys/lock.h>
|
#include <sys/lock.h>
|
||||||
@ -415,6 +417,18 @@ do_execve(td, args, mac_p)
|
|||||||
|
|
||||||
interpret:
|
interpret:
|
||||||
if (args->fname != NULL) {
|
if (args->fname != NULL) {
|
||||||
|
#ifdef CAPABILITY_MODE
|
||||||
|
/*
|
||||||
|
* While capability mode can't reach this point via direct
|
||||||
|
* path arguments to execve(), we also don't allow
|
||||||
|
* interpreters to be used in capability mode (for now).
|
||||||
|
* Catch indirect lookups and return a permissions error.
|
||||||
|
*/
|
||||||
|
if (IN_CAPABILITY_MODE(td)) {
|
||||||
|
error = ECAPMODE;
|
||||||
|
goto exec_fail;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
error = namei(&nd);
|
error = namei(&nd);
|
||||||
if (error)
|
if (error)
|
||||||
goto exec_fail;
|
goto exec_fail;
|
||||||
@ -631,6 +645,13 @@ do_execve(td, args, mac_p)
|
|||||||
* Don't honor setuid/setgid if the filesystem prohibits it or if
|
* Don't honor setuid/setgid if the filesystem prohibits it or if
|
||||||
* the process is being traced.
|
* the process is being traced.
|
||||||
*
|
*
|
||||||
|
* We disable setuid/setgid/etc in compatibility mode on the basis
|
||||||
|
* that most setugid applications are not written with that
|
||||||
|
* environment in mind, and will therefore almost certainly operate
|
||||||
|
* incorrectly. In principle there's no reason that setugid
|
||||||
|
* applications might not be useful in capability mode, so we may want
|
||||||
|
* to reconsider this conservative design choice in the future.
|
||||||
|
*
|
||||||
* XXXMAC: For the time being, use NOSUID to also prohibit
|
* XXXMAC: For the time being, use NOSUID to also prohibit
|
||||||
* transitions on the file system.
|
* transitions on the file system.
|
||||||
*/
|
*/
|
||||||
@ -646,6 +667,9 @@ do_execve(td, args, mac_p)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (credential_changing &&
|
if (credential_changing &&
|
||||||
|
#ifdef CAPABILITY_MODE
|
||||||
|
((oldcred->cr_flags & CRED_FLAG_CAPMODE) == 0) &&
|
||||||
|
#endif
|
||||||
(imgp->vp->v_mount->mnt_flag & MNT_NOSUID) == 0 &&
|
(imgp->vp->v_mount->mnt_flag & MNT_NOSUID) == 0 &&
|
||||||
(p->p_flag & P_TRACED) == 0) {
|
(p->p_flag & P_TRACED) == 0) {
|
||||||
/*
|
/*
|
||||||
|
@ -55,7 +55,10 @@
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "opt_capsicum.h"
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
#include <sys/capability.h>
|
||||||
#include <sys/fcntl.h>
|
#include <sys/fcntl.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/filedesc.h>
|
#include <sys/filedesc.h>
|
||||||
@ -486,6 +489,14 @@ shm_open(struct thread *td, struct shm_open_args *uap)
|
|||||||
mode_t cmode;
|
mode_t cmode;
|
||||||
int fd, error;
|
int fd, error;
|
||||||
|
|
||||||
|
#ifdef CAPABILITY_MODE
|
||||||
|
/*
|
||||||
|
* shm_open(2) is only allowed for anonymous objects.
|
||||||
|
*/
|
||||||
|
if (IN_CAPABILITY_MODE(td) && (uap->path != SHM_ANON))
|
||||||
|
return (ECAPMODE);
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((uap->flags & O_ACCMODE) != O_RDONLY &&
|
if ((uap->flags & O_ACCMODE) != O_RDONLY &&
|
||||||
(uap->flags & O_ACCMODE) != O_RDWR)
|
(uap->flags & O_ACCMODE) != O_RDWR)
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "opt_capsicum.h"
|
||||||
#include "opt_inet.h"
|
#include "opt_inet.h"
|
||||||
#include "opt_inet6.h"
|
#include "opt_inet6.h"
|
||||||
#include "opt_sctp.h"
|
#include "opt_sctp.h"
|
||||||
@ -43,6 +44,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
|
#include <sys/capability.h>
|
||||||
#include <sys/kernel.h>
|
#include <sys/kernel.h>
|
||||||
#include <sys/lock.h>
|
#include <sys/lock.h>
|
||||||
#include <sys/mutex.h>
|
#include <sys/mutex.h>
|
||||||
@ -675,6 +677,11 @@ sendit(td, s, mp, flags)
|
|||||||
struct sockaddr *to;
|
struct sockaddr *to;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
#ifdef CAPABILITY_MODE
|
||||||
|
if (IN_CAPABILITY_MODE(td) && (mp->msg_name != NULL))
|
||||||
|
return (ECAPMODE);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (mp->msg_name != NULL) {
|
if (mp->msg_name != NULL) {
|
||||||
error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
|
error = getsockaddr(&to, mp->msg_name, mp->msg_namelen);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -26,8 +26,11 @@
|
|||||||
* $FreeBSD$
|
* $FreeBSD$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "opt_capsicum.h"
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
|
#include <sys/capability.h>
|
||||||
#include <sys/lock.h>
|
#include <sys/lock.h>
|
||||||
#include <sys/malloc.h>
|
#include <sys/malloc.h>
|
||||||
#include <sys/mutex.h>
|
#include <sys/mutex.h>
|
||||||
@ -53,6 +56,24 @@ sysarch(struct thread *td, struct sysarch_args *uap)
|
|||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
|
#ifdef CAPABILITY_MODE
|
||||||
|
/*
|
||||||
|
* When adding new operations, add a new case statement here to
|
||||||
|
* explicitly indicate whether or not the operation is safe to
|
||||||
|
* perform in capability mode.
|
||||||
|
*/
|
||||||
|
if (IN_CAPABILITY_MODE(td)) {
|
||||||
|
switch (uap->op) {
|
||||||
|
case SPARC_SIGTRAMP_INSTALL:
|
||||||
|
case SPARC_UTRAP_INSTALL:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return (ECAPMODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
mtx_lock(&Giant);
|
mtx_lock(&Giant);
|
||||||
switch (uap->op) {
|
switch (uap->op) {
|
||||||
case SPARC_SIGTRAMP_INSTALL:
|
case SPARC_SIGTRAMP_INSTALL:
|
||||||
|
Loading…
Reference in New Issue
Block a user