jail_attach (2)
Leading comments
Copyright (c) 1999 Poul-Henning Kamp. Copyright (c) 2009 James Gritton. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclai...
NAME
jail jail_get jail_set jail_remove jail_attach - create and manage system jailsLIBRARY
Lb libcSYNOPSIS
In sys/param.h In sys/jail.h Ft int Fn jail struct jail *jail Ft int Fn jail_attach int jid Ft int Fn jail_remove int jid In sys/uio.h Ft int Fn jail_get struct iovec *iov u_int niov int flags Ft int Fn jail_set struct iovec *iov u_int niov int flagsDESCRIPTION
The Fn 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 the Fn 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 Fn 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 Fa iov , containing Fa 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 Fn 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 Fa flags arguments consists of one or more of the following flags:
- JAIL_CREATE
- Create a new jail. If a jid or name parameters exists, they must not refer to an existing jail.
- JAIL_UPDATE
- Modify an existing jail. One of the jid or name parameters must exist, and must refer to an existing jail. If both 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
- In addition to creating or modifying the jail, attach the current process to it, as with the Fn jail_attach system call.
- JAIL_DYING
- Allow setting a jail that is in the process of being removed.
The Fn jail_get system call retrieves jail parameters, using the same name-value list as Fn jail_set in the Fa iov and Fa 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 Fa flags arguments consists of one or more following flags:
- JAIL_DYING
- Allow getting a jail that is in the process of being removed.
The Fn jail_attach system call attaches the current process to an existing jail, identified by Fa jid .
The Fn jail_remove system call removes the jail identified by Fa jid . It will kill all processes belonging to the jail, and remove any children of that jail.
RETURN VALUES
If successful, Fn jail , Fn jail_set , and Fn jail_get return a non-negative integer, termed the jail identifier (JID). They return -1 on failure, and set errno to indicate the error.Rv -std jail_attach jail_remove
ERRORS
The Fn jail system call will fail if:- Bq Er EPERM
- This process is not allowed to create a jail, either because it is not the super-user, or because it would exceed the jail's children.max limit.
- Bq Er EFAULT
- Fa jail points to an address outside the allocated address space of the process.
- Bq Er EINVAL
- The version number of the argument is not correct.
- Bq Er EAGAIN
- No free JID could be found.
The Fn jail_set system call will fail if:
- Bq Er EPERM
- This process is not allowed to create a jail, either because it is not the super-user, or because it would exceed the jail's children.max limit.
- Bq Er EPERM
- A jail parameter was set to a less restrictive value then the current environment.
- Bq Er EFAULT
- Fa Iov , or one of the addresses contained within it, points to an address outside the allocated address space of the process.
- Bq Er ENOENT
- The jail referred to by a jid or name parameter does not exist, and the JAIL_CREATE flag is not set.
- Bq Er ENOENT
- The jail referred to by a jid is not accessible by the process, because the process is in a different jail.
- Bq Er EEXIST
- The jail referred to by a jid or name parameter exists, and the JAIL_UPDATE flag is not set.
- Bq Er EINVAL
- A supplied parameter is the wrong size.
- Bq Er EINVAL
- A supplied parameter is out of range.
- Bq Er EINVAL
- A supplied string parameter is not null-terminated.
- Bq Er EINVAL
- A supplied parameter name does not match any known parameters.
- Bq Er EINVAL
- One of the JAIL_CREATE or JAIL_UPDATE flags is not set.
- Bq Er ENAMETOOLONG
- A supplied string parameter is longer than allowed.
- Bq Er EAGAIN
- There are no jail IDs left.
The Fn jail_get system call will fail if:
- Bq Er EFAULT
- Fa Iov , or one of the addresses contained within it, points to an address outside the allocated address space of the process.
- Bq Er ENOENT
- The jail referred to by a jid or name parameter does not exist.
- Bq Er ENOENT
- The jail referred to by a jid is not accessible by the process, because the process is in a different jail.
- Bq Er ENOENT
- The lastjid parameter is greater than the highest current jail ID.
- Bq Er EINVAL
- A supplied parameter is the wrong size.
- Bq Er EINVAL
- A supplied parameter name does not match any known parameters.
The Fn jail_attach and Fn jail_remove system calls will fail if:
- Bq Er EPERM
- A user other than the super-user attempted to attach to or remove a jail.
- Bq Er EINVAL
- The jail specified by Fa jid does not exist.
Further Fn jail , Fn jail_set , and Fn jail_attach call chroot(2) internally, so they can fail for all the same reasons. Please consult the chroot(2) manual page for details.