JAIL(2) | System Calls Manual | JAIL(2) |
jail
, jail_get
,
jail_set
, jail_remove
,
jail_attach
— create and
manage system jails
Standard C Library (libc, -lc)
#include
<sys/param.h>
#include <sys/jail.h>
int
jail
(struct
jail *jail);
int
jail_attach
(int
jid);
int
jail_remove
(int
jid);
#include
<sys/uio.h>
int
jail_get
(struct
iovec *iov, u_int
niov, int
flags);
int
jail_set
(struct
iovec *iov, u_int
niov, int
flags);
The
jail
()
system call sets up a jail and locks the current process in it.
The argument is a pointer to a structure describing the prison:
struct jail { uint32_t version; char *path; char *hostname; char *jailname; unsigned int ip4s; unsigned int ip6s; struct in_addr *ip4; struct in6_addr *ip6; };
“version
” defines the
version of the API in use. JAIL_API_VERSION
is
defined for the current version.
The “path
” pointer should be
set to the directory which is to be the root of the prison.
The “hostname
” pointer can
be set to the hostname of the prison. This can be changed from the inside of
the prison.
The “jailname
” pointer is an
optional name that can be assigned to the jail for example for management
purposes.
The “ip4s
” and
“ip6s
” give the numbers of IPv4 and
IPv6 addresses that will be passed via their respective pointers.
The “ip4
” and
“ip6
” pointers can be set to an arrays
of IPv4 and IPv6 addresses to be assigned to the prison, or NULL if none.
IPv4 addresses must be in network byte order.
This is equivalent to, and deprecated in favor of,
the
jail_set
()
system call (see below), with the parameters path,
host.hostname, name,
ip4.addr, and ip6.addr, and with
the JAIL_ATTACH
flag.
The
jail_set
()
system call creates a new jail, or modifies an existing one, and optionally
locks the current process in it. Jail parameters are passed as an array of
name-value pairs in the array iov, containing
niov elements. Parameter names are a null-terminated
string, and values may be strings, integers, or other arbitrary data. Some
parameters are boolean, and do not have a value (their length is zero) but
are set by the name alone with or without a “no” prefix, e.g.
persist or nopersist. Any
parameters not set will be given default values, generally based on the
current environment.
Jails have a set of core parameters, and modules can
add their own jail parameters. The current set of available parameters, and
their formats, can be retrieved via the
security.jail.param sysctl MIB entry. Notable
parameters include those mentioned in the
jail
()
description above, as well as jid and
name, which identify the jail being created or
modified. See jail(8) for more information on the core
jail parameters.
The flags arguments consists of one or more of the following flags:
JAIL_CREATE
JAIL_UPDATE
JAIL_CREATE
and
JAIL_UPDATE
are set, a jail will be created if it
does not yet exist, and modified if it does exist.JAIL_ATTACH
jail_attach
()
system call.JAIL_DYING
The
jail_get
()
system call retrieves jail parameters, using the same name-value list as
jail_set
() in the iov and
niov arguments. The jail to read can be specified by
either jid or name by including
those parameters in the list. If they are included but are not intended to
be the search key, they should be cleared (zero and the empty string
respectively).
The special parameter lastjid can be used to retrieve a list of all jails. It will fetch the jail with the jid above and closest to the passed value. The first jail (usually but not always jid 1) can be found by passing a lastjid of zero.
The flags arguments consists of one or more following flags:
JAIL_DYING
The
jail_attach
()
system call attaches the current process to an existing jail, identified by
jid.
The
jail_remove
()
system call removes the jail identified by jid. It
will kill all processes belonging to the jail, and remove any children of
that jail.
If successful, jail
(),
jail_set
(), and jail_get
()
return a non-negative integer, termed the jail identifier (JID). They return
-1 on failure, and set errno to indicate the
error.
The jail_attach
() and
jail_remove
() functions return the value 0 if
successful; otherwise the value -1 is returned and the global
variable errno is set to indicate the error.
The jail
() system call will fail if:
EPERM
]EFAULT
]EINVAL
]EAGAIN
]The jail_set
() system call will fail
if:
EPERM
]EPERM
]EFAULT
]ENOENT
]JAIL_CREATE
flag is not set.ENOENT
]EEXIST
]JAIL_UPDATE
flag is not set.EINVAL
]EINVAL
]EINVAL
]EINVAL
]EINVAL
]JAIL_CREATE
or
JAIL_UPDATE
flags is not set.ENAMETOOLONG
]EAGAIN
]The jail_get
() system call will fail
if:
EFAULT
]ENOENT
]ENOENT
]ENOENT
]EINVAL
]EINVAL
]The jail_attach
() and
jail_remove
() system calls will fail if:
EPERM
]EINVAL
]Further jail
(),
jail_set
(), and
jail_attach
() call chroot(2)
internally, so they can fail for all the same reasons. Please consult the
chroot(2) manual page for details.
The jail
() system call appeared in
FreeBSD 4.0. The
jail_attach
() system call appeared in
FreeBSD 5.1. The jail_set
(),
jail_get
(), and
jail_remove
() system calls appeared in
FreeBSD 8.0.
The jail feature was written by Poul-Henning
Kamp for R&D Associates who contributed it to
FreeBSD.
James Gritton added the extensible jail parameters and
hierarchical jails.
February 8, 2012 | Debian |