2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
10 #include <sys/cdefs.h>
11 __FBSDID("$FreeBSD$");
15 #include <sys/param.h>
16 #include <sys/types.h>
17 #include <sys/kernel.h>
18 #include <sys/systm.h>
19 #include <sys/errno.h>
20 #include <sys/sysproto.h>
21 #include <sys/malloc.h>
24 #include <sys/taskqueue.h>
25 #include <sys/fcntl.h>
27 #include <sys/limits.h>
29 #include <sys/mutex.h>
31 #include <sys/namei.h>
32 #include <sys/mount.h>
33 #include <sys/queue.h>
34 #include <sys/socket.h>
35 #include <sys/syscallsubr.h>
36 #include <sys/sysctl.h>
37 #include <sys/vnode.h>
39 #include <netinet/in.h>
41 #include <security/mac/mac_framework.h>
43 MALLOC_DEFINE(M_PRISON, "prison", "Prison structures");
45 SYSCTL_NODE(_security, OID_AUTO, jail, CTLFLAG_RW, 0,
48 int jail_set_hostname_allowed = 1;
49 SYSCTL_INT(_security_jail, OID_AUTO, set_hostname_allowed, CTLFLAG_RW,
50 &jail_set_hostname_allowed, 0,
51 "Processes in jail can set their hostnames");
53 int jail_socket_unixiproute_only = 1;
54 SYSCTL_INT(_security_jail, OID_AUTO, socket_unixiproute_only, CTLFLAG_RW,
55 &jail_socket_unixiproute_only, 0,
56 "Processes in jail are limited to creating UNIX/IPv4/route sockets only");
58 int jail_sysvipc_allowed = 0;
59 SYSCTL_INT(_security_jail, OID_AUTO, sysvipc_allowed, CTLFLAG_RW,
60 &jail_sysvipc_allowed, 0,
61 "Processes in jail can use System V IPC primitives");
63 static int jail_enforce_statfs = 2;
64 SYSCTL_INT(_security_jail, OID_AUTO, enforce_statfs, CTLFLAG_RW,
65 &jail_enforce_statfs, 0,
66 "Processes in jail cannot see all mounted file systems");
68 int jail_allow_raw_sockets = 0;
69 SYSCTL_INT(_security_jail, OID_AUTO, allow_raw_sockets, CTLFLAG_RW,
70 &jail_allow_raw_sockets, 0,
71 "Prison root can create raw sockets");
73 int jail_chflags_allowed = 0;
74 SYSCTL_INT(_security_jail, OID_AUTO, chflags_allowed, CTLFLAG_RW,
75 &jail_chflags_allowed, 0,
76 "Processes in jail can alter system file flags");
78 int jail_mount_allowed = 0;
79 SYSCTL_INT(_security_jail, OID_AUTO, mount_allowed, CTLFLAG_RW,
80 &jail_mount_allowed, 0,
81 "Processes in jail can mount/unmount jail-friendly file systems");
83 /* allprison and prisoncount are protected by allprison_lock. */
84 struct sx allprison_lock;
85 SX_SYSINIT(allprison_lock, &allprison_lock, "allprison");
86 struct prisonlist allprison = LIST_HEAD_INITIALIZER(allprison);
88 /* Prison number allocation */
89 static struct unrhdr *prison_numpool;
92 * List of jail services. Protected by allprison_lock.
94 TAILQ_HEAD(prison_services_head, prison_service);
95 static struct prison_services_head prison_services =
96 TAILQ_HEAD_INITIALIZER(prison_services);
97 static int prison_service_slots = 0;
99 struct prison_service {
100 prison_create_t ps_create;
101 prison_destroy_t ps_destroy;
103 TAILQ_ENTRY(prison_service) ps_next;
107 static void init_prison(void *);
108 static void prison_complete(void *context, int pending);
109 static int sysctl_jail_list(SYSCTL_HANDLER_ARGS);
112 init_prison(void *data __unused)
115 prison_numpool = new_unrhdr(1, INT_MAX, NULL);
118 SYSINIT(prison, SI_SUB_INTRINSIC, SI_ORDER_ANY, init_prison, NULL);
126 jail(struct thread *td, struct jail_args *uap)
130 struct prison_service *psrv;
132 struct jail_attach_args jaa;
133 int vfslocked, error, prid;
135 error = copyin(uap->jail, &j, sizeof(j));
141 /* Allocate prison number */
142 prid = alloc_unr(prison_numpool);
146 MALLOC(pr, struct prison *, sizeof(*pr), M_PRISON, M_WAITOK | M_ZERO);
147 mtx_init(&pr->pr_mtx, "jail mutex", NULL, MTX_DEF);
149 pr->pr_id = jaa.jid = prid;
150 error = copyinstr(j.path, &pr->pr_path, sizeof(pr->pr_path), 0);
153 NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | LOCKLEAF, UIO_SYSSPACE,
158 vfslocked = NDHASGIANT(&nd);
159 pr->pr_root = nd.ni_vp;
160 VOP_UNLOCK(nd.ni_vp, 0);
161 NDFREE(&nd, NDF_ONLY_PNBUF);
162 VFS_UNLOCK_GIANT(vfslocked);
163 error = copyinstr(j.hostname, &pr->pr_host, sizeof(pr->pr_host), 0);
166 pr->pr_ip = j.ip_number;
168 pr->pr_securelevel = securelevel;
169 if (prison_service_slots == 0)
172 pr->pr_slots = malloc(sizeof(*pr->pr_slots) * prison_service_slots,
173 M_PRISON, M_ZERO | M_WAITOK);
176 /* Add prison to allprison list. */
177 sx_xlock(&allprison_lock);
178 LIST_INSERT_HEAD(&allprison, pr, pr_list);
180 sx_downgrade(&allprison_lock);
181 TAILQ_FOREACH(psrv, &prison_services, ps_next) {
182 psrv->ps_create(psrv, pr);
184 sx_sunlock(&allprison_lock);
186 error = jail_attach(td, &jaa);
189 mtx_lock(&pr->pr_mtx);
191 mtx_unlock(&pr->pr_mtx);
192 td->td_retval[0] = jaa.jid;
195 sx_xlock(&allprison_lock);
196 LIST_REMOVE(pr, pr_list);
198 sx_downgrade(&allprison_lock);
199 TAILQ_FOREACH(psrv, &prison_services, ps_next) {
200 psrv->ps_destroy(psrv, pr);
202 sx_sunlock(&allprison_lock);
204 vfslocked = VFS_LOCK_GIANT(pr->pr_root->v_mount);
206 VFS_UNLOCK_GIANT(vfslocked);
208 mtx_destroy(&pr->pr_mtx);
209 free_unr(prison_numpool, pr->pr_id);
215 * struct jail_attach_args {
220 jail_attach(struct thread *td, struct jail_attach_args *uap)
223 struct ucred *newcred, *oldcred;
225 int vfslocked, error;
228 * XXX: Note that there is a slight race here if two threads
229 * in the same privileged process attempt to attach to two
230 * different jails at the same time. It is important for
231 * user processes not to do this, or they might end up with
232 * a process root from one prison, but attached to the jail
235 error = priv_check(td, PRIV_JAIL_ATTACH);
240 sx_slock(&allprison_lock);
241 pr = prison_find(uap->jid);
243 sx_sunlock(&allprison_lock);
247 mtx_unlock(&pr->pr_mtx);
248 sx_sunlock(&allprison_lock);
250 vfslocked = VFS_LOCK_GIANT(pr->pr_root->v_mount);
251 vn_lock(pr->pr_root, LK_EXCLUSIVE | LK_RETRY);
252 if ((error = change_dir(pr->pr_root, td)) != 0)
255 if ((error = mac_vnode_check_chroot(td->td_ucred, pr->pr_root)))
258 VOP_UNLOCK(pr->pr_root, 0);
259 change_root(pr->pr_root, td);
260 VFS_UNLOCK_GIANT(vfslocked);
264 oldcred = p->p_ucred;
266 crcopy(newcred, oldcred);
267 newcred->cr_prison = pr;
268 p->p_ucred = newcred;
273 VOP_UNLOCK(pr->pr_root, 0);
274 VFS_UNLOCK_GIANT(vfslocked);
275 mtx_lock(&pr->pr_mtx);
277 mtx_unlock(&pr->pr_mtx);
282 * Returns a locked prison instance, or NULL on failure.
285 prison_find(int prid)
289 sx_assert(&allprison_lock, SX_LOCKED);
290 LIST_FOREACH(pr, &allprison, pr_list) {
291 if (pr->pr_id == prid) {
292 mtx_lock(&pr->pr_mtx);
293 if (pr->pr_ref == 0) {
294 mtx_unlock(&pr->pr_mtx);
304 prison_free(struct prison *pr)
307 mtx_lock(&pr->pr_mtx);
309 if (pr->pr_ref == 0) {
310 mtx_unlock(&pr->pr_mtx);
311 TASK_INIT(&pr->pr_task, 0, prison_complete, pr);
312 taskqueue_enqueue(taskqueue_thread, &pr->pr_task);
315 mtx_unlock(&pr->pr_mtx);
319 prison_complete(void *context, int pending)
321 struct prison_service *psrv;
325 pr = (struct prison *)context;
327 sx_xlock(&allprison_lock);
328 LIST_REMOVE(pr, pr_list);
330 sx_downgrade(&allprison_lock);
331 TAILQ_FOREACH(psrv, &prison_services, ps_next) {
332 psrv->ps_destroy(psrv, pr);
334 sx_sunlock(&allprison_lock);
336 vfslocked = VFS_LOCK_GIANT(pr->pr_root->v_mount);
338 VFS_UNLOCK_GIANT(vfslocked);
340 mtx_destroy(&pr->pr_mtx);
341 if (pr->pr_linux != NULL)
342 FREE(pr->pr_linux, M_PRISON);
343 free_unr(prison_numpool, pr->pr_id);
348 prison_hold(struct prison *pr)
351 mtx_lock(&pr->pr_mtx);
352 KASSERT(pr->pr_ref > 0,
353 ("Trying to hold dead prison (id=%d).", pr->pr_id));
355 mtx_unlock(&pr->pr_mtx);
359 prison_getip(struct ucred *cred)
362 return (cred->cr_prison->pr_ip);
366 prison_ip(struct ucred *cred, int flag, u_int32_t *ip)
376 if (tmp == INADDR_ANY) {
378 *ip = cred->cr_prison->pr_ip;
380 *ip = htonl(cred->cr_prison->pr_ip);
383 if (tmp == INADDR_LOOPBACK) {
385 *ip = cred->cr_prison->pr_ip;
387 *ip = htonl(cred->cr_prison->pr_ip);
390 if (cred->cr_prison->pr_ip != tmp)
396 prison_remote_ip(struct ucred *cred, int flag, u_int32_t *ip)
406 if (tmp == INADDR_LOOPBACK) {
408 *ip = cred->cr_prison->pr_ip;
410 *ip = htonl(cred->cr_prison->pr_ip);
417 prison_if(struct ucred *cred, struct sockaddr *sa)
419 struct sockaddr_in *sai;
422 sai = (struct sockaddr_in *)sa;
423 if ((sai->sin_family != AF_INET) && jail_socket_unixiproute_only)
425 else if (sai->sin_family != AF_INET)
427 else if (cred->cr_prison->pr_ip != ntohl(sai->sin_addr.s_addr))
435 * Return 0 if jails permit p1 to frob p2, otherwise ESRCH.
438 prison_check(struct ucred *cred1, struct ucred *cred2)
444 if (cred2->cr_prison != cred1->cr_prison)
452 * Return 1 if the passed credential is in a jail, otherwise 0.
455 jailed(struct ucred *cred)
458 return (cred->cr_prison != NULL);
462 * Return the correct hostname for the passed credential.
465 getcredhostname(struct ucred *cred, char *buf, size_t size)
469 mtx_lock(&cred->cr_prison->pr_mtx);
470 strlcpy(buf, cred->cr_prison->pr_host, size);
471 mtx_unlock(&cred->cr_prison->pr_mtx);
473 strlcpy(buf, hostname, size);
477 * Determine whether the subject represented by cred can "see"
478 * status of a mount point.
479 * Returns: 0 for permitted, ENOENT otherwise.
480 * XXX: This function should be called cr_canseemount() and should be
481 * placed in kern_prot.c.
484 prison_canseemount(struct ucred *cred, struct mount *mp)
490 if (!jailed(cred) || jail_enforce_statfs == 0)
492 pr = cred->cr_prison;
493 if (pr->pr_root->v_mount == mp)
495 if (jail_enforce_statfs == 2)
498 * If jail's chroot directory is set to "/" we should be able to see
499 * all mount-points from inside a jail.
500 * This is ugly check, but this is the only situation when jail's
501 * directory ends with '/'.
503 if (strcmp(pr->pr_path, "/") == 0)
505 len = strlen(pr->pr_path);
507 if (strncmp(pr->pr_path, sp->f_mntonname, len) != 0)
510 * Be sure that we don't have situation where jail's root directory
511 * is "/some/path" and mount point is "/some/pathpath".
513 if (sp->f_mntonname[len] != '\0' && sp->f_mntonname[len] != '/')
519 prison_enforce_statfs(struct ucred *cred, struct mount *mp, struct statfs *sp)
521 char jpath[MAXPATHLEN];
525 if (!jailed(cred) || jail_enforce_statfs == 0)
527 pr = cred->cr_prison;
528 if (prison_canseemount(cred, mp) != 0) {
529 bzero(sp->f_mntonname, sizeof(sp->f_mntonname));
530 strlcpy(sp->f_mntonname, "[restricted]",
531 sizeof(sp->f_mntonname));
534 if (pr->pr_root->v_mount == mp) {
536 * Clear current buffer data, so we are sure nothing from
537 * the valid path left there.
539 bzero(sp->f_mntonname, sizeof(sp->f_mntonname));
540 *sp->f_mntonname = '/';
544 * If jail's chroot directory is set to "/" we should be able to see
545 * all mount-points from inside a jail.
547 if (strcmp(pr->pr_path, "/") == 0)
549 len = strlen(pr->pr_path);
550 strlcpy(jpath, sp->f_mntonname + len, sizeof(jpath));
552 * Clear current buffer data, so we are sure nothing from
553 * the valid path left there.
555 bzero(sp->f_mntonname, sizeof(sp->f_mntonname));
556 if (*jpath == '\0') {
557 /* Should never happen. */
558 *sp->f_mntonname = '/';
560 strlcpy(sp->f_mntonname, jpath, sizeof(sp->f_mntonname));
565 * Check with permission for a specific privilege is granted within jail. We
566 * have a specific list of accepted privileges; the rest are denied.
569 prison_priv_check(struct ucred *cred, int priv)
578 * Allow ktrace privileges for root in jail.
584 * Allow jailed processes to configure audit identity and
585 * submit audit records (login, etc). In the future we may
586 * want to further refine the relationship between audit and
589 case PRIV_AUDIT_GETAUDIT:
590 case PRIV_AUDIT_SETAUDIT:
591 case PRIV_AUDIT_SUBMIT:
595 * Allow jailed processes to manipulate process UNIX
596 * credentials in any way they see fit.
598 case PRIV_CRED_SETUID:
599 case PRIV_CRED_SETEUID:
600 case PRIV_CRED_SETGID:
601 case PRIV_CRED_SETEGID:
602 case PRIV_CRED_SETGROUPS:
603 case PRIV_CRED_SETREUID:
604 case PRIV_CRED_SETREGID:
605 case PRIV_CRED_SETRESUID:
606 case PRIV_CRED_SETRESGID:
609 * Jail implements visibility constraints already, so allow
610 * jailed root to override uid/gid-based constraints.
612 case PRIV_SEEOTHERGIDS:
613 case PRIV_SEEOTHERUIDS:
616 * Jail implements inter-process debugging limits already, so
617 * allow jailed root various debugging privileges.
619 case PRIV_DEBUG_DIFFCRED:
620 case PRIV_DEBUG_SUGID:
621 case PRIV_DEBUG_UNPRIV:
624 * Allow jail to set various resource limits and login
625 * properties, and for now, exceed process resource limits.
627 case PRIV_PROC_LIMIT:
628 case PRIV_PROC_SETLOGIN:
629 case PRIV_PROC_SETRLIMIT:
632 * System V and POSIX IPC privileges are granted in jail.
637 case PRIV_IPC_MSGSIZE:
641 * Jail implements its own inter-process limits, so allow
642 * root processes in jail to change scheduling on other
643 * processes in the same jail. Likewise for signalling.
645 case PRIV_SCHED_DIFFCRED:
646 case PRIV_SIGNAL_DIFFCRED:
647 case PRIV_SIGNAL_SUGID:
650 * Allow jailed processes to write to sysctls marked as jail
653 case PRIV_SYSCTL_WRITEJAIL:
656 * Allow root in jail to manage a variety of quota
657 * properties. These should likely be conditional on a
658 * configuration option.
660 case PRIV_VFS_GETQUOTA:
661 case PRIV_VFS_SETQUOTA:
664 * Since Jail relies on chroot() to implement file system
665 * protections, grant many VFS privileges to root in jail.
666 * Be careful to exclude mount-related and NFS-related
673 case PRIV_VFS_LOOKUP:
674 case PRIV_VFS_BLOCKRESERVE: /* XXXRW: Slightly surprising. */
675 case PRIV_VFS_CHFLAGS_DEV:
677 case PRIV_VFS_CHROOT:
678 case PRIV_VFS_RETAINSUGID:
679 case PRIV_VFS_FCHROOT:
681 case PRIV_VFS_SETGID:
683 case PRIV_VFS_STICKYFILE:
687 * Depending on the global setting, allow privilege of
688 * setting system flags.
690 case PRIV_VFS_SYSFLAGS:
691 if (jail_chflags_allowed)
697 * Depending on the global setting, allow privilege of
698 * mounting/unmounting file systems.
701 case PRIV_VFS_UNMOUNT:
702 case PRIV_VFS_MOUNT_NONUSER:
703 case PRIV_VFS_MOUNT_OWNER:
704 if (jail_mount_allowed)
710 * Allow jailed root to bind reserved ports and reuse in-use
713 case PRIV_NETINET_RESERVEDPORT:
714 case PRIV_NETINET_REUSEPORT:
718 * Allow jailed root to set certian IPv4/6 (option) headers.
720 case PRIV_NETINET_SETHDROPTS:
724 * Conditionally allow creating raw sockets in jail.
726 case PRIV_NETINET_RAW:
727 if (jail_allow_raw_sockets)
733 * Since jail implements its own visibility limits on netstat
734 * sysctls, allow getcred. This allows identd to work in
737 case PRIV_NETINET_GETCRED:
742 * In all remaining cases, deny the privilege request. This
743 * includes almost all network privileges, many system
744 * configuration privileges.
751 * Register jail service. Provides 'create' and 'destroy' methods.
752 * 'create' method will be called for every existing jail and all
753 * jails in the future as they beeing created.
754 * 'destroy' method will be called for every jail going away and
755 * for all existing jails at the time of service deregistration.
757 struct prison_service *
758 prison_service_register(const char *name, prison_create_t create,
759 prison_destroy_t destroy)
761 struct prison_service *psrv, *psrv2;
763 int reallocate = 1, slotno = 0;
764 void **slots, **oldslots;
766 psrv = malloc(sizeof(*psrv) + strlen(name) + 1, M_PRISON,
768 psrv->ps_create = create;
769 psrv->ps_destroy = destroy;
770 strcpy(psrv->ps_name, name);
772 * Grab the allprison_lock here, so we won't miss any jail
773 * creation/destruction.
775 sx_xlock(&allprison_lock);
778 * Verify if service is not already registered.
780 TAILQ_FOREACH(psrv2, &prison_services, ps_next) {
781 KASSERT(strcmp(psrv2->ps_name, name) != 0,
782 ("jail service %s already registered", name));
786 * Find free slot. When there is no existing free slot available,
787 * allocate one at the end.
789 TAILQ_FOREACH(psrv2, &prison_services, ps_next) {
790 if (psrv2->ps_slotno != slotno) {
791 KASSERT(slotno < psrv2->ps_slotno,
792 ("Invalid slotno (slotno=%d >= ps_slotno=%d",
793 slotno, psrv2->ps_slotno));
794 /* We found free slot. */
800 psrv->ps_slotno = slotno;
802 * Keep the list sorted by slot number.
805 KASSERT(reallocate == 0, ("psrv2 != NULL && reallocate != 0"));
806 TAILQ_INSERT_BEFORE(psrv2, psrv, ps_next);
808 KASSERT(reallocate == 1, ("psrv2 == NULL && reallocate == 0"));
809 TAILQ_INSERT_TAIL(&prison_services, psrv, ps_next);
811 prison_service_slots++;
812 sx_downgrade(&allprison_lock);
814 * Allocate memory for new slot if we didn't found empty one.
815 * Do not use realloc(9), because pr_slots is protected with a mutex,
818 LIST_FOREACH(pr, &allprison, pr_list) {
820 /* First allocate memory with M_WAITOK. */
821 slots = malloc(sizeof(*slots) * prison_service_slots,
823 /* Now grab the mutex and replace pr_slots. */
824 mtx_lock(&pr->pr_mtx);
825 oldslots = pr->pr_slots;
826 if (psrv->ps_slotno > 0) {
827 bcopy(oldslots, slots,
828 sizeof(*slots) * (prison_service_slots - 1));
830 slots[psrv->ps_slotno] = NULL;
831 pr->pr_slots = slots;
832 mtx_unlock(&pr->pr_mtx);
833 if (oldslots != NULL)
834 free(oldslots, M_PRISON);
837 * Call 'create' method for each existing jail.
839 psrv->ps_create(psrv, pr);
841 sx_sunlock(&allprison_lock);
847 prison_service_deregister(struct prison_service *psrv)
850 void **slots, **oldslots;
853 sx_xlock(&allprison_lock);
854 if (TAILQ_LAST(&prison_services, prison_services_head) == psrv)
856 TAILQ_REMOVE(&prison_services, psrv, ps_next);
857 prison_service_slots--;
858 sx_downgrade(&allprison_lock);
859 LIST_FOREACH(pr, &allprison, pr_list) {
861 * Call 'destroy' method for every currently existing jail.
863 psrv->ps_destroy(psrv, pr);
865 * If this is the last slot, free the memory allocated for it.
868 if (prison_service_slots == 0)
871 slots = malloc(sizeof(*slots) * prison_service_slots,
874 mtx_lock(&pr->pr_mtx);
875 oldslots = pr->pr_slots;
877 * We require setting slot to NULL after freeing it,
878 * this way we can check for memory leaks here.
880 KASSERT(oldslots[psrv->ps_slotno] == NULL,
881 ("Slot %d (service %s, jailid=%d) still contains data?",
882 psrv->ps_slotno, psrv->ps_name, pr->pr_id));
883 if (psrv->ps_slotno > 0) {
884 bcopy(oldslots, slots,
885 sizeof(*slots) * prison_service_slots);
887 pr->pr_slots = slots;
888 mtx_unlock(&pr->pr_mtx);
889 KASSERT(oldslots != NULL, ("oldslots == NULL"));
890 free(oldslots, M_PRISON);
893 sx_sunlock(&allprison_lock);
894 free(psrv, M_PRISON);
898 * Function sets data for the given jail in slot assigned for the given
902 prison_service_data_set(struct prison_service *psrv, struct prison *pr,
906 mtx_assert(&pr->pr_mtx, MA_OWNED);
907 pr->pr_slots[psrv->ps_slotno] = data;
911 * Function clears slots assigned for the given jail service in the given
912 * prison structure and returns current slot data.
915 prison_service_data_del(struct prison_service *psrv, struct prison *pr)
919 mtx_assert(&pr->pr_mtx, MA_OWNED);
920 data = pr->pr_slots[psrv->ps_slotno];
921 pr->pr_slots[psrv->ps_slotno] = NULL;
926 * Function returns current data from the slot assigned to the given jail
927 * service for the given jail.
930 prison_service_data_get(struct prison_service *psrv, struct prison *pr)
933 mtx_assert(&pr->pr_mtx, MA_OWNED);
934 return (pr->pr_slots[psrv->ps_slotno]);
938 sysctl_jail_list(SYSCTL_HANDLER_ARGS)
940 struct xprison *xp, *sxp;
944 if (jailed(req->td->td_ucred))
947 sx_slock(&allprison_lock);
948 if ((count = prisoncount) == 0) {
949 sx_sunlock(&allprison_lock);
953 sxp = xp = malloc(sizeof(*xp) * count, M_TEMP, M_WAITOK | M_ZERO);
955 LIST_FOREACH(pr, &allprison, pr_list) {
956 xp->pr_version = XPRISON_VERSION;
957 xp->pr_id = pr->pr_id;
958 xp->pr_ip = pr->pr_ip;
959 strlcpy(xp->pr_path, pr->pr_path, sizeof(xp->pr_path));
960 mtx_lock(&pr->pr_mtx);
961 strlcpy(xp->pr_host, pr->pr_host, sizeof(xp->pr_host));
962 mtx_unlock(&pr->pr_mtx);
965 sx_sunlock(&allprison_lock);
967 error = SYSCTL_OUT(req, sxp, sizeof(*sxp) * count);
972 SYSCTL_OID(_security_jail, OID_AUTO, list, CTLTYPE_STRUCT | CTLFLAG_RD,
973 NULL, 0, sysctl_jail_list, "S", "List of active jails");
976 sysctl_jail_jailed(SYSCTL_HANDLER_ARGS)
980 injail = jailed(req->td->td_ucred);
981 error = SYSCTL_OUT(req, &injail, sizeof(injail));
985 SYSCTL_PROC(_security_jail, OID_AUTO, jailed, CTLTYPE_INT | CTLFLAG_RD,
986 NULL, 0, sysctl_jail_jailed, "I", "Process in jail?");