2007-11-21 18:22:29 +00:00
|
|
|
.\" Copyright (C) 2006, Janak Desai <janak@us.ibm.com>
|
2013-01-10 20:20:05 +00:00
|
|
|
.\" and Copyright (C) 2006, 2012 Michael Kerrisk <mtk.manpages@gmail.com>
|
ldd.1, capget.2, clone.2, create_module.2, fallocate.2, futex.2, get_kernel_syms.2, get_thread_area.2, getcpu.2, getitimer.2, getpid.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl_list.2, mkdir.2, mknod.2, pciconfig_read.2, pivot_root.2, posix_fadvise.2, query_module.2, sendfile.2, set_thread_area.2, setns.2, unshare.2, __setfpucw.3, a64l.3, addseverity.3, argz_add.3, bindresvport.3, cabs.3, cacos.3, cacosh.3, canonicalize_file_name.3, carg.3, casin.3, casinh.3, catan.3, catanh.3, ccos.3, ccosh.3, cerf.3, cexp.3, cexp2.3, cimag.3, clog.3, clog10.3, clog2.3, cmsg.3, conj.3, cpow.3, cproj.3, creal.3, csin.3, csinh.3, csqrt.3, ctan.3, ctanh.3, des_crypt.3, envz_add.3, fdim.3, fma.3, fmax.3, fmemopen.3, fmin.3, fmtmsg.3, fpclassify.3, gamma.3, getpt.3, getrpcent.3, getrpcport.3, getttyent.3, isgreater.3, key_setsecret.3, lgamma.3, malloc_hook.3, mempcpy.3, nan.3, netlink.3, nextafter.3, putgrent.3, remove.3, remquo.3, rpc.3, rtime.3, rtnetlink.3, setaliasent.3, setnetgrent.3, signbit.3, significand.3, sincos.3, stdin.3, tgamma.3, xcrypt.3, xdr.3, cciss.4, hpsa.4, mouse.4, pts.4, sk98lin.4, tty_ioctl.4, wavelan.4, hosts.equiv.5, rpc.5, tzfile.5, boot.7, complex.7, ddp.7, fifo.7, futex.7, icmp.7, ip.7, ipv6.7, netdevice.7, netlink.7, packet.7, raw.7, rtnetlink.7, socket.7, tcp.7, udp.7, unix.7, x25.7, sync.8: Global fix: Put copyright info at top of page, followed by blank line and LICENSE
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-03-10 09:29:51 +00:00
|
|
|
.\"
|
2013-03-10 09:28:50 +00:00
|
|
|
.\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
|
2006-03-20 21:29:29 +00:00
|
|
|
.\" Licensed under the GPL
|
2013-03-10 09:28:50 +00:00
|
|
|
.\" %%%LICENSE_END
|
2006-03-20 21:29:29 +00:00
|
|
|
.\"
|
2006-07-04 13:26:13 +00:00
|
|
|
.\" Patch Justification:
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" unshare system call is needed to implement, using PAM,
|
|
|
|
.\" per-security_context and/or per-user namespace to provide
|
|
|
|
.\" polyinstantiated directories. Using unshare and bind mounts, a
|
|
|
|
.\" PAM module can create private namespace with appropriate
|
|
|
|
.\" directories(based on user's security context) bind mounted on
|
|
|
|
.\" public directories such as /tmp, thus providing an instance of
|
|
|
|
.\" /tmp that is based on user's security context. Without the
|
|
|
|
.\" unshare system call, namespace separation can only be achieved
|
|
|
|
.\" by clone, which would require porting and maintaining all commands
|
|
|
|
.\" such as login, and su, that establish a user session.
|
2006-07-04 13:26:13 +00:00
|
|
|
.\"
|
ldd.1, localedef.1, add_key.2, chroot.2, clone.2, fork.2, futex.2, get_mempolicy.2, get_robust_list.2, getitimer.2, getpriority.2, ioctl.2, ioctl_ficlonerange.2, ioctl_fideduperange.2, kcmp.2, kill.2, lookup_dcookie.2, mmap.2, mount.2, open.2, pciconfig_read.2, perf_event_open.2, prctl.2, process_vm_readv.2, ptrace.2, quotactl.2, recv.2, setfsgid.2, setfsuid.2, sysinfo.2, umask.2, umount.2, unshare.2, utimensat.2, wait.2, assert.3, fmax.3, fmin.3, getauxval.3, inet_pton.3, malloc_hook.3, memmem.3, mkdtemp.3, mktemp.3, printf.3, strcasecmp.3, strcat.3, strtoul.3, strxfrm.3, console_codes.4, console_ioctl.4, lirc.4, tty.4, vcs.4, charmap.5, elf.5, locale.5, proc.5, repertoiremap.5, utmp.5, capabilities.7, cgroup_namespaces.7, cgroups.7, charsets.7, cp1251.7, cp1252.7, credentials.7, feature_test_macros.7, iso_8859-1.7, iso_8859-15.7, iso_8859-5.7, koi8-r.7, koi8-u.7, man-pages.7, mount_namespaces.7, namespaces.7, netlink.7, pid_namespaces.7, unix.7, user_namespaces.7, utf-8.7: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-07-17 16:07:58 +00:00
|
|
|
.TH UNSHARE 2 2016-07-17 "Linux" "Linux Programmer's Manual"
|
2006-03-20 21:29:29 +00:00
|
|
|
.SH NAME
|
|
|
|
unshare \- disassociate parts of the process execution context
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
2016-02-12 12:57:24 +00:00
|
|
|
.B #define _GNU_SOURCE
|
2006-03-20 21:29:29 +00:00
|
|
|
.B #include <sched.h>
|
|
|
|
.sp
|
|
|
|
.BI "int unshare(int " flags );
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
2007-04-12 22:42:49 +00:00
|
|
|
.BR unshare ()
|
2015-05-05 07:35:20 +00:00
|
|
|
allows a process (or thread) to disassociate parts of its execution
|
2015-08-08 08:04:37 +00:00
|
|
|
context that are currently being shared with other processes (or threads).
|
2008-11-20 16:04:07 +00:00
|
|
|
Part of the execution context, such as the mount namespace, is shared
|
2007-04-12 22:42:49 +00:00
|
|
|
implicitly when a new process is created using
|
2006-03-20 21:29:29 +00:00
|
|
|
.BR fork (2)
|
|
|
|
or
|
2007-04-12 22:42:49 +00:00
|
|
|
.BR vfork (2),
|
2006-03-20 21:29:29 +00:00
|
|
|
while other parts, such as virtual memory, may be
|
2015-05-05 07:35:20 +00:00
|
|
|
shared by explicit request when creating a process or thread using
|
2006-03-20 21:29:29 +00:00
|
|
|
.BR clone (2).
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
The main use of
|
2006-03-20 21:29:29 +00:00
|
|
|
.BR unshare ()
|
|
|
|
is to allow a process to control its
|
|
|
|
shared execution context without creating a new process.
|
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
The
|
|
|
|
.I flags
|
|
|
|
argument is a bit mask that specifies which parts of
|
|
|
|
the execution context should be unshared.
|
2006-03-20 21:29:29 +00:00
|
|
|
This argument is specified by ORing together zero or more
|
|
|
|
of the following constants:
|
|
|
|
.TP
|
|
|
|
.B CLONE_FILES
|
|
|
|
Reverse the effect of the
|
|
|
|
.BR clone (2)
|
|
|
|
.B CLONE_FILES
|
|
|
|
flag.
|
2007-04-12 22:42:49 +00:00
|
|
|
Unshare the file descriptor table, so that the calling process
|
2006-03-20 21:29:29 +00:00
|
|
|
no longer shares its file descriptors with any other process.
|
|
|
|
.TP
|
|
|
|
.B CLONE_FS
|
|
|
|
Reverse the effect of the
|
|
|
|
.BR clone (2)
|
2007-04-12 22:42:49 +00:00
|
|
|
.B CLONE_FS
|
2006-03-20 21:29:29 +00:00
|
|
|
flag.
|
intro.1, time.1, access.2, acct.2, alloc_hugepages.2, bind.2, chdir.2, chmod.2, chown.2, chroot.2, clone.2, close.2, execve.2, fallocate.2, fcntl.2, getdents.2, getrusage.2, getxattr.2, init_module.2, inotify_add_watch.2, ioprio_set.2, kcmp.2, link.2, listxattr.2, lseek.2, madvise.2, mkdir.2, mknod.2, mmap.2, mount.2, move_pages.2, msgctl.2, nfsservctl.2, open.2, pivot_root.2, quotactl.2, read.2, readlink.2, removexattr.2, rename.2, rmdir.2, semctl.2, setfsgid.2, setfsuid.2, setresuid.2, setuid.2, setup.2, setxattr.2, shmctl.2, splice.2, spu_create.2, stat.2, statfs.2, swapon.2, symlink.2, sync.2, sync_file_range.2, sysfs.2, truncate.2, umount.2, unlink.2, unshare.2, ustat.2, utime.2, utimensat.2, write.2, btree.3, errno.3, fexecve.3, ftw.3, futimes.3, get_nprocs_conf.3, getcwd.3, getdirentries.3, getmntent.3, glob.3, mkfifo.3, mq_open.3, readdir.3, realpath.3, recno.3, remove.3, sem_open.3, shm_open.3, statvfs.3, sysconf.3, telldir.3, tmpfile.3, cciss.4, initrd.4, pts.4, sk98lin.4, vcs.4, core.5, filesystems.5, proc.5, boot.7, bootparam.7, capabilities.7, cpuset.7, credentials.7, feature_test_macros.7, fifo.7, hier.7, inotify.7, intro.7, mq_overview.7, path_resolution.7, pipe.7, sem_overview.7, shm_overview.7, spufs.7, symlink.7, unix.7, uri.7, sync.8: Global fix: s/file system/filesystem/
Notwithstanding 24d01c530c5a3f75217543d02bf6712395e5f90c,
"filesystem" is the form used by the great majority of man pages
outside the man-pages project and in a number of other sources,
so let's go with that.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2013-08-08 08:07:57 +00:00
|
|
|
Unshare filesystem attributes, so that the calling process
|
2013-01-01 00:28:28 +00:00
|
|
|
no longer shares its root directory
|
|
|
|
.RB ( chroot (2)),
|
|
|
|
current directory
|
|
|
|
.RB ( chdir (2)),
|
|
|
|
or umask
|
|
|
|
.RB ( umask (2))
|
|
|
|
attributes with any other process.
|
2006-03-20 21:29:29 +00:00
|
|
|
.TP
|
2016-04-28 12:38:25 +00:00
|
|
|
.BR CLONE_NEWCGROUP " (since Linux 4.6)"
|
|
|
|
This flag has the same effect as the
|
|
|
|
.BR clone (2)
|
|
|
|
.B CLONE_NEWCGROUP
|
|
|
|
flag.
|
|
|
|
Unshare the cgroup namespace.
|
|
|
|
Use of
|
|
|
|
.BR CLONE_NEWCGROUP
|
|
|
|
requires the
|
|
|
|
.BR CAP_SYS_ADMIN
|
|
|
|
capability.
|
|
|
|
.TP
|
2016-04-28 12:36:59 +00:00
|
|
|
.BR CLONE_NEWIPC " (since Linux 2.6.19)"
|
2010-10-24 14:14:09 +00:00
|
|
|
This flag has the same effect as the
|
|
|
|
.BR clone (2)
|
|
|
|
.B CLONE_NEWIPC
|
|
|
|
flag.
|
2015-03-31 19:45:44 +00:00
|
|
|
Unshare the IPC namespace,
|
2010-10-24 14:14:09 +00:00
|
|
|
so that the calling process has a private copy of the
|
2015-03-31 19:45:44 +00:00
|
|
|
IPC namespace which is not shared with any other process.
|
2010-10-24 14:14:09 +00:00
|
|
|
Specifying this flag automatically implies
|
|
|
|
.BR CLONE_SYSVSEM
|
|
|
|
as well.
|
|
|
|
Use of
|
|
|
|
.BR CLONE_NEWIPC
|
|
|
|
requires the
|
|
|
|
.BR CAP_SYS_ADMIN
|
|
|
|
capability.
|
|
|
|
.TP
|
2016-04-28 12:36:59 +00:00
|
|
|
.BR CLONE_NEWNET " (since Linux 2.6.24)"
|
2010-10-24 14:32:50 +00:00
|
|
|
This flag has the same effect as the
|
|
|
|
.BR clone (2)
|
|
|
|
.B CLONE_NEWNET
|
|
|
|
flag.
|
|
|
|
Unshare the network namespace,
|
2010-10-30 05:52:36 +00:00
|
|
|
so that the calling process is moved into a
|
|
|
|
new network namespace which is not shared
|
|
|
|
with any previously existing process.
|
2013-01-01 00:29:12 +00:00
|
|
|
Use of
|
2010-10-24 14:32:50 +00:00
|
|
|
.BR CLONE_NEWNET
|
|
|
|
requires the
|
|
|
|
.BR CAP_SYS_ADMIN
|
|
|
|
capability.
|
|
|
|
.TP
|
2006-03-20 21:29:29 +00:00
|
|
|
.B CLONE_NEWNS
|
|
|
|
.\" These flag name are inconsistent:
|
2007-04-12 22:42:49 +00:00
|
|
|
.\" CLONE_NEWNS does the same thing in clone(), but CLONE_VM,
|
2006-03-20 21:29:29 +00:00
|
|
|
.\" CLONE_FS, and CLONE_FILES reverse the action of the clone()
|
|
|
|
.\" flags of the same name.
|
2010-10-24 13:59:48 +00:00
|
|
|
This flag has the same effect as the
|
2006-03-20 21:29:29 +00:00
|
|
|
.BR clone (2)
|
|
|
|
.B CLONE_NEWNS
|
|
|
|
flag.
|
2008-11-20 16:04:07 +00:00
|
|
|
Unshare the mount namespace,
|
2008-11-19 19:23:47 +00:00
|
|
|
so that the calling process has a private copy of
|
2006-03-20 21:29:29 +00:00
|
|
|
its namespace which is not shared with any other process.
|
|
|
|
Specifying this flag automatically implies
|
|
|
|
.B CLONE_FS
|
|
|
|
as well.
|
2010-10-24 14:02:24 +00:00
|
|
|
Use of
|
|
|
|
.BR CLONE_NEWNS
|
|
|
|
requires the
|
|
|
|
.BR CAP_SYS_ADMIN
|
|
|
|
capability.
|
2016-06-30 03:59:44 +00:00
|
|
|
For further information, see
|
|
|
|
.BR mount_namespaces (7).
|
2010-10-24 14:18:12 +00:00
|
|
|
.TP
|
2013-01-01 11:06:09 +00:00
|
|
|
.BR CLONE_NEWPID " (since Linux 3.8)"
|
|
|
|
This flag has the same effect as the
|
|
|
|
.BR clone (2)
|
|
|
|
.B CLONE_NEWPID
|
|
|
|
flag.
|
|
|
|
Unshare the PID namespace,
|
2013-01-07 05:25:07 +00:00
|
|
|
so that the calling process has a new PID namespace for its children
|
2013-01-01 11:06:09 +00:00
|
|
|
which is not shared with any previously existing process.
|
2013-01-07 08:19:19 +00:00
|
|
|
The calling process is
|
|
|
|
.I not
|
|
|
|
moved into the new namespace.
|
|
|
|
The first child created by the calling process will have
|
|
|
|
the process ID 1 and will assume the role of
|
|
|
|
.BR init (1)
|
|
|
|
in the new namespace.
|
2013-03-22 07:58:50 +00:00
|
|
|
.BR CLONE_NEWPID
|
|
|
|
automatically implies
|
|
|
|
.BR CLONE_THREAD
|
|
|
|
as well.
|
2013-01-01 11:06:09 +00:00
|
|
|
Use of
|
|
|
|
.BR CLONE_NEWPID
|
|
|
|
requires the
|
|
|
|
.BR CAP_SYS_ADMIN
|
|
|
|
capability.
|
2013-03-22 07:18:07 +00:00
|
|
|
For further information, see
|
|
|
|
.BR pid_namespaces (7).
|
2013-01-01 11:06:09 +00:00
|
|
|
.TP
|
2013-01-01 10:26:49 +00:00
|
|
|
.BR CLONE_NEWUSER " (since Linux 3.8)"
|
|
|
|
This flag has the same effect as the
|
|
|
|
.BR clone (2)
|
|
|
|
.B CLONE_NEWUSER
|
|
|
|
flag.
|
|
|
|
Unshare the user namespace,
|
|
|
|
so that the calling process is moved into a new user namespace
|
|
|
|
which is not shared with any previously existing process.
|
2013-03-22 07:50:13 +00:00
|
|
|
As with the child process created by
|
2013-03-04 16:39:46 +00:00
|
|
|
.BR clone (2)
|
|
|
|
with the
|
|
|
|
.B CLONE_NEWUSER
|
|
|
|
flag, the caller obtains a full set of capabilities in the new namespace.
|
2013-03-22 07:54:12 +00:00
|
|
|
.IP
|
|
|
|
.BR CLONE_NEWUSER
|
|
|
|
requires that the calling process is not threaded; specifying
|
|
|
|
.BR CLONE_NEWUSER
|
|
|
|
automatically implies
|
2013-03-22 12:06:53 +00:00
|
|
|
.BR CLONE_THREAD .
|
2014-06-02 11:33:20 +00:00
|
|
|
Since Linux 3.9,
|
2013-03-22 12:06:53 +00:00
|
|
|
.\" commit e66eded8309ebf679d3d3c1f5820d1f2ca332c71
|
|
|
|
.\" https://lwn.net/Articles/543273/
|
2014-06-02 11:33:20 +00:00
|
|
|
.BR CLONE_NEWUSER
|
|
|
|
also automatically implies
|
|
|
|
.BR CLONE_FS .
|
2013-01-07 05:25:07 +00:00
|
|
|
.BR CLONE_NEWUSER
|
2013-03-22 07:54:12 +00:00
|
|
|
requires that the user ID and group ID
|
2013-03-22 12:09:16 +00:00
|
|
|
of the calling process are mapped to user IDs and group IDs in the
|
2013-01-07 05:25:07 +00:00
|
|
|
user namespace of the calling process at the time of the call.
|
2013-03-22 12:05:30 +00:00
|
|
|
|
|
|
|
For further information on user namespaces, see
|
2013-03-22 07:14:13 +00:00
|
|
|
.BR user_namespaces (7).
|
2013-01-01 10:26:49 +00:00
|
|
|
.TP
|
2013-01-01 10:23:47 +00:00
|
|
|
.BR CLONE_NEWUTS " (since Linux 2.6.19)"
|
2013-01-01 10:06:23 +00:00
|
|
|
This flag has the same effect as the
|
|
|
|
.BR clone (2)
|
|
|
|
.B CLONE_NEWUTS
|
|
|
|
flag.
|
|
|
|
Unshare the UTS IPC namespace,
|
|
|
|
so that the calling process has a private copy of the
|
|
|
|
UTS namespace which is not shared with any other process.
|
|
|
|
Use of
|
|
|
|
.BR CLONE_NEWUTS
|
|
|
|
requires the
|
|
|
|
.BR CAP_SYS_ADMIN
|
|
|
|
capability.
|
|
|
|
.TP
|
2010-10-24 14:18:12 +00:00
|
|
|
.BR CLONE_SYSVSEM " (since Linux 2.6.26)
|
2013-01-01 00:21:12 +00:00
|
|
|
.\" commit 9edff4ab1f8d82675277a04e359d0ed8bf14a7b7
|
2010-10-24 14:18:12 +00:00
|
|
|
This flag reverses the effect of the
|
|
|
|
.BR clone (2)
|
|
|
|
.B CLONE_SYSVSEM
|
|
|
|
flag.
|
2013-03-22 10:38:55 +00:00
|
|
|
Unshare System\ V semaphore adjustment
|
|
|
|
.RI ( semadj )
|
|
|
|
values,
|
|
|
|
so that the calling process has a new empty
|
|
|
|
.I semadj
|
|
|
|
list that is not shared with any other process.
|
|
|
|
If this is the last process that has a reference to the process's current
|
|
|
|
.I semadj
|
|
|
|
list, then the adjustments in that list are applied
|
|
|
|
to the corresponding semaphores, as described in
|
|
|
|
.BR semop (2).
|
2013-01-01 10:28:02 +00:00
|
|
|
.\" CLONE_NEWNS If CLONE_SIGHAND is set and signals are also being shared
|
2006-03-20 21:29:29 +00:00
|
|
|
.\" (i.e., current->signal->count > 1), force CLONE_THREAD.
|
2006-03-21 05:42:30 +00:00
|
|
|
.PP
|
2013-03-06 09:10:44 +00:00
|
|
|
In addition,
|
|
|
|
.BR CLONE_THREAD ,
|
|
|
|
.BR CLONE_SIGHAND ,
|
|
|
|
and
|
|
|
|
.BR CLONE_VM
|
|
|
|
can be specified in
|
|
|
|
.I flags
|
|
|
|
if the caller is single threaded (i.e., it is not sharing
|
|
|
|
its address space with another process or thread).
|
|
|
|
In this case, these flags have no effect.
|
2014-09-14 03:07:12 +00:00
|
|
|
(Note also that specifying
|
|
|
|
.BR CLONE_THREAD
|
|
|
|
automatically implies
|
|
|
|
.BR CLONE_VM ,
|
|
|
|
and specifying
|
|
|
|
.BR CLONE_VM
|
|
|
|
automatically implies
|
|
|
|
.BR CLONE_SIGHAND .)
|
2013-03-22 07:41:41 +00:00
|
|
|
.\" As at 3.9, the following forced implications also apply,
|
|
|
|
.\" although the relevant flags are not yet implemented.
|
|
|
|
.\" If CLONE_THREAD is set force CLONE_VM.
|
|
|
|
.\" If CLONE_VM is set, force CLONE_SIGHAND.
|
|
|
|
.\"
|
2013-03-06 09:10:44 +00:00
|
|
|
If the process is multithreaded, then
|
|
|
|
the use of these flags results in an error.
|
|
|
|
.\" See kernel/fork.c::check_unshare_flags()
|
|
|
|
.PP
|
2007-04-12 22:42:49 +00:00
|
|
|
If
|
2006-03-20 21:29:29 +00:00
|
|
|
.I flags
|
|
|
|
is specified as zero, then
|
|
|
|
.BR unshare ()
|
|
|
|
is a no-op;
|
|
|
|
no changes are made to the calling process's execution context.
|
|
|
|
.SH RETURN VALUE
|
2007-04-12 22:42:49 +00:00
|
|
|
On success, zero returned.
|
|
|
|
On failure, \-1 is returned and
|
|
|
|
.I errno
|
2006-03-20 21:29:29 +00:00
|
|
|
is set to indicate the error.
|
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
2007-08-27 07:56:52 +00:00
|
|
|
.B EINVAL
|
|
|
|
An invalid bit was specified in
|
|
|
|
.IR flags .
|
|
|
|
.TP
|
2013-03-06 09:10:44 +00:00
|
|
|
.B EINVAL
|
|
|
|
.BR CLONE_THREAD ,
|
|
|
|
.BR CLONE_SIGHAND ,
|
|
|
|
or
|
|
|
|
.BR CLONE_VM
|
|
|
|
was specified in
|
|
|
|
.IR flags ,
|
|
|
|
and the caller is multithreaded.
|
|
|
|
.TP
|
2007-08-27 07:56:52 +00:00
|
|
|
.B ENOMEM
|
|
|
|
Cannot allocate sufficient memory to copy parts of caller's
|
|
|
|
context that need to be unshared.
|
|
|
|
.TP
|
2006-03-20 21:29:29 +00:00
|
|
|
.B EPERM
|
2010-10-24 14:02:24 +00:00
|
|
|
The calling process did not have the required privileges for this operation.
|
2013-02-26 13:02:06 +00:00
|
|
|
.TP
|
|
|
|
.B EPERM
|
|
|
|
.BR CLONE_NEWUSER
|
|
|
|
was specified in
|
|
|
|
.IR flags ,
|
|
|
|
but either the effective user ID or the effective group ID of the caller
|
|
|
|
does not have a mapping in the parent namespace (see
|
2013-02-27 06:40:40 +00:00
|
|
|
.BR user_namespaces (7)).
|
2014-06-02 09:33:52 +00:00
|
|
|
.TP
|
2014-06-02 10:17:46 +00:00
|
|
|
.BR EPERM " (since Linux 3.9)"
|
|
|
|
.\" commit 3151527ee007b73a0ebd296010f1c0454a919c7d
|
2015-01-15 17:21:28 +00:00
|
|
|
.B CLONE_NEWUSER
|
|
|
|
was specified in
|
2014-06-02 10:17:46 +00:00
|
|
|
.I flags
|
|
|
|
and the caller is in a chroot environment
|
|
|
|
.\" FIXME What is the rationale for this restriction?
|
|
|
|
(i.e., the caller's root directory does not match the root directory
|
|
|
|
of the mount namespace in which it resides).
|
|
|
|
.TP
|
|
|
|
.BR EUSERS " (since Linux 3.11)"
|
2014-06-02 09:33:52 +00:00
|
|
|
.B CLONE_NEWUSER
|
|
|
|
was specified in
|
|
|
|
.IR flags ,
|
|
|
|
and the call would cause the limit on the number of
|
|
|
|
nested user namespaces to be exceeded.
|
|
|
|
See
|
|
|
|
.BR user_namespaces (7).
|
2007-05-16 04:39:23 +00:00
|
|
|
.SH VERSIONS
|
2006-03-20 21:29:29 +00:00
|
|
|
The
|
|
|
|
.BR unshare ()
|
|
|
|
system call was added to Linux in kernel 2.6.16.
|
2007-05-18 16:30:46 +00:00
|
|
|
.SH CONFORMING TO
|
|
|
|
The
|
|
|
|
.BR unshare ()
|
2007-12-25 21:28:09 +00:00
|
|
|
system call is Linux-specific.
|
2007-05-16 04:39:23 +00:00
|
|
|
.SH NOTES
|
2007-04-12 22:42:49 +00:00
|
|
|
Not all of the process attributes that can be shared when
|
2006-03-20 21:29:29 +00:00
|
|
|
a new process is created using
|
|
|
|
.BR clone (2)
|
|
|
|
can be unshared using
|
|
|
|
.BR unshare ().
|
2013-01-01 00:25:22 +00:00
|
|
|
In particular, as at kernel 3.8,
|
2012-12-05 16:21:14 +00:00
|
|
|
.\" FIXME all of the following needs to be reviewed for the current kernel
|
2007-04-12 22:42:49 +00:00
|
|
|
.BR unshare ()
|
2006-03-20 21:29:29 +00:00
|
|
|
does not implement flags that reverse the effects of
|
|
|
|
.BR CLONE_SIGHAND ,
|
2006-03-21 05:42:30 +00:00
|
|
|
.\" However, we can do unshare(CLONE_SIGHAND) if CLONE_SIGHAND
|
2006-03-20 21:29:29 +00:00
|
|
|
.\" was not specified when doing clone(); i.e., unsharing
|
|
|
|
.\" signal handlers is permitted if we are not actually
|
|
|
|
.\" sharing signal handlers. mtk
|
2006-03-21 05:42:30 +00:00
|
|
|
.BR CLONE_THREAD ,
|
|
|
|
or
|
|
|
|
.BR CLONE_VM .
|
2013-01-01 00:25:22 +00:00
|
|
|
.\" However, we can do unshare(CLONE_VM) if CLONE_VM
|
2006-03-21 05:42:30 +00:00
|
|
|
.\" was not specified when doing clone(); i.e., unsharing
|
|
|
|
.\" virtual memory is permitted if we are not actually
|
|
|
|
.\" sharing virtual memory. mtk
|
2006-03-20 21:29:29 +00:00
|
|
|
Such functionality may be added in the future, if required.
|
|
|
|
.\"
|
|
|
|
.\"9) Future Work
|
|
|
|
.\"--------------
|
|
|
|
.\"The current implementation of unshare does not allow unsharing of
|
|
|
|
.\"signals and signal handlers. Signals are complex to begin with and
|
|
|
|
.\"to unshare signals and/or signal handlers of a currently running
|
|
|
|
.\"process is even more complex. If in the future there is a specific
|
|
|
|
.\"need to allow unsharing of signals and/or signal handlers, it can
|
|
|
|
.\"be incrementally added to unshare without affecting legacy
|
|
|
|
.\"applications using unshare.
|
|
|
|
.\"
|
2013-01-10 20:20:05 +00:00
|
|
|
.SH EXAMPLE
|
|
|
|
The program below provides a simple implementation of the
|
|
|
|
.BR unshare (1)
|
|
|
|
command, which unshares one or more namespaces and executes the
|
2014-06-02 09:29:05 +00:00
|
|
|
command supplied in its command-line arguments.
|
2013-01-10 20:20:05 +00:00
|
|
|
Here's an example of the use of this program,
|
|
|
|
running a shell in a new mount namespace,
|
|
|
|
and verifying that the original shell and the
|
|
|
|
new shell are in separate mount namespaces:
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
|
|
|
|
$ \fBreadlink /proc/$$/ns/mnt\fP
|
|
|
|
mnt:[4026531840]
|
|
|
|
$ \fBsudo ./unshare -m /bin/bash\fP
|
|
|
|
[sudo] password for cecilia:
|
|
|
|
# \fBreadlink /proc/$$/ns/mnt\fP
|
|
|
|
mnt:[4026532325]
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
|
|
|
|
The differing output of the two
|
|
|
|
.BR readlink (1)
|
|
|
|
commands shows that the two shells are in different mount namespaces.
|
|
|
|
.SS Program source
|
|
|
|
\&
|
|
|
|
.nf
|
2014-09-21 09:24:24 +00:00
|
|
|
/* unshare.c
|
2013-01-10 20:20:05 +00:00
|
|
|
|
|
|
|
A simple implementation of the unshare(1) command: unshare
|
|
|
|
namespaces and execute a command.
|
|
|
|
*/
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <sched.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* A simple error\-handling function: print an error message based
|
|
|
|
on the value in \(aqerrno\(aq and terminate the calling process */
|
|
|
|
|
|
|
|
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \\
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(char *pname)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s [options] program [arg...]\\n", pname);
|
|
|
|
fprintf(stderr, "Options can be:\\n");
|
|
|
|
fprintf(stderr, " \-i unshare IPC namespace\\n");
|
|
|
|
fprintf(stderr, " \-m unshare mount namespace\\n");
|
|
|
|
fprintf(stderr, " \-n unshare network namespace\\n");
|
|
|
|
fprintf(stderr, " \-p unshare PID namespace\\n");
|
|
|
|
fprintf(stderr, " \-u unshare UTS namespace\\n");
|
|
|
|
fprintf(stderr, " \-U unshare user namespace\\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int flags, opt;
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
|
|
|
|
while ((opt = getopt(argc, argv, "imnpuU")) != \-1) {
|
|
|
|
switch (opt) {
|
|
|
|
case \(aqi\(aq: flags |= CLONE_NEWIPC; break;
|
|
|
|
case \(aqm\(aq: flags |= CLONE_NEWNS; break;
|
|
|
|
case \(aqn\(aq: flags |= CLONE_NEWNET; break;
|
|
|
|
case \(aqp\(aq: flags |= CLONE_NEWPID; break;
|
|
|
|
case \(aqu\(aq: flags |= CLONE_NEWUTS; break;
|
|
|
|
case \(aqU\(aq: flags |= CLONE_NEWUSER; break;
|
|
|
|
default: usage(argv[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind >= argc)
|
|
|
|
usage(argv[0]);
|
|
|
|
|
|
|
|
if (unshare(flags) == \-1)
|
|
|
|
errExit("unshare");
|
|
|
|
|
2014-09-21 09:24:24 +00:00
|
|
|
execvp(argv[optind], &argv[optind]);
|
2013-01-10 20:20:05 +00:00
|
|
|
errExit("execvp");
|
|
|
|
}
|
|
|
|
.fi
|
2006-03-20 21:29:29 +00:00
|
|
|
.SH SEE ALSO
|
2013-01-10 20:08:27 +00:00
|
|
|
.BR unshare (1),
|
2007-04-12 22:42:49 +00:00
|
|
|
.BR clone (2),
|
|
|
|
.BR fork (2),
|
2012-12-18 17:24:25 +00:00
|
|
|
.BR kcmp (2),
|
2013-01-01 00:08:39 +00:00
|
|
|
.BR setns (2),
|
2013-01-10 20:20:54 +00:00
|
|
|
.BR vfork (2),
|
2013-01-13 23:18:46 +00:00
|
|
|
.BR namespaces (7)
|
arch_prctl.2, fcntl.2, flock.2, get_robust_list.2, getpriority.2, ioprio_set.2, migrate_pages.2, mmap.2, mremap.2, msync.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, select.2, socket.2, subpage_prot.2, unshare.2, btree.3, dbopen.3, dl_iterate_phdr.3, dlopen.3, getnameinfo.3, hash.3, lockf.3, netlink.3, recno.3, rpc.3, xdr.3, cciss.4, console_ioctl.4, hpsa.4, initrd.4, msr.4, rtc.4, st.4, hosts.5, services.5, tzfile.5, aio.7, arp.7, capabilities.7, cpuset.7, feature_test_macros.7, futex.7, inotify.7, ip.7, ipv6.7, iso_8859-16.7, iso_8859-2.7, koi8-r.7, math_error.7, netlink.7, packet.7, pthreads.7, raw.7, spufs.7, udplite.7, uri.7, x25.7: Global fix: Various consistency fixes for SEE ALSO
Coauthored-by: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2012-09-24 07:53:22 +00:00
|
|
|
|
|
|
|
.I Documentation/unshare.txt
|
|
|
|
in the Linux kernel source tree
|