1*8269e767SBrooks Davis.\" 2*8269e767SBrooks Davis.\" Copyright (c) 2008-2009 Robert N. M. Watson 3*8269e767SBrooks Davis.\" All rights reserved. 4*8269e767SBrooks Davis.\" 5*8269e767SBrooks Davis.\" This software was developed at the University of Cambridge Computer 6*8269e767SBrooks Davis.\" Laboratory with support from a grant from Google, Inc. 7*8269e767SBrooks Davis.\" 8*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 9*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 10*8269e767SBrooks Davis.\" are met: 11*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 12*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 13*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 14*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 15*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 16*8269e767SBrooks Davis.\" 17*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27*8269e767SBrooks Davis.\" SUCH DAMAGE. 28*8269e767SBrooks Davis.\" 29*8269e767SBrooks Davis.Dd March 9, 2023 30*8269e767SBrooks Davis.Dt CAP_ENTER 2 31*8269e767SBrooks Davis.Os 32*8269e767SBrooks Davis.Sh NAME 33*8269e767SBrooks Davis.Nm cap_enter , 34*8269e767SBrooks Davis.Nm cap_getmode 35*8269e767SBrooks Davis.Nd Capability mode system calls 36*8269e767SBrooks Davis.Sh LIBRARY 37*8269e767SBrooks Davis.Lb libc 38*8269e767SBrooks Davis.Sh SYNOPSIS 39*8269e767SBrooks Davis.In sys/capsicum.h 40*8269e767SBrooks Davis.Ft int 41*8269e767SBrooks Davis.Fn cap_enter "void" 42*8269e767SBrooks Davis.Ft int 43*8269e767SBrooks Davis.Fn cap_getmode "u_int *modep" 44*8269e767SBrooks Davis.Sh DESCRIPTION 45*8269e767SBrooks Davis.Fn cap_enter 46*8269e767SBrooks Davisplaces the current process into capability mode, a mode of execution in which 47*8269e767SBrooks Davisprocesses may only issue system calls operating on file descriptors or 48*8269e767SBrooks Davisreading limited global system state. 49*8269e767SBrooks DavisAccess to global name spaces, such as file system or IPC name spaces, is 50*8269e767SBrooks Davisprevented. 51*8269e767SBrooks DavisIf the process is already in a capability mode sandbox, the system call is a 52*8269e767SBrooks Davisno-op. 53*8269e767SBrooks DavisFuture process descendants created with 54*8269e767SBrooks Davis.Xr fork 2 55*8269e767SBrooks Davisor 56*8269e767SBrooks Davis.Xr pdfork 2 57*8269e767SBrooks Daviswill be placed in capability mode from inception. 58*8269e767SBrooks Davis.Pp 59*8269e767SBrooks DavisWhen combined with 60*8269e767SBrooks Davis.Xr cap_rights_limit 2 , 61*8269e767SBrooks Davis.Xr cap_ioctls_limit 2 , 62*8269e767SBrooks Davis.Xr cap_fcntls_limit 2 , 63*8269e767SBrooks Davis.Fn cap_enter 64*8269e767SBrooks Davismay be used to create kernel-enforced sandboxes in which 65*8269e767SBrooks Davisappropriately-crafted applications or application components may be run. 66*8269e767SBrooks Davis.Pp 67*8269e767SBrooks Davis.Fn cap_getmode 68*8269e767SBrooks Davisreturns a flag indicating whether or not the process is in a capability mode 69*8269e767SBrooks Davissandbox. 70*8269e767SBrooks Davis.Sh RUN-TIME SETTINGS 71*8269e767SBrooks DavisIf the 72*8269e767SBrooks Davis.Dv kern.trap_enotcap 73*8269e767SBrooks Davissysctl MIB is set to a non-zero value, then for any process executing in a 74*8269e767SBrooks Daviscapability mode sandbox, any syscall which results in either an 75*8269e767SBrooks Davis.Er ENOTCAPABLE 76*8269e767SBrooks Davisor 77*8269e767SBrooks Davis.Er ECAPMODE 78*8269e767SBrooks Daviserror also generates the synchronous 79*8269e767SBrooks Davis.Dv SIGTRAP 80*8269e767SBrooks Davissignal to the thread on the syscall return. 81*8269e767SBrooks DavisOn signal delivery, the 82*8269e767SBrooks Davis.Va si_errno 83*8269e767SBrooks Davismember of the 84*8269e767SBrooks Davis.Fa siginfo 85*8269e767SBrooks Davissignal handler parameter is set to the syscall error value, 86*8269e767SBrooks Davisand the 87*8269e767SBrooks Davis.Va si_code 88*8269e767SBrooks Davismember is set to 89*8269e767SBrooks Davis.Dv TRAP_CAP . 90*8269e767SBrooks Davis.Pp 91*8269e767SBrooks DavisSee also the 92*8269e767SBrooks Davis.Dv PROC_TRAPCAP_CTL 93*8269e767SBrooks Davisand 94*8269e767SBrooks Davis.Dv PROC_TRAPCAP_STATUS 95*8269e767SBrooks Davisoperations of the 96*8269e767SBrooks Davis.Xr procctl 2 97*8269e767SBrooks Davisfunction for similar per-process functionality. 98*8269e767SBrooks Davis.Sh RETURN VALUES 99*8269e767SBrooks Davis.Rv -std cap_enter cap_getmode 100*8269e767SBrooks Davis.Pp 101*8269e767SBrooks DavisWhen the process is in capability mode, 102*8269e767SBrooks Davis.Fn cap_getmode 103*8269e767SBrooks Davissets the flag to a non-zero value. 104*8269e767SBrooks DavisA zero value means the process is not in capability mode. 105*8269e767SBrooks Davis.Sh ERRORS 106*8269e767SBrooks DavisThe 107*8269e767SBrooks Davis.Fn cap_enter 108*8269e767SBrooks Davisand 109*8269e767SBrooks Davis.Fn cap_getmode 110*8269e767SBrooks Davissystem calls 111*8269e767SBrooks Daviswill fail if: 112*8269e767SBrooks Davis.Bl -tag -width Er 113*8269e767SBrooks Davis.It Bq Er ENOSYS 114*8269e767SBrooks DavisThe running kernel was compiled without 115*8269e767SBrooks Davis.Cd "options CAPABILITY_MODE" . 116*8269e767SBrooks Davis.El 117*8269e767SBrooks Davis.Pp 118*8269e767SBrooks DavisThe 119*8269e767SBrooks Davis.Fn cap_getmode 120*8269e767SBrooks Davissystem call may also return the following error: 121*8269e767SBrooks Davis.Bl -tag -width Er 122*8269e767SBrooks Davis.It Bq Er EFAULT 123*8269e767SBrooks DavisPointer 124*8269e767SBrooks Davis.Fa modep 125*8269e767SBrooks Davispoints outside the process's allocated address space. 126*8269e767SBrooks Davis.El 127*8269e767SBrooks Davis.Sh SEE ALSO 128*8269e767SBrooks Davis.Xr cap_fcntls_limit 2 , 129*8269e767SBrooks Davis.Xr cap_ioctls_limit 2 , 130*8269e767SBrooks Davis.Xr cap_rights_limit 2 , 131*8269e767SBrooks Davis.Xr fexecve 2 , 132*8269e767SBrooks Davis.Xr procctl 2 , 133*8269e767SBrooks Davis.Xr cap_sandboxed 3 , 134*8269e767SBrooks Davis.Xr capsicum 4 , 135*8269e767SBrooks Davis.Xr sysctl 9 136*8269e767SBrooks Davis.Sh HISTORY 137*8269e767SBrooks DavisThe 138*8269e767SBrooks Davis.Fn cap_getmode 139*8269e767SBrooks Davissystem call first appeared in 140*8269e767SBrooks Davis.Fx 8.3 . 141*8269e767SBrooks DavisSupport for capabilities and capabilities mode was developed as part of the 142*8269e767SBrooks Davis.Tn TrustedBSD 143*8269e767SBrooks DavisProject. 144*8269e767SBrooks Davis.Sh AUTHORS 145*8269e767SBrooks DavisThese functions and the capability facility were created by 146*8269e767SBrooks Davis.An "Robert N. M. Watson" 147*8269e767SBrooks Davisat the University of Cambridge Computer Laboratory with support from a grant 148*8269e767SBrooks Davisfrom Google, Inc. 149*8269e767SBrooks Davis.Sh CAVEATS 150*8269e767SBrooks DavisCreating effective process sandboxes is a tricky process that involves 151*8269e767SBrooks Davisidentifying the least possible rights required by the process and then 152*8269e767SBrooks Davispassing those rights into the process in a safe manner. 153*8269e767SBrooks DavisConsumers of 154*8269e767SBrooks Davis.Fn cap_enter 155*8269e767SBrooks Davisshould also be aware of other inherited rights, such as access to VM 156*8269e767SBrooks Davisresources, memory contents, and other process properties that should be 157*8269e767SBrooks Davisconsidered. 158*8269e767SBrooks DavisIt is advisable to use 159*8269e767SBrooks Davis.Xr fexecve 2 160*8269e767SBrooks Davisto create a runtime environment inside the sandbox that has as few implicitly 161*8269e767SBrooks Davisacquired rights as possible. 162