160727d8bSWarner Losh /*- 27074cfa2SJamie Gritton * Copyright (c) 1999 Poul-Henning Kamp. 3b38ff370SJamie Gritton * Copyright (c) 2009 James Gritton. 47074cfa2SJamie Gritton * All rights reserved. 57074cfa2SJamie Gritton * 67074cfa2SJamie Gritton * Redistribution and use in source and binary forms, with or without 77074cfa2SJamie Gritton * modification, are permitted provided that the following conditions 87074cfa2SJamie Gritton * are met: 97074cfa2SJamie Gritton * 1. Redistributions of source code must retain the above copyright 107074cfa2SJamie Gritton * notice, this list of conditions and the following disclaimer. 117074cfa2SJamie Gritton * 2. Redistributions in binary form must reproduce the above copyright 127074cfa2SJamie Gritton * notice, this list of conditions and the following disclaimer in the 137074cfa2SJamie Gritton * documentation and/or other materials provided with the distribution. 147074cfa2SJamie Gritton * 157074cfa2SJamie Gritton * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 167074cfa2SJamie Gritton * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 177074cfa2SJamie Gritton * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 187074cfa2SJamie Gritton * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 197074cfa2SJamie Gritton * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 207074cfa2SJamie Gritton * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 217074cfa2SJamie Gritton * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 227074cfa2SJamie Gritton * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 237074cfa2SJamie Gritton * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 247074cfa2SJamie Gritton * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 257074cfa2SJamie Gritton * SUCH DAMAGE. 2675c13541SPoul-Henning Kamp * 27c3aac50fSPeter Wemm * $FreeBSD$ 2875c13541SPoul-Henning Kamp */ 2975c13541SPoul-Henning Kamp 3075c13541SPoul-Henning Kamp #ifndef _SYS_JAIL_H_ 3175c13541SPoul-Henning Kamp #define _SYS_JAIL_H_ 3275c13541SPoul-Henning Kamp 33413628a7SBjoern A. Zeeb #ifdef _KERNEL 34413628a7SBjoern A. Zeeb struct jail_v0 { 35978f8d93SPoul-Henning Kamp u_int32_t version; 3675c13541SPoul-Henning Kamp char *path; 3775c13541SPoul-Henning Kamp char *hostname; 3875c13541SPoul-Henning Kamp u_int32_t ip_number; 3975c13541SPoul-Henning Kamp }; 40413628a7SBjoern A. Zeeb #endif 4175c13541SPoul-Henning Kamp 42413628a7SBjoern A. Zeeb struct jail { 43413628a7SBjoern A. Zeeb uint32_t version; 44413628a7SBjoern A. Zeeb char *path; 45413628a7SBjoern A. Zeeb char *hostname; 46413628a7SBjoern A. Zeeb char *jailname; 47413628a7SBjoern A. Zeeb uint32_t ip4s; 48413628a7SBjoern A. Zeeb uint32_t ip6s; 49413628a7SBjoern A. Zeeb struct in_addr *ip4; 50413628a7SBjoern A. Zeeb struct in6_addr *ip6; 51413628a7SBjoern A. Zeeb }; 52413628a7SBjoern A. Zeeb #define JAIL_API_VERSION 2 53413628a7SBjoern A. Zeeb 54413628a7SBjoern A. Zeeb /* 55413628a7SBjoern A. Zeeb * For all xprison structs, always keep the pr_version an int and 56413628a7SBjoern A. Zeeb * the first variable so userspace can easily distinguish them. 57413628a7SBjoern A. Zeeb */ 58413628a7SBjoern A. Zeeb #ifndef _KERNEL 59413628a7SBjoern A. Zeeb struct xprison_v1 { 60fd7a8150SMike Barcroft int pr_version; 61fd7a8150SMike Barcroft int pr_id; 62fd7a8150SMike Barcroft char pr_path[MAXPATHLEN]; 63fd7a8150SMike Barcroft char pr_host[MAXHOSTNAMELEN]; 64fd7a8150SMike Barcroft u_int32_t pr_ip; 65fd7a8150SMike Barcroft }; 66413628a7SBjoern A. Zeeb #endif 67413628a7SBjoern A. Zeeb 68413628a7SBjoern A. Zeeb struct xprison { 69413628a7SBjoern A. Zeeb int pr_version; 70413628a7SBjoern A. Zeeb int pr_id; 71413628a7SBjoern A. Zeeb int pr_state; 72413628a7SBjoern A. Zeeb cpusetid_t pr_cpusetid; 73413628a7SBjoern A. Zeeb char pr_path[MAXPATHLEN]; 74413628a7SBjoern A. Zeeb char pr_host[MAXHOSTNAMELEN]; 75413628a7SBjoern A. Zeeb char pr_name[MAXHOSTNAMELEN]; 76413628a7SBjoern A. Zeeb uint32_t pr_ip4s; 77413628a7SBjoern A. Zeeb uint32_t pr_ip6s; 78413628a7SBjoern A. Zeeb #if 0 79413628a7SBjoern A. Zeeb /* 80413628a7SBjoern A. Zeeb * sizeof(xprison) will be malloced + size needed for all 81413628a7SBjoern A. Zeeb * IPv4 and IPv6 addesses. Offsets are based numbers of addresses. 82413628a7SBjoern A. Zeeb */ 83413628a7SBjoern A. Zeeb struct in_addr pr_ip4[]; 84413628a7SBjoern A. Zeeb struct in6_addr pr_ip6[]; 85413628a7SBjoern A. Zeeb #endif 86413628a7SBjoern A. Zeeb }; 87413628a7SBjoern A. Zeeb #define XPRISON_VERSION 3 88413628a7SBjoern A. Zeeb 89413628a7SBjoern A. Zeeb #define PRISON_STATE_INVALID 0 90413628a7SBjoern A. Zeeb #define PRISON_STATE_ALIVE 1 91413628a7SBjoern A. Zeeb #define PRISON_STATE_DYING 2 92413628a7SBjoern A. Zeeb 93b38ff370SJamie Gritton /* 94b38ff370SJamie Gritton * Flags for jail_set and jail_get. 95b38ff370SJamie Gritton */ 96b38ff370SJamie Gritton #define JAIL_CREATE 0x01 /* Create jail if it doesn't exist */ 97b38ff370SJamie Gritton #define JAIL_UPDATE 0x02 /* Update parameters of existing jail */ 98b38ff370SJamie Gritton #define JAIL_ATTACH 0x04 /* Attach to jail upon creation */ 99b38ff370SJamie Gritton #define JAIL_DYING 0x08 /* Allow getting a dying jail */ 100b38ff370SJamie Gritton #define JAIL_SET_MASK 0x0f 101b38ff370SJamie Gritton #define JAIL_GET_MASK 0x08 102fd7a8150SMike Barcroft 1037cbf7213SJamie Gritton #define JAIL_SYS_DISABLE 0 1047cbf7213SJamie Gritton #define JAIL_SYS_NEW 1 1057cbf7213SJamie Gritton #define JAIL_SYS_INHERIT 2 1067cbf7213SJamie Gritton 107664a31e4SPeter Wemm #ifndef _KERNEL 108d8bd3ac4SPoul-Henning Kamp 109b38ff370SJamie Gritton struct iovec; 110b38ff370SJamie Gritton 111789f12feSAlfred Perlstein int jail(struct jail *); 112b38ff370SJamie Gritton int jail_set(struct iovec *, unsigned int, int); 113b38ff370SJamie Gritton int jail_get(struct iovec *, unsigned int, int); 114fd7a8150SMike Barcroft int jail_attach(int); 115b38ff370SJamie Gritton int jail_remove(int); 116d8bd3ac4SPoul-Henning Kamp 117664a31e4SPeter Wemm #else /* _KERNEL */ 11875c13541SPoul-Henning Kamp 119607aa34eSBruce Evans #include <sys/queue.h> 120b38ff370SJamie Gritton #include <sys/sysctl.h> 1210304c731SJamie Gritton #include <sys/lock.h> 1220304c731SJamie Gritton #include <sys/mutex.h> 123b3059e09SRobert Watson #include <sys/_task.h> 12401137630SRobert Watson 1252110d913SXin LI #define JAIL_MAX 999999 1262110d913SXin LI 12775c13541SPoul-Henning Kamp #ifdef MALLOC_DECLARE 12875c13541SPoul-Henning Kamp MALLOC_DECLARE(M_PRISON); 12975c13541SPoul-Henning Kamp #endif 130e69f1fa2SPawel Jakub Dawidek #endif /* _KERNEL */ 13175c13541SPoul-Henning Kamp 1321ba4a712SPawel Jakub Dawidek #if defined(_KERNEL) || defined(_WANT_PRISON) 1331ba4a712SPawel Jakub Dawidek 1341ba4a712SPawel Jakub Dawidek #include <sys/osd.h> 1351ba4a712SPawel Jakub Dawidek 13676ca6f88SJamie Gritton #define HOSTUUIDLEN 64 137b96bd95bSIan Lepore #define OSRELEASELEN 32 13876ca6f88SJamie Gritton 139097055e2SEdward Tomasz Napierala struct racct; 140a7ad07bfSEdward Tomasz Napierala struct prison_racct; 141097055e2SEdward Tomasz Napierala 14275c13541SPoul-Henning Kamp /* 14375c13541SPoul-Henning Kamp * This structure describes a prison. It is pointed to by all struct 14491421ba2SRobert Watson * ucreds's of the inmates. pr_ref keeps track of them and is used to 14575c13541SPoul-Henning Kamp * delete the struture when the last inmate is dead. 14691421ba2SRobert Watson * 14701137630SRobert Watson * Lock key: 148dc68a633SPawel Jakub Dawidek * (a) allprison_lock 1494bc6b2afSPawel Jakub Dawidek * (p) locked by pr_mtx 15001137630SRobert Watson * (c) set only during creation before the structure is shared, no mutex 15101137630SRobert Watson * required to read 152b3059e09SRobert Watson * (d) set only during destruction of jail, no mutex needed 15375c13541SPoul-Henning Kamp */ 15475c13541SPoul-Henning Kamp struct prison { 155b38ff370SJamie Gritton TAILQ_ENTRY(prison) pr_list; /* (a) all prisons */ 156fd7a8150SMike Barcroft int pr_id; /* (c) prison id */ 15701137630SRobert Watson int pr_ref; /* (p) refcount */ 158b38ff370SJamie Gritton int pr_uref; /* (p) user (alive) refcount */ 159b38ff370SJamie Gritton unsigned pr_flags; /* (p) PR_* flags */ 1600304c731SJamie Gritton LIST_HEAD(, prison) pr_children; /* (a) list of child jails */ 1610304c731SJamie Gritton LIST_ENTRY(prison) pr_sibling; /* (a) next in parent's list */ 162ca006477SJamie Gritton struct prison *pr_parent; /* (c) containing jail */ 163ca006477SJamie Gritton struct mtx pr_mtx; 164ca006477SJamie Gritton struct task pr_task; /* (d) destroy task */ 165ca006477SJamie Gritton struct osd pr_osd; /* (p) additional data */ 166ca006477SJamie Gritton struct cpuset *pr_cpuset; /* (p) cpuset */ 167ca006477SJamie Gritton struct vnet *pr_vnet; /* (c) network stack */ 168ca006477SJamie Gritton struct vnode *pr_root; /* (c) vnode to rdir */ 169ca006477SJamie Gritton int pr_ip4s; /* (p) number of v4 IPs */ 170ca006477SJamie Gritton int pr_ip6s; /* (p) number of v6 IPs */ 171ca006477SJamie Gritton struct in_addr *pr_ip4; /* (p) v4 IPs of jail */ 172ca006477SJamie Gritton struct in6_addr *pr_ip6; /* (p) v6 IPs of jail */ 173a7ad07bfSEdward Tomasz Napierala struct prison_racct *pr_prison_racct; /* (c) racct jail proxy */ 174097055e2SEdward Tomasz Napierala void *pr_sparep[3]; 175b97457e2SJamie Gritton int pr_childcount; /* (a) number of child jails */ 176ca006477SJamie Gritton int pr_childmax; /* (p) maximum child jails */ 1770304c731SJamie Gritton unsigned pr_allow; /* (p) PR_ALLOW_* flags */ 178ca006477SJamie Gritton int pr_securelevel; /* (p) securelevel */ 1790304c731SJamie Gritton int pr_enforce_statfs; /* (p) statfs permission */ 1800cc207a6SMartin Matuska int pr_devfs_rsnum; /* (p) devfs ruleset */ 181b96bd95bSIan Lepore int pr_spare[3]; 182b96bd95bSIan Lepore int pr_osreldate; /* (c) kern.osreldate value */ 183ca006477SJamie Gritton unsigned long pr_hostid; /* (p) jail hostid */ 184ca006477SJamie Gritton char pr_name[MAXHOSTNAMELEN]; /* (p) admin jail name */ 185ca006477SJamie Gritton char pr_path[MAXPATHLEN]; /* (c) chroot path */ 186ca006477SJamie Gritton char pr_hostname[MAXHOSTNAMELEN]; /* (p) jail hostname */ 187c1f19219SJamie Gritton char pr_domainname[MAXHOSTNAMELEN]; /* (p) jail domainname */ 188c1f19219SJamie Gritton char pr_hostuuid[HOSTUUIDLEN]; /* (p) jail hostuuid */ 189b96bd95bSIan Lepore char pr_osrelease[OSRELEASELEN]; /* (c) kern.osrelease value */ 19075c13541SPoul-Henning Kamp }; 191a7ad07bfSEdward Tomasz Napierala 192a7ad07bfSEdward Tomasz Napierala struct prison_racct { 193a7ad07bfSEdward Tomasz Napierala LIST_ENTRY(prison_racct) prr_next; 194a7ad07bfSEdward Tomasz Napierala char prr_name[MAXHOSTNAMELEN]; 195a7ad07bfSEdward Tomasz Napierala u_int prr_refcount; 196a7ad07bfSEdward Tomasz Napierala struct racct *prr_racct; 197a7ad07bfSEdward Tomasz Napierala }; 198e69f1fa2SPawel Jakub Dawidek #endif /* _KERNEL || _WANT_PRISON */ 19975c13541SPoul-Henning Kamp 200e69f1fa2SPawel Jakub Dawidek #ifdef _KERNEL 2010304c731SJamie Gritton /* Flag bits set via options */ 202b38ff370SJamie Gritton #define PR_PERSIST 0x00000001 /* Can exist without processes */ 20376ca6f88SJamie Gritton #define PR_HOST 0x00000002 /* Virtualize hostname et al */ 2047cbf7213SJamie Gritton #define PR_IP4_USER 0x00000004 /* Restrict IPv4 addresses */ 2057cbf7213SJamie Gritton #define PR_IP6_USER 0x00000008 /* Restrict IPv6 addresses */ 206679e1390SJamie Gritton #define PR_VNET 0x00000010 /* Virtual network stack */ 207592bcae8SBjoern A. Zeeb #define PR_IP4_SADDRSEL 0x00000080 /* Do IPv4 src addr sel. or use the */ 208592bcae8SBjoern A. Zeeb /* primary jail address. */ 209592bcae8SBjoern A. Zeeb #define PR_IP6_SADDRSEL 0x00000100 /* Do IPv6 src addr sel. or use the */ 210592bcae8SBjoern A. Zeeb /* primary jail address. */ 2110304c731SJamie Gritton 2120304c731SJamie Gritton /* Internal flag bits */ 213b38ff370SJamie Gritton #define PR_REMOVE 0x01000000 /* In process of being removed */ 2147cbf7213SJamie Gritton #define PR_IP4 0x02000000 /* IPv4 restricted or disabled */ 2157cbf7213SJamie Gritton /* by this jail or an ancestor */ 2167cbf7213SJamie Gritton #define PR_IP6 0x04000000 /* IPv6 restricted or disabled */ 2177cbf7213SJamie Gritton /* by this jail or an ancestor */ 2180304c731SJamie Gritton 2190304c731SJamie Gritton /* Flags for pr_allow */ 2200304c731SJamie Gritton #define PR_ALLOW_SET_HOSTNAME 0x0001 2210304c731SJamie Gritton #define PR_ALLOW_SYSVIPC 0x0002 2220304c731SJamie Gritton #define PR_ALLOW_RAW_SOCKETS 0x0004 2230304c731SJamie Gritton #define PR_ALLOW_CHFLAGS 0x0008 2240304c731SJamie Gritton #define PR_ALLOW_MOUNT 0x0010 2250304c731SJamie Gritton #define PR_ALLOW_QUOTAS 0x0020 226b97457e2SJamie Gritton #define PR_ALLOW_SOCKET_AF 0x0040 227bf3db8aaSMartin Matuska #define PR_ALLOW_MOUNT_DEVFS 0x0080 228bf3db8aaSMartin Matuska #define PR_ALLOW_MOUNT_NULLFS 0x0100 229e7af90abSMartin Matuska #define PR_ALLOW_MOUNT_ZFS 0x0200 23041c0675eSMartin Matuska #define PR_ALLOW_MOUNT_PROCFS 0x0400 2312454886eSXin LI #define PR_ALLOW_MOUNT_TMPFS 0x0800 232464aad14SJamie Gritton #define PR_ALLOW_MOUNT_FDESCFS 0x1000 233464aad14SJamie Gritton #define PR_ALLOW_ALL 0x1fff 234b38ff370SJamie Gritton 235b38ff370SJamie Gritton /* 236b38ff370SJamie Gritton * OSD methods 237b38ff370SJamie Gritton */ 238b38ff370SJamie Gritton #define PR_METHOD_CREATE 0 239b38ff370SJamie Gritton #define PR_METHOD_GET 1 240b38ff370SJamie Gritton #define PR_METHOD_SET 2 241b38ff370SJamie Gritton #define PR_METHOD_CHECK 3 242b38ff370SJamie Gritton #define PR_METHOD_ATTACH 4 24349939083SJamie Gritton #define PR_MAXMETHOD 5 244b38ff370SJamie Gritton 245b38ff370SJamie Gritton /* 2460304c731SJamie Gritton * Lock/unlock a prison. 2470304c731SJamie Gritton * XXX These exist not so much for general convenience, but to be useable in 2480304c731SJamie Gritton * the FOREACH_PRISON_DESCENDANT_LOCKED macro which can't handle them in 2490304c731SJamie Gritton * non-function form as currently defined. 2505bdee2c5SRobert Watson */ 2510304c731SJamie Gritton static __inline void 2520304c731SJamie Gritton prison_lock(struct prison *pr) 2530304c731SJamie Gritton { 2540304c731SJamie Gritton 2550304c731SJamie Gritton mtx_lock(&pr->pr_mtx); 2560304c731SJamie Gritton } 2570304c731SJamie Gritton 2580304c731SJamie Gritton static __inline void 2590304c731SJamie Gritton prison_unlock(struct prison *pr) 2600304c731SJamie Gritton { 2610304c731SJamie Gritton 2620304c731SJamie Gritton mtx_unlock(&pr->pr_mtx); 2630304c731SJamie Gritton } 2640304c731SJamie Gritton 2650304c731SJamie Gritton /* Traverse a prison's immediate children. */ 2660304c731SJamie Gritton #define FOREACH_PRISON_CHILD(ppr, cpr) \ 2670304c731SJamie Gritton LIST_FOREACH(cpr, &(ppr)->pr_children, pr_sibling) 2680304c731SJamie Gritton 2690304c731SJamie Gritton /* 2700304c731SJamie Gritton * Preorder traversal of all of a prison's descendants. 2710304c731SJamie Gritton * This ugly loop allows the macro to be followed by a single block 2720304c731SJamie Gritton * as expected in a looping primitive. 2730304c731SJamie Gritton */ 2740304c731SJamie Gritton #define FOREACH_PRISON_DESCENDANT(ppr, cpr, descend) \ 2750304c731SJamie Gritton for ((cpr) = (ppr), (descend) = 1; \ 2760304c731SJamie Gritton ((cpr) = (((descend) && !LIST_EMPTY(&(cpr)->pr_children)) \ 2770304c731SJamie Gritton ? LIST_FIRST(&(cpr)->pr_children) \ 2780304c731SJamie Gritton : ((cpr) == (ppr) \ 2790304c731SJamie Gritton ? NULL \ 2800304c731SJamie Gritton : (((descend) = LIST_NEXT(cpr, pr_sibling) != NULL) \ 2810304c731SJamie Gritton ? LIST_NEXT(cpr, pr_sibling) \ 2820304c731SJamie Gritton : (cpr)->pr_parent))));) \ 2830304c731SJamie Gritton if (!(descend)) \ 2840304c731SJamie Gritton ; \ 2850304c731SJamie Gritton else 2860304c731SJamie Gritton 2870304c731SJamie Gritton /* 2880304c731SJamie Gritton * As above, but lock descendants on the way down and unlock on the way up. 2890304c731SJamie Gritton */ 2900304c731SJamie Gritton #define FOREACH_PRISON_DESCENDANT_LOCKED(ppr, cpr, descend) \ 2910304c731SJamie Gritton for ((cpr) = (ppr), (descend) = 1; \ 2920304c731SJamie Gritton ((cpr) = (((descend) && !LIST_EMPTY(&(cpr)->pr_children)) \ 2930304c731SJamie Gritton ? LIST_FIRST(&(cpr)->pr_children) \ 2940304c731SJamie Gritton : ((cpr) == (ppr) \ 2950304c731SJamie Gritton ? NULL \ 2960304c731SJamie Gritton : ((prison_unlock(cpr), \ 2970304c731SJamie Gritton (descend) = LIST_NEXT(cpr, pr_sibling) != NULL) \ 2980304c731SJamie Gritton ? LIST_NEXT(cpr, pr_sibling) \ 2990304c731SJamie Gritton : (cpr)->pr_parent))));) \ 3000304c731SJamie Gritton if ((descend) ? (prison_lock(cpr), 0) : 1) \ 3010304c731SJamie Gritton ; \ 3020304c731SJamie Gritton else 3030304c731SJamie Gritton 3040304c731SJamie Gritton /* 305b97457e2SJamie Gritton * As above, but also keep track of the level descended to. 306b97457e2SJamie Gritton */ 307b97457e2SJamie Gritton #define FOREACH_PRISON_DESCENDANT_LOCKED_LEVEL(ppr, cpr, descend, level)\ 308b97457e2SJamie Gritton for ((cpr) = (ppr), (descend) = 1, (level) = 0; \ 309b97457e2SJamie Gritton ((cpr) = (((descend) && !LIST_EMPTY(&(cpr)->pr_children)) \ 310b97457e2SJamie Gritton ? (level++, LIST_FIRST(&(cpr)->pr_children)) \ 311b97457e2SJamie Gritton : ((cpr) == (ppr) \ 312b97457e2SJamie Gritton ? NULL \ 313b97457e2SJamie Gritton : ((prison_unlock(cpr), \ 314b97457e2SJamie Gritton (descend) = LIST_NEXT(cpr, pr_sibling) != NULL) \ 315b97457e2SJamie Gritton ? LIST_NEXT(cpr, pr_sibling) \ 316b97457e2SJamie Gritton : (level--, (cpr)->pr_parent)))));) \ 317b97457e2SJamie Gritton if ((descend) ? (prison_lock(cpr), 0) : 1) \ 318b97457e2SJamie Gritton ; \ 319b97457e2SJamie Gritton else 320b97457e2SJamie Gritton 321b97457e2SJamie Gritton /* 3220304c731SJamie Gritton * Attributes of the physical system, and the root of the jail tree. 3230304c731SJamie Gritton */ 3240304c731SJamie Gritton extern struct prison prison0; 3255bdee2c5SRobert Watson 326b38ff370SJamie Gritton TAILQ_HEAD(prisonlist, prison); 327fd7a8150SMike Barcroft extern struct prisonlist allprison; 328dc68a633SPawel Jakub Dawidek extern struct sx allprison_lock; 329fd7a8150SMike Barcroft 33091421ba2SRobert Watson /* 331b38ff370SJamie Gritton * Sysctls to describe jail parameters. 332b38ff370SJamie Gritton */ 333b38ff370SJamie Gritton SYSCTL_DECL(_security_jail_param); 334b38ff370SJamie Gritton 335b38ff370SJamie Gritton #define SYSCTL_JAIL_PARAM(module, param, type, fmt, descr) \ 336b38ff370SJamie Gritton SYSCTL_PROC(_security_jail_param ## module, OID_AUTO, param, \ 337b38ff370SJamie Gritton (type) | CTLFLAG_MPSAFE, NULL, 0, sysctl_jail_param, fmt, descr) 338b38ff370SJamie Gritton #define SYSCTL_JAIL_PARAM_STRING(module, param, access, len, descr) \ 339b38ff370SJamie Gritton SYSCTL_PROC(_security_jail_param ## module, OID_AUTO, param, \ 340b38ff370SJamie Gritton CTLTYPE_STRING | CTLFLAG_MPSAFE | (access), NULL, len, \ 341b38ff370SJamie Gritton sysctl_jail_param, "A", descr) 342b38ff370SJamie Gritton #define SYSCTL_JAIL_PARAM_STRUCT(module, param, access, len, fmt, descr)\ 343b38ff370SJamie Gritton SYSCTL_PROC(_security_jail_param ## module, OID_AUTO, param, \ 344b38ff370SJamie Gritton CTLTYPE_STRUCT | CTLFLAG_MPSAFE | (access), NULL, len, \ 345b38ff370SJamie Gritton sysctl_jail_param, fmt, descr) 346b38ff370SJamie Gritton #define SYSCTL_JAIL_PARAM_NODE(module, descr) \ 3477cbf7213SJamie Gritton SYSCTL_NODE(_security_jail_param, OID_AUTO, module, 0, 0, descr) 348bf3db8aaSMartin Matuska #define SYSCTL_JAIL_PARAM_SUBNODE(parent, module, descr) \ 349bf3db8aaSMartin Matuska SYSCTL_NODE(_security_jail_param_##parent, OID_AUTO, module, 0, 0, descr) 3507cbf7213SJamie Gritton #define SYSCTL_JAIL_PARAM_SYS_NODE(module, access, descr) \ 3517cbf7213SJamie Gritton SYSCTL_JAIL_PARAM_NODE(module, descr); \ 3527cbf7213SJamie Gritton SYSCTL_JAIL_PARAM(_##module, , CTLTYPE_INT | (access), "E,jailsys", \ 3537cbf7213SJamie Gritton descr) 354b38ff370SJamie Gritton 355b38ff370SJamie Gritton /* 35691421ba2SRobert Watson * Kernel support functions for jail(). 35791421ba2SRobert Watson */ 35891421ba2SRobert Watson struct ucred; 359f08df373SRobert Watson struct mount; 36091421ba2SRobert Watson struct sockaddr; 361820a0de9SPawel Jakub Dawidek struct statfs; 362789f12feSAlfred Perlstein int jailed(struct ucred *cred); 363de0bd6f7SBjoern A. Zeeb int jailed_without_vnet(struct ucred *); 3647455b100SJamie Gritton void getcredhostname(struct ucred *, char *, size_t); 3657455b100SJamie Gritton void getcreddomainname(struct ucred *, char *, size_t); 3667455b100SJamie Gritton void getcredhostuuid(struct ucred *, char *, size_t); 3677455b100SJamie Gritton void getcredhostid(struct ucred *, unsigned long *); 368b96bd95bSIan Lepore void prison0_init(void); 3690304c731SJamie Gritton int prison_allow(struct ucred *, unsigned); 370789f12feSAlfred Perlstein int prison_check(struct ucred *cred1, struct ucred *cred2); 371eb79e1c7SBjoern A. Zeeb int prison_owns_vnet(struct ucred *); 372820a0de9SPawel Jakub Dawidek int prison_canseemount(struct ucred *cred, struct mount *mp); 373820a0de9SPawel Jakub Dawidek void prison_enforce_statfs(struct ucred *cred, struct mount *mp, 374820a0de9SPawel Jakub Dawidek struct statfs *sp); 37554b369c1SPawel Jakub Dawidek struct prison *prison_find(int prid); 3760304c731SJamie Gritton struct prison *prison_find_child(struct prison *, int); 3770304c731SJamie Gritton struct prison *prison_find_name(struct prison *, const char *); 3780304c731SJamie Gritton int prison_flag(struct ucred *, unsigned); 379789f12feSAlfred Perlstein void prison_free(struct prison *pr); 3801ba4a712SPawel Jakub Dawidek void prison_free_locked(struct prison *pr); 381789f12feSAlfred Perlstein void prison_hold(struct prison *pr); 3821ba4a712SPawel Jakub Dawidek void prison_hold_locked(struct prison *pr); 383413628a7SBjoern A. Zeeb void prison_proc_hold(struct prison *); 384413628a7SBjoern A. Zeeb void prison_proc_free(struct prison *); 3850304c731SJamie Gritton int prison_ischild(struct prison *, struct prison *); 3860304c731SJamie Gritton int prison_equal_ip4(struct prison *, struct prison *); 3871cecba0fSBjoern A. Zeeb int prison_get_ip4(struct ucred *cred, struct in_addr *ia); 388413628a7SBjoern A. Zeeb int prison_local_ip4(struct ucred *cred, struct in_addr *ia); 389413628a7SBjoern A. Zeeb int prison_remote_ip4(struct ucred *cred, struct in_addr *ia); 3900d168b8dSGleb Smirnoff int prison_check_ip4(const struct ucred *, const struct in_addr *); 391592bcae8SBjoern A. Zeeb int prison_saddrsel_ip4(struct ucred *, struct in_addr *); 392413628a7SBjoern A. Zeeb #ifdef INET6 3930304c731SJamie Gritton int prison_equal_ip6(struct prison *, struct prison *); 3941cecba0fSBjoern A. Zeeb int prison_get_ip6(struct ucred *, struct in6_addr *); 395413628a7SBjoern A. Zeeb int prison_local_ip6(struct ucred *, struct in6_addr *, int); 396413628a7SBjoern A. Zeeb int prison_remote_ip6(struct ucred *, struct in6_addr *); 397413628a7SBjoern A. Zeeb int prison_check_ip6(struct ucred *, struct in6_addr *); 398592bcae8SBjoern A. Zeeb int prison_saddrsel_ip6(struct ucred *, struct in6_addr *); 399413628a7SBjoern A. Zeeb #endif 400ca04ba64SJamie Gritton int prison_check_af(struct ucred *cred, int af); 401789f12feSAlfred Perlstein int prison_if(struct ucred *cred, struct sockaddr *sa); 4020304c731SJamie Gritton char *prison_name(struct prison *, struct prison *); 403800c9408SRobert Watson int prison_priv_check(struct ucred *cred, int priv); 404e4cd31ddSJeff Roberson int sysctl_jail_param(SYSCTL_HANDLER_ARGS); 405097055e2SEdward Tomasz Napierala void prison_racct_foreach(void (*callback)(struct racct *racct, 406097055e2SEdward Tomasz Napierala void *arg2, void *arg3), void *arg2, void *arg3); 407a7ad07bfSEdward Tomasz Napierala struct prison_racct *prison_racct_find(const char *name); 408a7ad07bfSEdward Tomasz Napierala void prison_racct_hold(struct prison_racct *prr); 409a7ad07bfSEdward Tomasz Napierala void prison_racct_free(struct prison_racct *prr); 41091421ba2SRobert Watson 411e69f1fa2SPawel Jakub Dawidek #endif /* _KERNEL */ 41275c13541SPoul-Henning Kamp #endif /* !_SYS_JAIL_H_ */ 413