| 1 | /*- |
| 2 | * SPDX-License-Identifier: BSD-2-Clause |
| 3 | * |
| 4 | * Copyright (c) 1999 Poul-Henning Kamp. |
| 5 | * Copyright (c) 2009 James Gritton. |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef _SYS_JAIL_H_ |
| 31 | #define _SYS_JAIL_H_ |
| 32 | |
| 33 | #ifdef _KERNEL |
| 34 | struct jail_v0 { |
| 35 | 	u_int32_t	version; |
| 36 | 	char		*path; |
| 37 | 	char		*hostname; |
| 38 | 	u_int32_t	ip_number; |
| 39 | }; |
| 40 | #endif |
| 41 | |
| 42 | struct jail { |
| 43 | 	uint32_t	version; |
| 44 | 	char		*path; |
| 45 | 	char		*hostname; |
| 46 | 	char		*jailname; |
| 47 | 	uint32_t	ip4s; |
| 48 | 	uint32_t	ip6s; |
| 49 | 	struct in_addr	*ip4; |
| 50 | 	struct in6_addr	*ip6; |
| 51 | }; |
| 52 | #define	JAIL_API_VERSION	2 |
| 53 | |
| 54 | /* |
| 55 | * For all xprison structs, always keep the pr_version an int and |
| 56 | * the first variable so userspace can easily distinguish them. |
| 57 | */ |
| 58 | #ifndef _KERNEL |
| 59 | struct xprison_v1 { |
| 60 | 	int		 pr_version; |
| 61 | 	int		 pr_id; |
| 62 | 	char		 pr_path[MAXPATHLEN]; |
| 63 | 	char		 pr_host[MAXHOSTNAMELEN]; |
| 64 | 	u_int32_t	 pr_ip; |
| 65 | }; |
| 66 | #endif |
| 67 | |
| 68 | struct xprison { |
| 69 | 	int		 pr_version; |
| 70 | 	int		 pr_id; |
| 71 | 	int		 pr_state; |
| 72 | 	cpusetid_t	 pr_cpusetid; |
| 73 | 	char		 pr_path[MAXPATHLEN]; |
| 74 | 	char		 pr_host[MAXHOSTNAMELEN]; |
| 75 | 	char		 pr_name[MAXHOSTNAMELEN]; |
| 76 | 	uint32_t	 pr_ip4s; |
| 77 | 	uint32_t	 pr_ip6s; |
| 78 | #if 0 |
| 79 | 	/* |
| 80 | 	 * sizeof(xprison) will be malloced + size needed for all |
| 81 | 	 * IPv4 and IPv6 addesses. Offsets are based numbers of addresses. |
| 82 | 	 */ |
| 83 | 	struct in_addr	 pr_ip4[]; |
| 84 | 	struct in6_addr	 pr_ip6[]; |
| 85 | #endif |
| 86 | }; |
| 87 | #define	XPRISON_VERSION		3 |
| 88 | |
| 89 | enum prison_state { |
| 90 | PRISON_STATE_INVALID = 0,	/* New prison, not ready to be seen */ |
| 91 | PRISON_STATE_ALIVE,		/* Current prison, visible to all */ |
| 92 | PRISON_STATE_DYING		/* Removed but holding resources, */ |
| 93 | };				/* optionally visible. */ |
| 94 | |
| 95 | /* |
| 96 | * Flags for jail_set and jail_get. |
| 97 | */ |
| 98 | #define	JAIL_CREATE	0x01	/* Create jail if it doesn't exist */ |
| 99 | #define	JAIL_UPDATE	0x02	/* Update parameters of existing jail */ |
| 100 | #define	JAIL_ATTACH	0x04	/* Attach to jail upon creation */ |
| 101 | #define	JAIL_DYING	0x08	/* Allow getting a dying jail */ |
| 102 | #define JAIL_USE_DESC	0x10	/* Get/set jail in descriptor */ |
| 103 | #define JAIL_AT_DESC	0x20	/* Find/add jail under descriptor */ |
| 104 | #define	JAIL_GET_DESC	0x40	/* Return a new jail descriptor */ |
| 105 | #define	JAIL_OWN_DESC	0x80	/* Return a new owning jail descriptor */ |
| 106 | #define	JAIL_SET_MASK	0xff	/* JAIL_DYING is deprecated/ignored here */ |
| 107 | #define	JAIL_GET_MASK	0xf8 |
| 108 | |
| 109 | #define	JAIL_SYS_DISABLE	0 |
| 110 | #define	JAIL_SYS_NEW		1 |
| 111 | #define	JAIL_SYS_INHERIT	2 |
| 112 | |
| 113 | #ifndef _KERNEL |
| 114 | |
| 115 | struct iovec; |
| 116 | |
| 117 | __BEGIN_DECLS |
| 118 | int jail(struct jail *); |
| 119 | int jail_set(struct iovec *, unsigned int, int); |
| 120 | int jail_get(struct iovec *, unsigned int, int); |
| 121 | int jail_attach(int); |
| 122 | int jail_attach_jd(int); |
| 123 | int jail_remove(int); |
| 124 | int jail_remove_jd(int); |
| 125 | __END_DECLS |
| 126 | |
| 127 | #else /* _KERNEL */ |
| 128 | |
| 129 | #include <sys/queue.h> |
| 130 | #include <sys/sysctl.h> |
| 131 | #include <sys/lock.h> |
| 132 | #include <sys/mutex.h> |
| 133 | #include <sys/_task.h> |
| 134 | |
| 135 | #define JAIL_MAX	999999 |
| 136 | |
| 137 | #ifdef MALLOC_DECLARE |
| 138 | MALLOC_DECLARE(M_PRISON); |
| 139 | #endif |
| 140 | #endif /* _KERNEL */ |
| 141 | |
| 142 | #if defined(_KERNEL) || defined(_WANT_PRISON) |
| 143 | |
| 144 | #include <sys/osd.h> |
| 145 | |
| 146 | #define	HOSTUUIDLEN	64 |
| 147 | #define	DEFAULT_HOSTUUID	"00000000-0000-0000-0000-000000000000" |
| 148 | #define	OSRELEASELEN	32 |
| 149 | |
| 150 | #define	JAIL_META_PRIVATE	"meta" |
| 151 | #define	JAIL_META_SHARED	"env" |
| 152 | |
| 153 | struct jaildesc; |
| 154 | struct knlist; |
| 155 | struct racct; |
| 156 | struct prison_racct; |
| 157 | |
| 158 | typedef enum { |
| 159 | 	PR_INET		= 0, |
| 160 | 	PR_INET6	= 1, |
| 161 | 	PR_FAMILY_MAX	= 2, |
| 162 | } pr_family_t; |
| 163 | |
| 164 | /* |
| 165 | * This structure describes a prison. It is pointed to by all struct |
| 166 | * ucreds's of the inmates. pr_ref keeps track of them and is used to |
| 167 | * delete the structure when the last inmate is dead. |
| 168 | * |
| 169 | * Lock key: |
| 170 | * (a) allprison_lock |
| 171 | * (A) allproc_lock |
| 172 | * (c) set only during creation before the structure is shared, no mutex |
| 173 | * required to read |
| 174 | * (m) locked by pr_mtx |
| 175 | * (p) locked by pr_mtx, and also at least shared allprison_lock required |
| 176 | * to update |
| 177 | * (q) locked by both pr_mtx and allprison_lock |
| 178 | * (r) atomic via refcount(9), pr_mtx and allprison_lock required to |
| 179 | * decrement to zero |
| 180 | * (n) read access granted with the network epoch |
| 181 | */ |
| 182 | struct prison { |
| 183 | 	TAILQ_ENTRY(prison) pr_list;			/* (a) all prisons */ |
| 184 | 	int		 pr_id;				/* (c) prison id */ |
| 185 | 	volatile u_int	 pr_ref;			/* (r) refcount */ |
| 186 | 	volatile u_int	 pr_uref;			/* (r) user (alive) refcount */ |
| 187 | 	unsigned	 pr_flags;			/* (p) PR_* flags */ |
| 188 | 	LIST_HEAD(, prison) pr_children;		/* (a) list of child jails */ |
| 189 | 	LIST_HEAD(, proc) pr_proclist;			/* (A) list of jailed processes */ |
| 190 | 	LIST_ENTRY(prison) pr_sibling;			/* (a) next in parent's list */ |
| 191 | 	struct prison	*pr_parent;			/* (c) containing jail */ |
| 192 | 	struct mtx	 pr_mtx; |
| 193 | 	struct task	 pr_task;			/* (c) destroy task */ |
| 194 | 	struct osd	 pr_osd;			/* (p) additional data */ |
| 195 | 	struct cpuset	*pr_cpuset;			/* (p) cpuset */ |
| 196 | 	struct vnet	*pr_vnet;			/* (c) network stack */ |
| 197 | 	struct vnode	*pr_root;			/* (c) vnode to rdir */ |
| 198 | 	struct prison_ip *pr_addrs[PR_FAMILY_MAX];	/* (p,n) IPs of jail */ |
| 199 | 	struct prison_racct *pr_prison_racct;		/* (c) racct jail proxy */ |
| 200 | 	struct knlist	*pr_klist;			/* (m) attached knotes */ |
| 201 | 	LIST_HEAD(, jaildesc) pr_descs;			/* (a) attached descriptors */ |
| 202 | 	void		*pr_sparep; |
| 203 | 	int		 pr_childcount;			/* (a) number of child jails */ |
| 204 | 	int		 pr_childmax;			/* (p) maximum child jails */ |
| 205 | 	unsigned	 pr_allow;			/* (p) PR_ALLOW_* flags */ |
| 206 | 	int		 pr_securelevel;		/* (p) securelevel */ |
| 207 | 	int		 pr_enforce_statfs;		/* (p) statfs permission */ |
| 208 | 	int		 pr_devfs_rsnum;		/* (p) devfs ruleset */ |
| 209 | 	enum prison_state pr_state;			/* (q) state in life cycle */ |
| 210 | 	volatile int	 pr_exportcnt;			/* (r) count of mount exports */ |
| 211 | 	int		 pr_spare; |
| 212 | 	int		 pr_osreldate;			/* (c) kern.osreldate value */ |
| 213 | 	unsigned long	 pr_hostid;			/* (p) jail hostid */ |
| 214 | 	char		 pr_name[MAXHOSTNAMELEN];	/* (p) admin jail name */ |
| 215 | 	char		 pr_path[MAXPATHLEN];		/* (c) chroot path */ |
| 216 | 	char		 pr_hostname[MAXHOSTNAMELEN];	/* (p) jail hostname */ |
| 217 | 	char		 pr_domainname[MAXHOSTNAMELEN];	/* (p) jail domainname */ |
| 218 | 	char		 pr_hostuuid[HOSTUUIDLEN];	/* (p) jail hostuuid */ |
| 219 | 	char		 pr_osrelease[OSRELEASELEN];	/* (c) kern.osrelease value */ |
| 220 | }; |
| 221 | |
| 222 | struct prison_racct { |
| 223 | 	LIST_ENTRY(prison_racct) prr_next; |
| 224 | 	char		prr_name[MAXHOSTNAMELEN]; |
| 225 | 	u_int		prr_refcount; |
| 226 | 	struct racct	*prr_racct; |
| 227 | }; |
| 228 | #endif /* _KERNEL || _WANT_PRISON */ |
| 229 | |
| 230 | #ifdef _KERNEL |
| 231 | /* Flag bits set via options */ |
| 232 | #define	PR_PERSIST	0x00000001	/* Can exist without processes */ |
| 233 | #define	PR_HOST		0x00000002	/* Virtualize hostname et al */ |
| 234 | #define	PR_IP4_USER	0x00000004	/* Restrict IPv4 addresses */ |
| 235 | #define	PR_IP6_USER	0x00000008	/* Restrict IPv6 addresses */ |
| 236 | #define	PR_VNET		0x00000010	/* Virtual network stack */ |
| 237 | #define	PR_IP4_SADDRSEL	0x00000080	/* Do IPv4 src addr sel. or use the */ |
| 238 | 					/* primary jail address. */ |
| 239 | #define	PR_IP6_SADDRSEL	0x00000100	/* Do IPv6 src addr sel. or use the */ |
| 240 | 					/* primary jail address. */ |
| 241 | |
| 242 | /* Internal flag bits */ |
| 243 | #define	PR_REMOVE	0x01000000	/* In process of being removed */ |
| 244 | #define	PR_IP4		0x02000000	/* IPv4 restricted or disabled */ |
| 245 | 					/* by this jail or an ancestor */ |
| 246 | #define	PR_IP6		0x04000000	/* IPv6 restricted or disabled */ |
| 247 | 					/* by this jail or an ancestor */ |
| 248 | #define PR_COMPLETE_PROC 0x08000000	/* prison_complete called from */ |
| 249 | 					/* prison_proc_free, releases uref */ |
| 250 | |
| 251 | /* |
| 252 | * Flags for pr_allow |
| 253 | * Bits not noted here may be used for dynamic allow.mount.xxxfs. |
| 254 | */ |
| 255 | #define	PR_ALLOW_SET_HOSTNAME		0x00000001 |
| 256 | #define	PR_ALLOW_SYSVIPC		0x00000002 |
| 257 | #define	PR_ALLOW_RAW_SOCKETS		0x00000004 |
| 258 | #define	PR_ALLOW_CHFLAGS		0x00000008 |
| 259 | #define	PR_ALLOW_MOUNT			0x00000010 |
| 260 | #define	PR_ALLOW_QUOTAS			0x00000020 |
| 261 | #define	PR_ALLOW_SOCKET_AF		0x00000040 |
| 262 | #define	PR_ALLOW_MLOCK			0x00000080 |
| 263 | #define	PR_ALLOW_READ_MSGBUF		0x00000100 |
| 264 | #define	PR_ALLOW_UNPRIV_DEBUG		0x00000200 |
| 265 | #define	PR_ALLOW_SUSER			0x00000400 |
| 266 | #define	PR_ALLOW_RESERVED_PORTS		0x00008000 |
| 267 | #define	PR_ALLOW_KMEM_ACCESS		0x00010000	/* reserved, not used yet */ |
| 268 | #define	PR_ALLOW_NFSD			0x00020000 |
| 269 | #define	PR_ALLOW_EXTATTR		0x00040000 |
| 270 | #define	PR_ALLOW_ADJTIME		0x00080000 |
| 271 | #define	PR_ALLOW_SETTIME		0x00100000 |
| 272 | #define	PR_ALLOW_ROUTING		0x00200000 |
| 273 | #define	PR_ALLOW_UNPRIV_PARENT_TAMPER	0x00400000 |
| 274 | #define	PR_ALLOW_SETAUDIT		0x00800000 |
| 275 | |
| 276 | /* |
| 277 | * PR_ALLOW_PRISON0 are the allow flags that we apply by default to prison0, |
| 278 | * while PR_ALLOW_ALL_STATIC are all of the allow bits that we have allocated at |
| 279 | * build time. PR_ALLOW_ALL_STATIC should contain any bit above that we expect |
| 280 | * to be used on the system, while PR_ALLOW_PRISON0 will be some subset of that. |
| 281 | */ |
| 282 | #define	PR_ALLOW_ALL_STATIC		0x00ff87ff |
| 283 | #define	PR_ALLOW_PRISON0		\ |
| 284 | (PR_ALLOW_ALL_STATIC & ~(PR_ALLOW_UNPRIV_PARENT_TAMPER)) |
| 285 | |
| 286 | /* |
| 287 | * PR_ALLOW_DIFFERENCES determines which flags are able to be |
| 288 | * different between the parent and child jail upon creation. |
| 289 | */ |
| 290 | #define	PR_ALLOW_DIFFERENCES		\ |
| 291 | (PR_ALLOW_UNPRIV_DEBUG | PR_ALLOW_UNPRIV_PARENT_TAMPER) |
| 292 | |
| 293 | /* |
| 294 | * OSD methods |
| 295 | */ |
| 296 | #define	PR_METHOD_CREATE	0 |
| 297 | #define	PR_METHOD_GET		1 |
| 298 | #define	PR_METHOD_SET		2 |
| 299 | #define	PR_METHOD_CHECK		3 |
| 300 | #define	PR_METHOD_ATTACH	4 |
| 301 | #define	PR_METHOD_REMOVE	5 |
| 302 | #define	PR_MAXMETHOD		6 |
| 303 | |
| 304 | /* |
| 305 | * Lock/unlock a prison. |
| 306 | * XXX These exist not so much for general convenience, but to be useable in |
| 307 | * the FOREACH_PRISON_DESCENDANT_LOCKED macro which can't handle them in |
| 308 | * non-function form as currently defined. |
| 309 | */ |
| 310 | static __inline void |
| 311 | prison_lock(struct prison *pr) |
| 312 | { |
| 313 | |
| 314 | 	mtx_lock(&pr->pr_mtx); |
| 315 | } |
| 316 | |
| 317 | static __inline void |
| 318 | prison_unlock(struct prison *pr) |
| 319 | { |
| 320 | |
| 321 | 	mtx_unlock(&pr->pr_mtx); |
| 322 | } |
| 323 | |
| 324 | /* Traverse a prison's immediate children. */ |
| 325 | #define	FOREACH_PRISON_CHILD(ppr, cpr)					\ |
| 326 | 	LIST_FOREACH(cpr, &(ppr)->pr_children, pr_sibling) |
| 327 | |
| 328 | /* |
| 329 | * Preorder traversal of all of a prison's descendants. |
| 330 | * This ugly loop allows the macro to be followed by a single block |
| 331 | * as expected in a looping primitive. |
| 332 | */ |
| 333 | #define	FOREACH_PRISON_DESCENDANT(ppr, cpr, descend)			\ |
| 334 | 	for ((cpr) = (ppr), (descend) = 1;				\ |
| 335 | 	 ((cpr) = (((descend) && !LIST_EMPTY(&(cpr)->pr_children))	\ |
| 336 | 	 ? LIST_FIRST(&(cpr)->pr_children)				\ |
| 337 | 	 : ((cpr) == (ppr)						\ |
| 338 | 		 ? NULL							\ |
| 339 | 		 : (((descend) = LIST_NEXT(cpr, pr_sibling) != NULL)	\ |
| 340 | 		 ? LIST_NEXT(cpr, pr_sibling)			\ |
| 341 | 		 : (cpr)->pr_parent))));)				\ |
| 342 | 		if (!(descend))						\ |
| 343 | 			;						\ |
| 344 | 		else |
| 345 | |
| 346 | /* |
| 347 | * As above, but lock descendants on the way down and unlock on the way up. |
| 348 | */ |
| 349 | #define	FOREACH_PRISON_DESCENDANT_LOCKED(ppr, cpr, descend)		\ |
| 350 | 	for ((cpr) = (ppr), (descend) = 1;				\ |
| 351 | 	 ((cpr) = (((descend) && !LIST_EMPTY(&(cpr)->pr_children))	\ |
| 352 | 	 ? LIST_FIRST(&(cpr)->pr_children)				\ |
| 353 | 	 : ((cpr) == (ppr)						\ |
| 354 | 		 ? NULL							\ |
| 355 | 		 : ((prison_unlock(cpr),				\ |
| 356 | 		 (descend) = LIST_NEXT(cpr, pr_sibling) != NULL)	\ |
| 357 | 		 ? LIST_NEXT(cpr, pr_sibling)			\ |
| 358 | 		 : (cpr)->pr_parent))));)				\ |
| 359 | 		if ((descend) ? (prison_lock(cpr), 0) : 1)		\ |
| 360 | 			;						\ |
| 361 | 		else |
| 362 | |
| 363 | /* |
| 364 | * As above, but also keep track of the level descended to. |
| 365 | */ |
| 366 | #define	FOREACH_PRISON_DESCENDANT_LOCKED_LEVEL(ppr, cpr, descend, level)\ |
| 367 | 	for ((cpr) = (ppr), (descend) = 1, (level) = 0;			\ |
| 368 | 	 ((cpr) = (((descend) && !LIST_EMPTY(&(cpr)->pr_children))	\ |
| 369 | 	 ? (level++, LIST_FIRST(&(cpr)->pr_children))		\ |
| 370 | 	 : ((cpr) == (ppr)						\ |
| 371 | 		 ? NULL							\ |
| 372 | 		 : ((prison_unlock(cpr),				\ |
| 373 | 		 (descend) = LIST_NEXT(cpr, pr_sibling) != NULL)	\ |
| 374 | 		 ? LIST_NEXT(cpr, pr_sibling)			\ |
| 375 | 		 : (level--, (cpr)->pr_parent)))));)			\ |
| 376 | 		if ((descend) ? (prison_lock(cpr), 0) : 1)		\ |
| 377 | 			;						\ |
| 378 | 		else |
| 379 | |
| 380 | /* |
| 381 | * Traverse a prison's descendants, visiting both preorder and postorder. |
| 382 | */ |
| 383 | #define FOREACH_PRISON_DESCENDANT_PRE_POST(ppr, cpr, descend)		\ |
| 384 | 	for ((cpr) = (ppr), (descend) = 1;				\ |
| 385 | 	 ((cpr) = (descend)						\ |
| 386 | 	 ? ((descend) = !LIST_EMPTY(&(cpr)->pr_children))		\ |
| 387 | 		? LIST_FIRST(&(cpr)->pr_children)			\ |
| 388 | 		: (cpr)							\ |
| 389 | 	 : ((descend) = LIST_NEXT(cpr, pr_sibling) != NULL)	\ |
| 390 | 		? LIST_NEXT(cpr, pr_sibling)				\ |
| 391 | 		: cpr->pr_parent) != (ppr);) |
| 392 | |
| 393 | /* |
| 394 | * Attributes of the physical system, and the root of the jail tree. |
| 395 | */ |
| 396 | extern struct	prison prison0; |
| 397 | |
| 398 | TAILQ_HEAD(prisonlist, prison); |
| 399 | extern struct	prisonlist allprison; |
| 400 | extern struct	sx allprison_lock; |
| 401 | |
| 402 | /* |
| 403 | * Sysctls to describe jail parameters. |
| 404 | */ |
| 405 | SYSCTL_DECL(_security_jail); |
| 406 | SYSCTL_DECL(_security_jail_param); |
| 407 | |
| 408 | #define SYSCTL_JAIL_PARAM_DECL(name)					\ |
| 409 | 	SYSCTL_DECL(_security_jail_param_##name) |
| 410 | #define	SYSCTL_JAIL_PARAM(module, param, type, fmt, descr)		\ |
| 411 | 	SYSCTL_PROC(_security_jail_param ## module, OID_AUTO, param,	\ |
| 412 | 	 (type) | CTLFLAG_MPSAFE, NULL, 0, sysctl_jail_param, fmt, descr) |
| 413 | #define	SYSCTL_JAIL_PARAM_STRING(module, param, access, len, descr)	\ |
| 414 | 	SYSCTL_PROC(_security_jail_param ## module, OID_AUTO, param,	\ |
| 415 | 	 CTLTYPE_STRING | CTLFLAG_MPSAFE | (access), NULL, len,	\ |
| 416 | 	 sysctl_jail_param, "A", descr) |
| 417 | #define	SYSCTL_JAIL_PARAM_STRUCT(module, param, access, len, fmt, descr) \ |
| 418 | 	SYSCTL_PROC(_security_jail_param ## module, OID_AUTO, param,	\ |
| 419 | 	 CTLTYPE_STRUCT | CTLFLAG_MPSAFE | (access), NULL, len,	\ |
| 420 | 	 sysctl_jail_param, fmt, descr) |
| 421 | #define	SYSCTL_JAIL_PARAM_NODE(module, descr)				\ |
| 422 | 	SYSCTL_NODE(_security_jail_param, OID_AUTO, module, CTLFLAG_MPSAFE, \ |
| 423 | 	 0, descr) |
| 424 | #define	SYSCTL_JAIL_PARAM_SUBNODE(parent, module, descr)		\ |
| 425 | 	SYSCTL_NODE(_security_jail_param_##parent, OID_AUTO, module,	\ |
| 426 | 	 CTLFLAG_MPSAFE, 0, descr) |
| 427 | #define	SYSCTL_JAIL_PARAM_SYS_NODE(module, access, descr)		\ |
| 428 | 	SYSCTL_JAIL_PARAM_NODE(module, descr);				\ |
| 429 | 	SYSCTL_JAIL_PARAM(_##module, , CTLTYPE_INT | (access), "E,jailsys", \ |
| 430 | 	 descr) |
| 431 | #define	SYSCTL_JAIL_PARAM_SYS_SUBNODE(parent, module, access, descr)	\ |
| 432 | 	SYSCTL_JAIL_PARAM_SUBNODE(parent, module, descr);		\ |
| 433 | 	SYSCTL_JAIL_PARAM(_##parent##_##module, , CTLTYPE_INT | (access), \ |
| 434 | 	 "E,jailsys", descr) |
| 435 | |
| 436 | /* |
| 437 | * Kernel support functions for jail(). |
| 438 | */ |
| 439 | struct knote; |
| 440 | struct mount; |
| 441 | struct sockaddr; |
| 442 | struct statfs; |
| 443 | struct ucred; |
| 444 | struct vfsconf; |
| 445 | |
| 446 | /* |
| 447 | * Return 1 if the passed credential is in a jail, otherwise 0. |
| 448 | */ |
| 449 | #define jailed(cred)	(cred->cr_prison != &prison0) |
| 450 | |
| 451 | bool jailed_without_vnet(struct ucred *); |
| 452 | void getcredhostname(struct ucred *, char *, size_t); |
| 453 | void getcreddomainname(struct ucred *, char *, size_t); |
| 454 | void getcredhostuuid(struct ucred *, char *, size_t); |
| 455 | void getcredhostid(struct ucred *, unsigned long *); |
| 456 | void getjailname(struct ucred *cred, char *name, size_t len); |
| 457 | void prison0_init(void); |
| 458 | bool prison_allow(struct ucred *, unsigned); |
| 459 | int prison_check(struct ucred *cred1, struct ucred *cred2); |
| 460 | bool prison_check_nfsd(struct ucred *cred); |
| 461 | bool prison_owns_vnet(struct prison *pr); |
| 462 | int prison_canseemount(struct ucred *cred, struct mount *mp); |
| 463 | void prison_enforce_statfs(struct ucred *cred, struct mount *mp, |
| 464 | struct statfs *sp); |
| 465 | struct prison *prison_find(int prid); |
| 466 | struct prison *prison_find_child(struct prison *, int); |
| 467 | struct prison *prison_find_name(struct prison *, const char *); |
| 468 | bool prison_flag(struct ucred *, unsigned); |
| 469 | void prison_free(struct prison *pr); |
| 470 | void prison_free_locked(struct prison *pr); |
| 471 | void prison_hold(struct prison *pr); |
| 472 | void prison_hold_locked(struct prison *pr); |
| 473 | void prison_proc_hold(struct prison *); |
| 474 | void prison_proc_free(struct prison *); |
| 475 | void prison_proc_link(struct prison *, struct proc *); |
| 476 | void prison_proc_unlink(struct prison *, struct proc *); |
| 477 | void prison_proc_iterate(struct prison *, void (*)(struct proc *, void *), void *); |
| 478 | void prison_remove(struct prison *); |
| 479 | void prison_set_allow(struct ucred *cred, unsigned flag, int enable); |
| 480 | bool prison_ischild(struct prison *, struct prison *); |
| 481 | bool prison_isalive(const struct prison *); |
| 482 | bool prison_isvalid(struct prison *); |
| 483 | #if defined(INET) || defined(INET6) |
| 484 | int prison_ip_check(const struct prison *, const pr_family_t, const void *); |
| 485 | const void *prison_ip_get0(const struct prison *, const pr_family_t); |
| 486 | u_int prison_ip_cnt(const struct prison *, const pr_family_t); |
| 487 | #endif |
| 488 | #ifdef INET |
| 489 | bool prison_equal_ip4(struct prison *, struct prison *); |
| 490 | int prison_get_ip4(struct ucred *cred, struct in_addr *ia); |
| 491 | int prison_local_ip4(struct ucred *cred, struct in_addr *ia); |
| 492 | int prison_remote_ip4(struct ucred *cred, struct in_addr *ia); |
| 493 | int prison_check_ip4(const struct ucred *, const struct in_addr *); |
| 494 | int prison_check_ip4_locked(const struct prison *, const struct in_addr *); |
| 495 | bool prison_saddrsel_ip4(struct ucred *, struct in_addr *); |
| 496 | int prison_qcmp_v4(const void *, const void *); |
| 497 | bool prison_valid_v4(const void *); |
| 498 | #endif |
| 499 | #ifdef INET6 |
| 500 | bool prison_equal_ip6(struct prison *, struct prison *); |
| 501 | int prison_get_ip6(struct ucred *, struct in6_addr *); |
| 502 | int prison_local_ip6(struct ucred *, struct in6_addr *, int); |
| 503 | int prison_remote_ip6(struct ucred *, struct in6_addr *); |
| 504 | int prison_check_ip6(const struct ucred *, const struct in6_addr *); |
| 505 | int prison_check_ip6_locked(const struct prison *, const struct in6_addr *); |
| 506 | bool prison_saddrsel_ip6(struct ucred *, struct in6_addr *); |
| 507 | int prison_qcmp_v6(const void *, const void *); |
| 508 | bool prison_valid_v6(const void *); |
| 509 | #endif |
| 510 | int prison_check_af(struct ucred *cred, int af); |
| 511 | int prison_if(struct ucred *cred, const struct sockaddr *sa); |
| 512 | char *prison_name(struct prison *, struct prison *); |
| 513 | int prison_priv_check(struct ucred *cred, int priv); |
| 514 | int sysctl_jail_param(SYSCTL_HANDLER_ARGS); |
| 515 | unsigned prison_add_allow(const char *prefix, const char *name, |
| 516 | const char *prefix_descr, const char *descr); |
| 517 | void prison_add_vfs(struct vfsconf *vfsp); |
| 518 | void prison_racct_foreach(void (*callback)(struct racct *racct, |
| 519 | void *arg2, void *arg3), void (*pre)(void), void (*post)(void), |
| 520 | void *arg2, void *arg3); |
| 521 | struct prison_racct *prison_racct_find(const char *name); |
| 522 | void prison_racct_hold(struct prison_racct *prr); |
| 523 | void prison_racct_free(struct prison_racct *prr); |
| 524 | |
| 525 | #endif /* _KERNEL */ |
| 526 | #endif /* !_SYS_JAIL_H_ */ |