All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] enter: new command (light wrapper around setns)
@ 2013-01-11 10:29 Eric W. Biederman
  2013-01-11 10:54 ` Michael Kerrisk (man-pages)
  2013-01-11 16:13 ` Karel Zak
  0 siblings, 2 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-11 10:29 UTC (permalink / raw)
  To: util-linux
  Cc: Neil Horman, Karel Zak, Serge E. Hallyn, Michael Kerrisk (man-pages)


Inspired by unshare, enter is a simple wrapper around setns that
allows running a new process in the context of an existing process.

Full paths may be specified to the namespace arguments so that
namespace file descriptors may be used wherever they reside in the
filesystem.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---

While doing a final check on this patch I just realized I am a week or
two late to the discussion.  So much for waiting until my code had
merged into the kernel before submitting patches.  I have been
developing enter off and on as I have been developing these patches
and it seems to be stable and feature complete at this point.

I really don't like the the idea of adding setns support into unshare.
Creating new namespaces and using existing namespaces are related
but different concepts and place different demands on the evolotion
of the code.  Especially when the pid and user namespaces come into
play.

Little things like retaining the the ability for unshare to be suid root
safely and sanely become intractable if you call setns() and join a
user namespace.  

Supporting the ability for the command to be setuid root does not
work in combination with the user namespace.  As after entering
the user namespace you can not reliably change your uid back to
your uid without setuid as your uid may not be mapped.

When joining an existing mount namespace you most likely want to change
your root directory and your working directory to the directory of the
process whoose mount namespace you are entering.  Something you don't
even think about when just unsharing a mount namespace.

Then there is the practical wish to call fork after entering a pid
namespace and before launching a command.  You don't always want that
but almost always so that the command will actually be run in the new
pid namespace with a new pid, instead of having it's children in the new
pid namespace.

I really can't see support for using setns being in the same binary as
unshare that just mixes two different but closely related things that
will want to evolve in different directions.

My inclination is to send a follow up patch to remove setns and migrate
from unshare.  And a second patch to add pid and user namespace support
to unshare.  But since I am going against the way that seems to have
already been decided I will hold off on those patches until after we
there is agreement on this one.

Eric

 configure.ac            |   11 ++
 sys-utils/Makemodule.am |    7 +
 sys-utils/enter.1       |  101 +++++++++++++++++
 sys-utils/enter.c       |  286 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 405 insertions(+), 0 deletions(-)
 create mode 100644 sys-utils/enter.1
 create mode 100644 sys-utils/enter.c

diff --git a/configure.ac b/configure.ac
index e937736..b0c9c6f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -867,6 +867,17 @@ if test "x$build_unshare" = xyes; then
   AC_CHECK_FUNCS([unshare])
 fi
 
+AC_ARG_ENABLE([enter],
+  AS_HELP_STRING([--disable-enter], [do not build enter]),
+  [], enable_enter=check
+)
+UL_BUILD_INIT([enter])
+UL_REQUIRES_LINUX([enter])
+UL_REQUIRES_SYSCALL_CHECK([setns], [UL_CHECK_SYSCALL([setns])])
+AM_CONDITIONAL(BUILD_ENTER, test "x$build_enter" = xyes)
+if test "x$build_enter" = xyes; then
+  AC_CHECK_FUNCS([setns])
+fi
 
 AC_ARG_ENABLE([arch],
   AS_HELP_STRING([--enable-arch], [do build arch]),
diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
index 5636f70..6ad09b2 100644
--- a/sys-utils/Makemodule.am
+++ b/sys-utils/Makemodule.am
@@ -290,6 +290,13 @@ unshare_SOURCES = sys-utils/unshare.c
 unshare_LDADD = $(LDADD) libcommon.la
 endif
 
+if BUILD_UNSHARE
+usrbin_exec_PROGRAMS += enter
+dist_man_MANS += sys-utils/enter.1
+enter_SOURCES = sys-utils/enter.c
+enter_LDADD = $(LDADD) libcommon.la
+endif
+
 if BUILD_ARCH
 bin_PROGRAMS += arch
 dist_man_MANS += sys-utils/arch.1
diff --git a/sys-utils/enter.1 b/sys-utils/enter.1
new file mode 100644
index 0000000..0829ee2
--- /dev/null
+++ b/sys-utils/enter.1
@@ -0,0 +1,101 @@
+.TH ENTER 1 "January 2013" "util-linux" "User Commands"
+.SH NAME
+enter \- run program with namespaces of other processes
+.SH SYNOPSIS
+.B enter
+.RI [ options ]
+program
+.RI [ arguments ]
+.SH DESCRIPTION
+Enters the contexts of one or more other processes and then executes specified
+program. Enterable namespaces are:
+.TP
+.BR "mount namespace"
+mounting and unmounting filesystems will not affect rest of the system
+(\fBCLONE_NEWNS\fP flag), except for filesystems which are explicitly marked as
+shared (by mount --make-shared). See /proc/self/mountinfo for the shared flags.
+.TP
+.BR "UTS namespace"
+setting hostname, domainname will not affect rest of the system
+(\fBCLONE_NEWUTS\fP flag).
+.TP
+.BR "IPC namespace"
+process will have independent namespace for System V message queues, semaphore
+sets and shared memory segments (\fBCLONE_NEWIPC\fP flag).
+.TP
+.BR "network namespace"
+process will have independent IPv4 and IPv6 stacks, IP routing tables, firewall
+rules, the \fI/proc/net\fP and \fI/sys/class/net\fP directory trees, sockets
+etc. (\fBCLONE_NEWNET\fP flag).
+.TP
+.BR "pid namespace"
+children will have a distinct set of pid to process mappings thantheir parent.
+(\fBCLONE_NEWPID\fP flag).
+.TP
+.BR "user namespace"
+process will have distinct set of uids, gids and capabilities. (\fBCLONE_NEWUSER\fP flag).
+.TP
+See the \fBclone\fR(2) for exact semantics of the flags.
+.SH OPTIONS
+.TP
+.BR \-h , " \-\-help"
+Print a help message,
+.TP
+.BR \-t , " \-\-target " \fIpid\fP
+Specify a target process to get contexts from.
+.TP
+.BR \-m , " \-\-mount"=[\fIfile\fP]
+Enter the mount namespace.
+If no file is specified enter the mount namespace of the target process.
+If file is specified enter the mount namespace specified by file.
+.TP
+.BR \-u , " \-\-uts"=[\fIfile\fP]
+Enter the uts namespace.
+If no file is specified enter the uts namespace of the target process.
+If file is specified enter the uts namespace specified by file.
+.TP
+.BR \-i , " \-\-ipc "=[\fIfile\fP]
+Enter the IPC namespace.
+If no file is specified enter the IPC namespace of the target process.
+If file is specified enter the uts namespace specified by file.
+.TP
+.BR \-n , " \-\-net"=[\fIfile\fP]
+Enter the network namespace.
+If no file is specified enter the network namespace of the target process.
+If file is specified enter the network namespace specified by file.
+.TP
+.BR \-p , " \-\-pid"=[\fIfile\fP]
+Enter the pid namespace.
+If no file is specified enter the pid namespace of the target process.
+If file is specified enter the pid namespace specified by file.
+.TP
+.BR \-U , " \-\-user"=[\fIfile\fP]
+Enter the user namespace.
+If no file is specified enter the user namespace of the target process.
+If file is specified enter the user namespace specified by file.
+.TP
+.BR \-r , " \-\-root"=[\fIdirectory\fP]
+Set the root directory.  
+If no directory is specified set the root directory to the root directory of the target process.
+If directory is specified set the root directory to the specified directory.
+.TP
+.BR \-w , " \-\-wd"=[\fIdirectory\fP]
+Set the working directory.
+If no directory is specified set the working directory to the working directory of the target process.
+If directory is specified set the working directory to the specified directory.
+.TP
+.BR \-e , " \-\-exec"
+Don't fork before exec'ing the specified program.  By default when entering
+a pid namespace enter calls fork before calling exec so that the children will
+be in the newly entered pid namespace.
+.SH NOTES
+.SH SEE ALSO
+.BR setns (2),
+.BR clone (2)
+.SH BUGS
+None known so far.
+.SH AUTHOR
+Eric Biederman <ebiederm@xmission.com>
+.SH AVAILABILITY
+The enter command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/sys-utils/enter.c b/sys-utils/enter.c
new file mode 100644
index 0000000..d7bd540
--- /dev/null
+++ b/sys-utils/enter.c
@@ -0,0 +1,286 @@
+/*
+ * enter(1) - command-line interface for setns(2)
+ *
+ * Copyright (C) 2012-2013 Eric Biederman <ebiederm@xmission.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <dirent.h>
+#include <errno.h>
+#include <getopt.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "nls.h"
+#include "c.h"
+#include "closestream.h"
+
+#ifndef CLONE_NEWSNS
+# define CLONE_NEWNS 0x00020000
+#endif
+#ifndef CLONE_NEWUTS
+# define CLONE_NEWUTS 0x04000000
+#endif
+#ifndef CLONE_NEWIPC
+# define CLONE_NEWIPC 0x08000000
+#endif
+#ifndef CLONE_NEWNET
+# define CLONE_NEWNET 0x40000000
+#endif
+#ifndef CLONE_NEWUSER
+# define CLONE_NEWUSER 0x10000000
+#endif
+#ifndef CLONE_NEWPID
+# define CLONE_NEWPID 0x20000000
+#endif
+
+#ifndef HAVE_SETNS
+# include <sys/syscall.h>
+static int setns(int fd, int nstype)
+{
+	return syscall(SYS_setns, fd, nstype);
+}
+#endif /* HAVE_SETNS */
+
+static struct namespace_file{
+	int nstype;
+	char *name;
+	int fd;
+} namespace_files[] = {
+	/* Careful the order is signifcant in this array.
+	 *
+	 * The user namespace comes first, so that it is entered
+	 * first.  This gives an unprivileged user the potential to
+	 * enter the other namespaces.
+	 */
+	{ .nstype = CLONE_NEWUSER, .name = "ns/user", .fd = -1 },
+	{ .nstype = CLONE_NEWIPC,  .name = "ns/ipc",  .fd = -1 },
+	{ .nstype = CLONE_NEWUTS,  .name = "ns/uts",  .fd = -1 },
+	{ .nstype = CLONE_NEWNET,  .name = "ns/net",  .fd = -1 },
+	{ .nstype = CLONE_NEWPID,  .name = "ns/pid",  .fd = -1 },
+	{ .nstype = CLONE_NEWNS,   .name = "ns/mnt",  .fd = -1 },
+	{}
+};
+
+static void usage(int status)
+{
+	FILE *out = status == EXIT_SUCCESS ? stdout : stderr;
+
+	fputs(USAGE_HEADER, out);
+	fprintf(out, _(" %s [options] <program> [args...]\n"),
+		program_invocation_short_name);
+
+	fputs(USAGE_OPTIONS, out);
+	fputs(_(" -t, --target <pid>   target process to get namespaces from\n"
+		" -m, --mount [<file>] enter mount namespace\n"
+		" -u, --uts   [<file>] enter UTS namespace (hostname etc)\n"
+		" -i, --ipc   [<file>] enter System V IPC namespace\n"
+		" -n, --net   [<file>] enter network namespace\n"
+		" -p, --pid   [<file>] enter pid namespace\n"
+		" -U, --user  [<file>] enter user namespace\n"
+		" -e, --exec           don't fork before exec'ing <program>\n"
+		" -r, --root  [<dir>]  set the root directory\n"
+		" -w, --wd    [<dir>]  set the working directory\n"), out);
+	fputs(USAGE_SEPARATOR, out);
+	fputs(USAGE_HELP, out);
+	fputs(USAGE_VERSION, out);
+	fprintf(out, USAGE_MAN_TAIL("enter(1)"));
+
+	exit(status);
+}
+
+static pid_t namespace_target_pid = 0;
+static int root_fd = -1;
+static int wd_fd = -1;
+
+static void open_target_fd(int *fd, const char *type, char *path)
+{
+	char pathbuf[PATH_MAX];
+
+	if (!path && namespace_target_pid) {
+		snprintf(pathbuf, sizeof(pathbuf), "/proc/%u/%s",
+			namespace_target_pid, type);
+		path = pathbuf;
+	}
+	if (!path)
+		err(EXIT_FAILURE, _("No filename and no target pid supplied for %s"),
+		    type);
+
+	if (*fd >= 0)
+		close(*fd);
+
+	*fd = open(path, O_RDONLY);
+	if (*fd < 0)
+		err(EXIT_FAILURE, _("open of '%s' failed"), path);
+}
+
+static void open_namespace_fd(int nstype, char *path)
+{
+	struct namespace_file *nsfile;
+
+	for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
+		if (nstype != nsfile->nstype)
+			continue;
+
+		open_target_fd(&nsfile->fd, nsfile->name, path);
+		return;
+	}
+	/* This should never happen */
+	err(EXIT_FAILURE, "Unrecognized namespace type");
+}
+
+int main(int argc, char *argv[])
+{
+	static const struct option longopts[] = {
+		{ "help", no_argument, NULL, 'h' },
+		{ "version", no_argument, NULL, 'V'},
+		{ "target", required_argument, NULL, 't' },
+		{ "mount", optional_argument, NULL, 'm' },
+		{ "uts", optional_argument, NULL, 'u' },
+		{ "ipc", optional_argument, NULL, 'i' },
+		{ "net", optional_argument, NULL, 'n' },
+		{ "pid", optional_argument, NULL, 'p' },
+		{ "user", optional_argument, NULL, 'U' },
+		{ "exec", no_argument, NULL, 'e' },
+		{ "root", optional_argument, NULL, 'r' },
+		{ "wd", optional_argument, NULL, 'w' },
+		{ NULL, 0, NULL, 0 }
+	};
+
+	struct namespace_file *nsfile;
+	int do_fork = 0;
+	char *end;
+	int c;
+
+	setlocale(LC_MESSAGES, "");
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	textdomain(PACKAGE);
+	atexit(close_stdout);
+
+	while((c = getopt_long(argc, argv, "hVt:m::u::i::n::p::U::er::w::", longopts, NULL)) != -1) {
+		switch(c) {
+		case 'h':
+			usage(EXIT_SUCCESS);
+		case 'V':
+			printf(UTIL_LINUX_VERSION);
+			return EXIT_SUCCESS;
+		case 't':
+			errno = 0;
+			namespace_target_pid = strtoul(optarg, &end, 10);
+			if (!*optarg || (*optarg && *end) || errno != 0) {
+				err(EXIT_FAILURE,
+				    _("Pid '%s' is not a valid number"),
+				    optarg);
+			}
+			break;
+		case 'm':
+			open_namespace_fd(CLONE_NEWNS, optarg);
+			break;
+		case 'u':
+			open_namespace_fd(CLONE_NEWUTS, optarg);
+			break;
+		case 'i':
+			open_namespace_fd(CLONE_NEWIPC, optarg);
+			break;
+		case 'n':
+			open_namespace_fd(CLONE_NEWNET, optarg);
+			break;
+		case 'p':
+			do_fork = 1;
+			open_namespace_fd(CLONE_NEWPID, optarg);
+			break;
+		case 'U':
+			open_namespace_fd(CLONE_NEWUSER, optarg);
+			break;
+		case 'e':
+			do_fork = 0;
+			break;
+		case 'r':
+			open_target_fd(&root_fd, "root", optarg);
+			break;
+		case 'w':
+			open_target_fd(&wd_fd, "cwd", optarg);
+			break;
+		default:
+			usage(EXIT_FAILURE);
+		}
+	}
+
+	if(optind >= argc)
+		usage(EXIT_FAILURE);
+
+	/*
+	 * Now that we know which namespaces we want to enter, enter them.
+	 */
+	for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
+		if (nsfile->fd < 0)
+			continue;
+		if (setns(nsfile->fd, nsfile->nstype))
+			err(EXIT_FAILURE, _("setns of '%s' failed"),
+			    nsfile->name);
+		close(nsfile->fd);
+		nsfile->fd = -1;
+	}
+
+	/* Remember the current working directory if I'm not changing it */
+	if (root_fd >= 0 && wd_fd < 0) {
+		wd_fd = open(".", O_RDONLY);
+		if (wd_fd < 0)
+			err(EXIT_FAILURE, _("open of . failed"));
+	}
+
+	/* Change the root directory */
+	if (root_fd >= 0) {
+		if (fchdir(root_fd) < 0)
+			err(EXIT_FAILURE, _("fchdir to root_fd failed"));
+
+		if (chroot(".") < 0)
+			err(EXIT_FAILURE, _("chroot failed"));
+
+		close(root_fd);
+		root_fd = -1;
+	}
+		
+	/* Change the working directory */
+	if (wd_fd >= 0) {
+		if (fchdir(wd_fd) < 0)
+			err(EXIT_FAILURE, _("fchdir to wd_fd failed"));
+
+		close(wd_fd);
+		wd_fd = -1;
+	}
+
+	if (do_fork) {
+		pid_t child = fork();
+		if (child < 0)
+			err(EXIT_FAILURE, _("fork failed"));
+		if (child != 0) {
+			int status;
+			if ((waitpid(child, &status, 0) == child) &&
+			     WIFEXITED(status)) {
+				exit(WEXITSTATUS(status));
+			}
+			exit(EXIT_FAILURE);
+		}
+	}
+
+	execvp(argv[optind], argv + optind);
+
+	err(EXIT_FAILURE, _("exec %s failed"), argv[optind]);
+}
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH] enter: new command (light wrapper around setns)
  2013-01-11 10:29 [PATCH] enter: new command (light wrapper around setns) Eric W. Biederman
@ 2013-01-11 10:54 ` Michael Kerrisk (man-pages)
  2013-01-11 11:10   ` Eric W. Biederman
  2013-01-11 16:13 ` Karel Zak
  1 sibling, 1 reply; 24+ messages in thread
From: Michael Kerrisk (man-pages) @ 2013-01-11 10:54 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: util-linux, Neil Horman, Karel Zak, Serge E. Hallyn

Hi Eric,

On Fri, Jan 11, 2013 at 11:29 AM, Eric W. Biederman
<ebiederm@xmission.com> wrote:
>
> Inspired by unshare, enter is a simple wrapper around setns that
> allows running a new process in the context of an existing process.

The name "enter" seems way too generic (far more so than even
"unshare"). How about "nsexec" or "execns" or some such?

Aside from that, what is the purpose of the -f "fork" option?

Thanks,

Michael



> Full paths may be specified to the namespace arguments so that
> namespace file descriptors may be used wherever they reside in the
> filesystem.
>
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
> ---
>
> While doing a final check on this patch I just realized I am a week or
> two late to the discussion.  So much for waiting until my code had
> merged into the kernel before submitting patches.  I have been
> developing enter off and on as I have been developing these patches
> and it seems to be stable and feature complete at this point.
>
> I really don't like the the idea of adding setns support into unshare.
> Creating new namespaces and using existing namespaces are related
> but different concepts and place different demands on the evolotion
> of the code.  Especially when the pid and user namespaces come into
> play.
>
> Little things like retaining the the ability for unshare to be suid root
> safely and sanely become intractable if you call setns() and join a
> user namespace.
>
> Supporting the ability for the command to be setuid root does not
> work in combination with the user namespace.  As after entering
> the user namespace you can not reliably change your uid back to
> your uid without setuid as your uid may not be mapped.
>
> When joining an existing mount namespace you most likely want to change
> your root directory and your working directory to the directory of the
> process whoose mount namespace you are entering.  Something you don't
> even think about when just unsharing a mount namespace.
>
> Then there is the practical wish to call fork after entering a pid
> namespace and before launching a command.  You don't always want that
> but almost always so that the command will actually be run in the new
> pid namespace with a new pid, instead of having it's children in the new
> pid namespace.
>
> I really can't see support for using setns being in the same binary as
> unshare that just mixes two different but closely related things that
> will want to evolve in different directions.
>
> My inclination is to send a follow up patch to remove setns and migrate
> from unshare.  And a second patch to add pid and user namespace support
> to unshare.  But since I am going against the way that seems to have
> already been decided I will hold off on those patches until after we
> there is agreement on this one.
>
> Eric
>
>  configure.ac            |   11 ++
>  sys-utils/Makemodule.am |    7 +
>  sys-utils/enter.1       |  101 +++++++++++++++++
>  sys-utils/enter.c       |  286 +++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 405 insertions(+), 0 deletions(-)
>  create mode 100644 sys-utils/enter.1
>  create mode 100644 sys-utils/enter.c
>
> diff --git a/configure.ac b/configure.ac
> index e937736..b0c9c6f 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -867,6 +867,17 @@ if test "x$build_unshare" = xyes; then
>    AC_CHECK_FUNCS([unshare])
>  fi
>
> +AC_ARG_ENABLE([enter],
> +  AS_HELP_STRING([--disable-enter], [do not build enter]),
> +  [], enable_enter=check
> +)
> +UL_BUILD_INIT([enter])
> +UL_REQUIRES_LINUX([enter])
> +UL_REQUIRES_SYSCALL_CHECK([setns], [UL_CHECK_SYSCALL([setns])])
> +AM_CONDITIONAL(BUILD_ENTER, test "x$build_enter" = xyes)
> +if test "x$build_enter" = xyes; then
> +  AC_CHECK_FUNCS([setns])
> +fi
>
>  AC_ARG_ENABLE([arch],
>    AS_HELP_STRING([--enable-arch], [do build arch]),
> diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
> index 5636f70..6ad09b2 100644
> --- a/sys-utils/Makemodule.am
> +++ b/sys-utils/Makemodule.am
> @@ -290,6 +290,13 @@ unshare_SOURCES = sys-utils/unshare.c
>  unshare_LDADD = $(LDADD) libcommon.la
>  endif
>
> +if BUILD_UNSHARE
> +usrbin_exec_PROGRAMS += enter
> +dist_man_MANS += sys-utils/enter.1
> +enter_SOURCES = sys-utils/enter.c
> +enter_LDADD = $(LDADD) libcommon.la
> +endif
> +
>  if BUILD_ARCH
>  bin_PROGRAMS += arch
>  dist_man_MANS += sys-utils/arch.1
> diff --git a/sys-utils/enter.1 b/sys-utils/enter.1
> new file mode 100644
> index 0000000..0829ee2
> --- /dev/null
> +++ b/sys-utils/enter.1
> @@ -0,0 +1,101 @@
> +.TH ENTER 1 "January 2013" "util-linux" "User Commands"
> +.SH NAME
> +enter \- run program with namespaces of other processes
> +.SH SYNOPSIS
> +.B enter
> +.RI [ options ]
> +program
> +.RI [ arguments ]
> +.SH DESCRIPTION
> +Enters the contexts of one or more other processes and then executes specified
> +program. Enterable namespaces are:
> +.TP
> +.BR "mount namespace"
> +mounting and unmounting filesystems will not affect rest of the system
> +(\fBCLONE_NEWNS\fP flag), except for filesystems which are explicitly marked as
> +shared (by mount --make-shared). See /proc/self/mountinfo for the shared flags.
> +.TP
> +.BR "UTS namespace"
> +setting hostname, domainname will not affect rest of the system
> +(\fBCLONE_NEWUTS\fP flag).
> +.TP
> +.BR "IPC namespace"
> +process will have independent namespace for System V message queues, semaphore
> +sets and shared memory segments (\fBCLONE_NEWIPC\fP flag).
> +.TP
> +.BR "network namespace"
> +process will have independent IPv4 and IPv6 stacks, IP routing tables, firewall
> +rules, the \fI/proc/net\fP and \fI/sys/class/net\fP directory trees, sockets
> +etc. (\fBCLONE_NEWNET\fP flag).
> +.TP
> +.BR "pid namespace"
> +children will have a distinct set of pid to process mappings thantheir parent.
> +(\fBCLONE_NEWPID\fP flag).
> +.TP
> +.BR "user namespace"
> +process will have distinct set of uids, gids and capabilities. (\fBCLONE_NEWUSER\fP flag).
> +.TP
> +See the \fBclone\fR(2) for exact semantics of the flags.
> +.SH OPTIONS
> +.TP
> +.BR \-h , " \-\-help"
> +Print a help message,
> +.TP
> +.BR \-t , " \-\-target " \fIpid\fP
> +Specify a target process to get contexts from.
> +.TP
> +.BR \-m , " \-\-mount"=[\fIfile\fP]
> +Enter the mount namespace.
> +If no file is specified enter the mount namespace of the target process.
> +If file is specified enter the mount namespace specified by file.
> +.TP
> +.BR \-u , " \-\-uts"=[\fIfile\fP]
> +Enter the uts namespace.
> +If no file is specified enter the uts namespace of the target process.
> +If file is specified enter the uts namespace specified by file.
> +.TP
> +.BR \-i , " \-\-ipc "=[\fIfile\fP]
> +Enter the IPC namespace.
> +If no file is specified enter the IPC namespace of the target process.
> +If file is specified enter the uts namespace specified by file.
> +.TP
> +.BR \-n , " \-\-net"=[\fIfile\fP]
> +Enter the network namespace.
> +If no file is specified enter the network namespace of the target process.
> +If file is specified enter the network namespace specified by file.
> +.TP
> +.BR \-p , " \-\-pid"=[\fIfile\fP]
> +Enter the pid namespace.
> +If no file is specified enter the pid namespace of the target process.
> +If file is specified enter the pid namespace specified by file.
> +.TP
> +.BR \-U , " \-\-user"=[\fIfile\fP]
> +Enter the user namespace.
> +If no file is specified enter the user namespace of the target process.
> +If file is specified enter the user namespace specified by file.
> +.TP
> +.BR \-r , " \-\-root"=[\fIdirectory\fP]
> +Set the root directory.
> +If no directory is specified set the root directory to the root directory of the target process.
> +If directory is specified set the root directory to the specified directory.
> +.TP
> +.BR \-w , " \-\-wd"=[\fIdirectory\fP]
> +Set the working directory.
> +If no directory is specified set the working directory to the working directory of the target process.
> +If directory is specified set the working directory to the specified directory.
> +.TP
> +.BR \-e , " \-\-exec"
> +Don't fork before exec'ing the specified program.  By default when entering
> +a pid namespace enter calls fork before calling exec so that the children will
> +be in the newly entered pid namespace.
> +.SH NOTES
> +.SH SEE ALSO
> +.BR setns (2),
> +.BR clone (2)
> +.SH BUGS
> +None known so far.
> +.SH AUTHOR
> +Eric Biederman <ebiederm@xmission.com>
> +.SH AVAILABILITY
> +The enter command is part of the util-linux package and is available from
> +ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
> diff --git a/sys-utils/enter.c b/sys-utils/enter.c
> new file mode 100644
> index 0000000..d7bd540
> --- /dev/null
> +++ b/sys-utils/enter.c
> @@ -0,0 +1,286 @@
> +/*
> + * enter(1) - command-line interface for setns(2)
> + *
> + * Copyright (C) 2012-2013 Eric Biederman <ebiederm@xmission.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by the
> + * Free Software Foundation; version 2.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <dirent.h>
> +#include <errno.h>
> +#include <getopt.h>
> +#include <sched.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +#include "nls.h"
> +#include "c.h"
> +#include "closestream.h"
> +
> +#ifndef CLONE_NEWSNS
> +# define CLONE_NEWNS 0x00020000
> +#endif
> +#ifndef CLONE_NEWUTS
> +# define CLONE_NEWUTS 0x04000000
> +#endif
> +#ifndef CLONE_NEWIPC
> +# define CLONE_NEWIPC 0x08000000
> +#endif
> +#ifndef CLONE_NEWNET
> +# define CLONE_NEWNET 0x40000000
> +#endif
> +#ifndef CLONE_NEWUSER
> +# define CLONE_NEWUSER 0x10000000
> +#endif
> +#ifndef CLONE_NEWPID
> +# define CLONE_NEWPID 0x20000000
> +#endif
> +
> +#ifndef HAVE_SETNS
> +# include <sys/syscall.h>
> +static int setns(int fd, int nstype)
> +{
> +       return syscall(SYS_setns, fd, nstype);
> +}
> +#endif /* HAVE_SETNS */
> +
> +static struct namespace_file{
> +       int nstype;
> +       char *name;
> +       int fd;
> +} namespace_files[] = {
> +       /* Careful the order is signifcant in this array.
> +        *
> +        * The user namespace comes first, so that it is entered
> +        * first.  This gives an unprivileged user the potential to
> +        * enter the other namespaces.
> +        */
> +       { .nstype = CLONE_NEWUSER, .name = "ns/user", .fd = -1 },
> +       { .nstype = CLONE_NEWIPC,  .name = "ns/ipc",  .fd = -1 },
> +       { .nstype = CLONE_NEWUTS,  .name = "ns/uts",  .fd = -1 },
> +       { .nstype = CLONE_NEWNET,  .name = "ns/net",  .fd = -1 },
> +       { .nstype = CLONE_NEWPID,  .name = "ns/pid",  .fd = -1 },
> +       { .nstype = CLONE_NEWNS,   .name = "ns/mnt",  .fd = -1 },
> +       {}
> +};
> +
> +static void usage(int status)
> +{
> +       FILE *out = status == EXIT_SUCCESS ? stdout : stderr;
> +
> +       fputs(USAGE_HEADER, out);
> +       fprintf(out, _(" %s [options] <program> [args...]\n"),
> +               program_invocation_short_name);
> +
> +       fputs(USAGE_OPTIONS, out);
> +       fputs(_(" -t, --target <pid>   target process to get namespaces from\n"
> +               " -m, --mount [<file>] enter mount namespace\n"
> +               " -u, --uts   [<file>] enter UTS namespace (hostname etc)\n"
> +               " -i, --ipc   [<file>] enter System V IPC namespace\n"
> +               " -n, --net   [<file>] enter network namespace\n"
> +               " -p, --pid   [<file>] enter pid namespace\n"
> +               " -U, --user  [<file>] enter user namespace\n"
> +               " -e, --exec           don't fork before exec'ing <program>\n"
> +               " -r, --root  [<dir>]  set the root directory\n"
> +               " -w, --wd    [<dir>]  set the working directory\n"), out);
> +       fputs(USAGE_SEPARATOR, out);
> +       fputs(USAGE_HELP, out);
> +       fputs(USAGE_VERSION, out);
> +       fprintf(out, USAGE_MAN_TAIL("enter(1)"));
> +
> +       exit(status);
> +}
> +
> +static pid_t namespace_target_pid = 0;
> +static int root_fd = -1;
> +static int wd_fd = -1;
> +
> +static void open_target_fd(int *fd, const char *type, char *path)
> +{
> +       char pathbuf[PATH_MAX];
> +
> +       if (!path && namespace_target_pid) {
> +               snprintf(pathbuf, sizeof(pathbuf), "/proc/%u/%s",
> +                       namespace_target_pid, type);
> +               path = pathbuf;
> +       }
> +       if (!path)
> +               err(EXIT_FAILURE, _("No filename and no target pid supplied for %s"),
> +                   type);
> +
> +       if (*fd >= 0)
> +               close(*fd);
> +
> +       *fd = open(path, O_RDONLY);
> +       if (*fd < 0)
> +               err(EXIT_FAILURE, _("open of '%s' failed"), path);
> +}
> +
> +static void open_namespace_fd(int nstype, char *path)
> +{
> +       struct namespace_file *nsfile;
> +
> +       for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
> +               if (nstype != nsfile->nstype)
> +                       continue;
> +
> +               open_target_fd(&nsfile->fd, nsfile->name, path);
> +               return;
> +       }
> +       /* This should never happen */
> +       err(EXIT_FAILURE, "Unrecognized namespace type");
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +       static const struct option longopts[] = {
> +               { "help", no_argument, NULL, 'h' },
> +               { "version", no_argument, NULL, 'V'},
> +               { "target", required_argument, NULL, 't' },
> +               { "mount", optional_argument, NULL, 'm' },
> +               { "uts", optional_argument, NULL, 'u' },
> +               { "ipc", optional_argument, NULL, 'i' },
> +               { "net", optional_argument, NULL, 'n' },
> +               { "pid", optional_argument, NULL, 'p' },
> +               { "user", optional_argument, NULL, 'U' },
> +               { "exec", no_argument, NULL, 'e' },
> +               { "root", optional_argument, NULL, 'r' },
> +               { "wd", optional_argument, NULL, 'w' },
> +               { NULL, 0, NULL, 0 }
> +       };
> +
> +       struct namespace_file *nsfile;
> +       int do_fork = 0;
> +       char *end;
> +       int c;
> +
> +       setlocale(LC_MESSAGES, "");
> +       bindtextdomain(PACKAGE, LOCALEDIR);
> +       textdomain(PACKAGE);
> +       atexit(close_stdout);
> +
> +       while((c = getopt_long(argc, argv, "hVt:m::u::i::n::p::U::er::w::", longopts, NULL)) != -1) {
> +               switch(c) {
> +               case 'h':
> +                       usage(EXIT_SUCCESS);
> +               case 'V':
> +                       printf(UTIL_LINUX_VERSION);
> +                       return EXIT_SUCCESS;
> +               case 't':
> +                       errno = 0;
> +                       namespace_target_pid = strtoul(optarg, &end, 10);
> +                       if (!*optarg || (*optarg && *end) || errno != 0) {
> +                               err(EXIT_FAILURE,
> +                                   _("Pid '%s' is not a valid number"),
> +                                   optarg);
> +                       }
> +                       break;
> +               case 'm':
> +                       open_namespace_fd(CLONE_NEWNS, optarg);
> +                       break;
> +               case 'u':
> +                       open_namespace_fd(CLONE_NEWUTS, optarg);
> +                       break;
> +               case 'i':
> +                       open_namespace_fd(CLONE_NEWIPC, optarg);
> +                       break;
> +               case 'n':
> +                       open_namespace_fd(CLONE_NEWNET, optarg);
> +                       break;
> +               case 'p':
> +                       do_fork = 1;
> +                       open_namespace_fd(CLONE_NEWPID, optarg);
> +                       break;
> +               case 'U':
> +                       open_namespace_fd(CLONE_NEWUSER, optarg);
> +                       break;
> +               case 'e':
> +                       do_fork = 0;
> +                       break;
> +               case 'r':
> +                       open_target_fd(&root_fd, "root", optarg);
> +                       break;
> +               case 'w':
> +                       open_target_fd(&wd_fd, "cwd", optarg);
> +                       break;
> +               default:
> +                       usage(EXIT_FAILURE);
> +               }
> +       }
> +
> +       if(optind >= argc)
> +               usage(EXIT_FAILURE);
> +
> +       /*
> +        * Now that we know which namespaces we want to enter, enter them.
> +        */
> +       for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
> +               if (nsfile->fd < 0)
> +                       continue;
> +               if (setns(nsfile->fd, nsfile->nstype))
> +                       err(EXIT_FAILURE, _("setns of '%s' failed"),
> +                           nsfile->name);
> +               close(nsfile->fd);
> +               nsfile->fd = -1;
> +       }
> +
> +       /* Remember the current working directory if I'm not changing it */
> +       if (root_fd >= 0 && wd_fd < 0) {
> +               wd_fd = open(".", O_RDONLY);
> +               if (wd_fd < 0)
> +                       err(EXIT_FAILURE, _("open of . failed"));
> +       }
> +
> +       /* Change the root directory */
> +       if (root_fd >= 0) {
> +               if (fchdir(root_fd) < 0)
> +                       err(EXIT_FAILURE, _("fchdir to root_fd failed"));
> +
> +               if (chroot(".") < 0)
> +                       err(EXIT_FAILURE, _("chroot failed"));
> +
> +               close(root_fd);
> +               root_fd = -1;
> +       }
> +
> +       /* Change the working directory */
> +       if (wd_fd >= 0) {
> +               if (fchdir(wd_fd) < 0)
> +                       err(EXIT_FAILURE, _("fchdir to wd_fd failed"));
> +
> +               close(wd_fd);
> +               wd_fd = -1;
> +       }
> +
> +       if (do_fork) {
> +               pid_t child = fork();
> +               if (child < 0)
> +                       err(EXIT_FAILURE, _("fork failed"));
> +               if (child != 0) {
> +                       int status;
> +                       if ((waitpid(child, &status, 0) == child) &&
> +                            WIFEXITED(status)) {
> +                               exit(WEXITSTATUS(status));
> +                       }
> +                       exit(EXIT_FAILURE);
> +               }
> +       }
> +
> +       execvp(argv[optind], argv + optind);
> +
> +       err(EXIT_FAILURE, _("exec %s failed"), argv[optind]);
> +}
> --
> 1.7.5.4
>



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] enter: new command (light wrapper around setns)
  2013-01-11 10:54 ` Michael Kerrisk (man-pages)
@ 2013-01-11 11:10   ` Eric W. Biederman
  2013-01-11 13:13     ` Ángel González
  2013-01-12  8:59     ` Michael Kerrisk (man-pages)
  0 siblings, 2 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-11 11:10 UTC (permalink / raw)
  To: mtk.manpages; +Cc: util-linux, Neil Horman, Karel Zak, Serge E. Hallyn

"Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes:

> Hi Eric,
>
> On Fri, Jan 11, 2013 at 11:29 AM, Eric W. Biederman
> <ebiederm@xmission.com> wrote:
>>
>> Inspired by unshare, enter is a simple wrapper around setns that
>> allows running a new process in the context of an existing process.
>
> The name "enter" seems way too generic (far more so than even
> "unshare"). How about "nsexec" or "execns" or some such?

Enter unlike exec is the right concept, and the name is free.

> Aside from that, what is the purpose of the -f "fork" option?

To tell when you are tired, and should go to bed.  There is no fork
option ony an exec option.  And the exec option is documented and
explained.


> Thanks,
>
> Michael
>
>
>
>> Full paths may be specified to the namespace arguments so that
>> namespace file descriptors may be used wherever they reside in the
>> filesystem.
>>
>> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
>> ---
>>
>> While doing a final check on this patch I just realized I am a week or
>> two late to the discussion.  So much for waiting until my code had
>> merged into the kernel before submitting patches.  I have been
>> developing enter off and on as I have been developing these patches
>> and it seems to be stable and feature complete at this point.
>>
>> I really don't like the the idea of adding setns support into unshare.
>> Creating new namespaces and using existing namespaces are related
>> but different concepts and place different demands on the evolotion
>> of the code.  Especially when the pid and user namespaces come into
>> play.
>>
>> Little things like retaining the the ability for unshare to be suid root
>> safely and sanely become intractable if you call setns() and join a
>> user namespace.
>>
>> Supporting the ability for the command to be setuid root does not
>> work in combination with the user namespace.  As after entering
>> the user namespace you can not reliably change your uid back to
>> your uid without setuid as your uid may not be mapped.
>>
>> When joining an existing mount namespace you most likely want to change
>> your root directory and your working directory to the directory of the
>> process whoose mount namespace you are entering.  Something you don't
>> even think about when just unsharing a mount namespace.
>>
>> Then there is the practical wish to call fork after entering a pid
>> namespace and before launching a command.  You don't always want that
>> but almost always so that the command will actually be run in the new
>> pid namespace with a new pid, instead of having it's children in the new
>> pid namespace.
>>
>> I really can't see support for using setns being in the same binary as
>> unshare that just mixes two different but closely related things that
>> will want to evolve in different directions.
>>
>> My inclination is to send a follow up patch to remove setns and migrate
>> from unshare.  And a second patch to add pid and user namespace support
>> to unshare.  But since I am going against the way that seems to have
>> already been decided I will hold off on those patches until after we
>> there is agreement on this one.
>>
>> Eric
>>
>>  configure.ac            |   11 ++
>>  sys-utils/Makemodule.am |    7 +
>>  sys-utils/enter.1       |  101 +++++++++++++++++
>>  sys-utils/enter.c       |  286 +++++++++++++++++++++++++++++++++++++++++++++++
>>  4 files changed, 405 insertions(+), 0 deletions(-)
>>  create mode 100644 sys-utils/enter.1
>>  create mode 100644 sys-utils/enter.c
>>
>> diff --git a/configure.ac b/configure.ac
>> index e937736..b0c9c6f 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -867,6 +867,17 @@ if test "x$build_unshare" = xyes; then
>>    AC_CHECK_FUNCS([unshare])
>>  fi
>>
>> +AC_ARG_ENABLE([enter],
>> +  AS_HELP_STRING([--disable-enter], [do not build enter]),
>> +  [], enable_enter=check
>> +)
>> +UL_BUILD_INIT([enter])
>> +UL_REQUIRES_LINUX([enter])
>> +UL_REQUIRES_SYSCALL_CHECK([setns], [UL_CHECK_SYSCALL([setns])])
>> +AM_CONDITIONAL(BUILD_ENTER, test "x$build_enter" = xyes)
>> +if test "x$build_enter" = xyes; then
>> +  AC_CHECK_FUNCS([setns])
>> +fi
>>
>>  AC_ARG_ENABLE([arch],
>>    AS_HELP_STRING([--enable-arch], [do build arch]),
>> diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
>> index 5636f70..6ad09b2 100644
>> --- a/sys-utils/Makemodule.am
>> +++ b/sys-utils/Makemodule.am
>> @@ -290,6 +290,13 @@ unshare_SOURCES = sys-utils/unshare.c
>>  unshare_LDADD = $(LDADD) libcommon.la
>>  endif
>>
>> +if BUILD_UNSHARE
>> +usrbin_exec_PROGRAMS += enter
>> +dist_man_MANS += sys-utils/enter.1
>> +enter_SOURCES = sys-utils/enter.c
>> +enter_LDADD = $(LDADD) libcommon.la
>> +endif
>> +
>>  if BUILD_ARCH
>>  bin_PROGRAMS += arch
>>  dist_man_MANS += sys-utils/arch.1
>> diff --git a/sys-utils/enter.1 b/sys-utils/enter.1
>> new file mode 100644
>> index 0000000..0829ee2
>> --- /dev/null
>> +++ b/sys-utils/enter.1
>> @@ -0,0 +1,101 @@
>> +.TH ENTER 1 "January 2013" "util-linux" "User Commands"
>> +.SH NAME
>> +enter \- run program with namespaces of other processes
>> +.SH SYNOPSIS
>> +.B enter
>> +.RI [ options ]
>> +program
>> +.RI [ arguments ]
>> +.SH DESCRIPTION
>> +Enters the contexts of one or more other processes and then executes specified
>> +program. Enterable namespaces are:
>> +.TP
>> +.BR "mount namespace"
>> +mounting and unmounting filesystems will not affect rest of the system
>> +(\fBCLONE_NEWNS\fP flag), except for filesystems which are explicitly marked as
>> +shared (by mount --make-shared). See /proc/self/mountinfo for the shared flags.
>> +.TP
>> +.BR "UTS namespace"
>> +setting hostname, domainname will not affect rest of the system
>> +(\fBCLONE_NEWUTS\fP flag).
>> +.TP
>> +.BR "IPC namespace"
>> +process will have independent namespace for System V message queues, semaphore
>> +sets and shared memory segments (\fBCLONE_NEWIPC\fP flag).
>> +.TP
>> +.BR "network namespace"
>> +process will have independent IPv4 and IPv6 stacks, IP routing tables, firewall
>> +rules, the \fI/proc/net\fP and \fI/sys/class/net\fP directory trees, sockets
>> +etc. (\fBCLONE_NEWNET\fP flag).
>> +.TP
>> +.BR "pid namespace"
>> +children will have a distinct set of pid to process mappings thantheir parent.
>> +(\fBCLONE_NEWPID\fP flag).
>> +.TP
>> +.BR "user namespace"
>> +process will have distinct set of uids, gids and capabilities. (\fBCLONE_NEWUSER\fP flag).
>> +.TP
>> +See the \fBclone\fR(2) for exact semantics of the flags.
>> +.SH OPTIONS
>> +.TP
>> +.BR \-h , " \-\-help"
>> +Print a help message,
>> +.TP
>> +.BR \-t , " \-\-target " \fIpid\fP
>> +Specify a target process to get contexts from.
>> +.TP
>> +.BR \-m , " \-\-mount"=[\fIfile\fP]
>> +Enter the mount namespace.
>> +If no file is specified enter the mount namespace of the target process.
>> +If file is specified enter the mount namespace specified by file.
>> +.TP
>> +.BR \-u , " \-\-uts"=[\fIfile\fP]
>> +Enter the uts namespace.
>> +If no file is specified enter the uts namespace of the target process.
>> +If file is specified enter the uts namespace specified by file.
>> +.TP
>> +.BR \-i , " \-\-ipc "=[\fIfile\fP]
>> +Enter the IPC namespace.
>> +If no file is specified enter the IPC namespace of the target process.
>> +If file is specified enter the uts namespace specified by file.
>> +.TP
>> +.BR \-n , " \-\-net"=[\fIfile\fP]
>> +Enter the network namespace.
>> +If no file is specified enter the network namespace of the target process.
>> +If file is specified enter the network namespace specified by file.
>> +.TP
>> +.BR \-p , " \-\-pid"=[\fIfile\fP]
>> +Enter the pid namespace.
>> +If no file is specified enter the pid namespace of the target process.
>> +If file is specified enter the pid namespace specified by file.
>> +.TP
>> +.BR \-U , " \-\-user"=[\fIfile\fP]
>> +Enter the user namespace.
>> +If no file is specified enter the user namespace of the target process.
>> +If file is specified enter the user namespace specified by file.
>> +.TP
>> +.BR \-r , " \-\-root"=[\fIdirectory\fP]
>> +Set the root directory.
>> +If no directory is specified set the root directory to the root directory of the target process.
>> +If directory is specified set the root directory to the specified directory.
>> +.TP
>> +.BR \-w , " \-\-wd"=[\fIdirectory\fP]
>> +Set the working directory.
>> +If no directory is specified set the working directory to the working directory of the target process.
>> +If directory is specified set the working directory to the specified directory.
>> +.TP
>> +.BR \-e , " \-\-exec"
>> +Don't fork before exec'ing the specified program.  By default when entering
>> +a pid namespace enter calls fork before calling exec so that the children will
>> +be in the newly entered pid namespace.
>> +.SH NOTES
>> +.SH SEE ALSO
>> +.BR setns (2),
>> +.BR clone (2)
>> +.SH BUGS
>> +None known so far.
>> +.SH AUTHOR
>> +Eric Biederman <ebiederm@xmission.com>
>> +.SH AVAILABILITY
>> +The enter command is part of the util-linux package and is available from
>> +ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
>> diff --git a/sys-utils/enter.c b/sys-utils/enter.c
>> new file mode 100644
>> index 0000000..d7bd540
>> --- /dev/null
>> +++ b/sys-utils/enter.c
>> @@ -0,0 +1,286 @@
>> +/*
>> + * enter(1) - command-line interface for setns(2)
>> + *
>> + * Copyright (C) 2012-2013 Eric Biederman <ebiederm@xmission.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify it
>> + * under the terms of the GNU General Public License as published by the
>> + * Free Software Foundation; version 2.
>> + *
>> + * This program is distributed in the hope that it will be useful, but
>> + * WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License along
>> + * with this program; if not, write to the Free Software Foundation, Inc.,
>> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>> + */
>> +
>> +#include <sys/types.h>
>> +#include <sys/wait.h>
>> +#include <dirent.h>
>> +#include <errno.h>
>> +#include <getopt.h>
>> +#include <sched.h>
>> +#include <stdio.h>
>> +#include <stdlib.h>
>> +#include <unistd.h>
>> +
>> +#include "nls.h"
>> +#include "c.h"
>> +#include "closestream.h"
>> +
>> +#ifndef CLONE_NEWSNS
>> +# define CLONE_NEWNS 0x00020000
>> +#endif
>> +#ifndef CLONE_NEWUTS
>> +# define CLONE_NEWUTS 0x04000000
>> +#endif
>> +#ifndef CLONE_NEWIPC
>> +# define CLONE_NEWIPC 0x08000000
>> +#endif
>> +#ifndef CLONE_NEWNET
>> +# define CLONE_NEWNET 0x40000000
>> +#endif
>> +#ifndef CLONE_NEWUSER
>> +# define CLONE_NEWUSER 0x10000000
>> +#endif
>> +#ifndef CLONE_NEWPID
>> +# define CLONE_NEWPID 0x20000000
>> +#endif
>> +
>> +#ifndef HAVE_SETNS
>> +# include <sys/syscall.h>
>> +static int setns(int fd, int nstype)
>> +{
>> +       return syscall(SYS_setns, fd, nstype);
>> +}
>> +#endif /* HAVE_SETNS */
>> +
>> +static struct namespace_file{
>> +       int nstype;
>> +       char *name;
>> +       int fd;
>> +} namespace_files[] = {
>> +       /* Careful the order is signifcant in this array.
>> +        *
>> +        * The user namespace comes first, so that it is entered
>> +        * first.  This gives an unprivileged user the potential to
>> +        * enter the other namespaces.
>> +        */
>> +       { .nstype = CLONE_NEWUSER, .name = "ns/user", .fd = -1 },
>> +       { .nstype = CLONE_NEWIPC,  .name = "ns/ipc",  .fd = -1 },
>> +       { .nstype = CLONE_NEWUTS,  .name = "ns/uts",  .fd = -1 },
>> +       { .nstype = CLONE_NEWNET,  .name = "ns/net",  .fd = -1 },
>> +       { .nstype = CLONE_NEWPID,  .name = "ns/pid",  .fd = -1 },
>> +       { .nstype = CLONE_NEWNS,   .name = "ns/mnt",  .fd = -1 },
>> +       {}
>> +};
>> +
>> +static void usage(int status)
>> +{
>> +       FILE *out = status == EXIT_SUCCESS ? stdout : stderr;
>> +
>> +       fputs(USAGE_HEADER, out);
>> +       fprintf(out, _(" %s [options] <program> [args...]\n"),
>> +               program_invocation_short_name);
>> +
>> +       fputs(USAGE_OPTIONS, out);
>> +       fputs(_(" -t, --target <pid>   target process to get namespaces from\n"
>> +               " -m, --mount [<file>] enter mount namespace\n"
>> +               " -u, --uts   [<file>] enter UTS namespace (hostname etc)\n"
>> +               " -i, --ipc   [<file>] enter System V IPC namespace\n"
>> +               " -n, --net   [<file>] enter network namespace\n"
>> +               " -p, --pid   [<file>] enter pid namespace\n"
>> +               " -U, --user  [<file>] enter user namespace\n"
>> +               " -e, --exec           don't fork before exec'ing <program>\n"
>> +               " -r, --root  [<dir>]  set the root directory\n"
>> +               " -w, --wd    [<dir>]  set the working directory\n"), out);
>> +       fputs(USAGE_SEPARATOR, out);
>> +       fputs(USAGE_HELP, out);
>> +       fputs(USAGE_VERSION, out);
>> +       fprintf(out, USAGE_MAN_TAIL("enter(1)"));
>> +
>> +       exit(status);
>> +}
>> +
>> +static pid_t namespace_target_pid = 0;
>> +static int root_fd = -1;
>> +static int wd_fd = -1;
>> +
>> +static void open_target_fd(int *fd, const char *type, char *path)
>> +{
>> +       char pathbuf[PATH_MAX];
>> +
>> +       if (!path && namespace_target_pid) {
>> +               snprintf(pathbuf, sizeof(pathbuf), "/proc/%u/%s",
>> +                       namespace_target_pid, type);
>> +               path = pathbuf;
>> +       }
>> +       if (!path)
>> +               err(EXIT_FAILURE, _("No filename and no target pid supplied for %s"),
>> +                   type);
>> +
>> +       if (*fd >= 0)
>> +               close(*fd);
>> +
>> +       *fd = open(path, O_RDONLY);
>> +       if (*fd < 0)
>> +               err(EXIT_FAILURE, _("open of '%s' failed"), path);
>> +}
>> +
>> +static void open_namespace_fd(int nstype, char *path)
>> +{
>> +       struct namespace_file *nsfile;
>> +
>> +       for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
>> +               if (nstype != nsfile->nstype)
>> +                       continue;
>> +
>> +               open_target_fd(&nsfile->fd, nsfile->name, path);
>> +               return;
>> +       }
>> +       /* This should never happen */
>> +       err(EXIT_FAILURE, "Unrecognized namespace type");
>> +}
>> +
>> +int main(int argc, char *argv[])
>> +{
>> +       static const struct option longopts[] = {
>> +               { "help", no_argument, NULL, 'h' },
>> +               { "version", no_argument, NULL, 'V'},
>> +               { "target", required_argument, NULL, 't' },
>> +               { "mount", optional_argument, NULL, 'm' },
>> +               { "uts", optional_argument, NULL, 'u' },
>> +               { "ipc", optional_argument, NULL, 'i' },
>> +               { "net", optional_argument, NULL, 'n' },
>> +               { "pid", optional_argument, NULL, 'p' },
>> +               { "user", optional_argument, NULL, 'U' },
>> +               { "exec", no_argument, NULL, 'e' },
>> +               { "root", optional_argument, NULL, 'r' },
>> +               { "wd", optional_argument, NULL, 'w' },
>> +               { NULL, 0, NULL, 0 }
>> +       };
>> +
>> +       struct namespace_file *nsfile;
>> +       int do_fork = 0;
>> +       char *end;
>> +       int c;
>> +
>> +       setlocale(LC_MESSAGES, "");
>> +       bindtextdomain(PACKAGE, LOCALEDIR);
>> +       textdomain(PACKAGE);
>> +       atexit(close_stdout);
>> +
>> +       while((c = getopt_long(argc, argv, "hVt:m::u::i::n::p::U::er::w::", longopts, NULL)) != -1) {
>> +               switch(c) {
>> +               case 'h':
>> +                       usage(EXIT_SUCCESS);
>> +               case 'V':
>> +                       printf(UTIL_LINUX_VERSION);
>> +                       return EXIT_SUCCESS;
>> +               case 't':
>> +                       errno = 0;
>> +                       namespace_target_pid = strtoul(optarg, &end, 10);
>> +                       if (!*optarg || (*optarg && *end) || errno != 0) {
>> +                               err(EXIT_FAILURE,
>> +                                   _("Pid '%s' is not a valid number"),
>> +                                   optarg);
>> +                       }
>> +                       break;
>> +               case 'm':
>> +                       open_namespace_fd(CLONE_NEWNS, optarg);
>> +                       break;
>> +               case 'u':
>> +                       open_namespace_fd(CLONE_NEWUTS, optarg);
>> +                       break;
>> +               case 'i':
>> +                       open_namespace_fd(CLONE_NEWIPC, optarg);
>> +                       break;
>> +               case 'n':
>> +                       open_namespace_fd(CLONE_NEWNET, optarg);
>> +                       break;
>> +               case 'p':
>> +                       do_fork = 1;
>> +                       open_namespace_fd(CLONE_NEWPID, optarg);
>> +                       break;
>> +               case 'U':
>> +                       open_namespace_fd(CLONE_NEWUSER, optarg);
>> +                       break;
>> +               case 'e':
>> +                       do_fork = 0;
>> +                       break;
>> +               case 'r':
>> +                       open_target_fd(&root_fd, "root", optarg);
>> +                       break;
>> +               case 'w':
>> +                       open_target_fd(&wd_fd, "cwd", optarg);
>> +                       break;
>> +               default:
>> +                       usage(EXIT_FAILURE);
>> +               }
>> +       }
>> +
>> +       if(optind >= argc)
>> +               usage(EXIT_FAILURE);
>> +
>> +       /*
>> +        * Now that we know which namespaces we want to enter, enter them.
>> +        */
>> +       for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
>> +               if (nsfile->fd < 0)
>> +                       continue;
>> +               if (setns(nsfile->fd, nsfile->nstype))
>> +                       err(EXIT_FAILURE, _("setns of '%s' failed"),
>> +                           nsfile->name);
>> +               close(nsfile->fd);
>> +               nsfile->fd = -1;
>> +       }
>> +
>> +       /* Remember the current working directory if I'm not changing it */
>> +       if (root_fd >= 0 && wd_fd < 0) {
>> +               wd_fd = open(".", O_RDONLY);
>> +               if (wd_fd < 0)
>> +                       err(EXIT_FAILURE, _("open of . failed"));
>> +       }
>> +
>> +       /* Change the root directory */
>> +       if (root_fd >= 0) {
>> +               if (fchdir(root_fd) < 0)
>> +                       err(EXIT_FAILURE, _("fchdir to root_fd failed"));
>> +
>> +               if (chroot(".") < 0)
>> +                       err(EXIT_FAILURE, _("chroot failed"));
>> +
>> +               close(root_fd);
>> +               root_fd = -1;
>> +       }
>> +
>> +       /* Change the working directory */
>> +       if (wd_fd >= 0) {
>> +               if (fchdir(wd_fd) < 0)
>> +                       err(EXIT_FAILURE, _("fchdir to wd_fd failed"));
>> +
>> +               close(wd_fd);
>> +               wd_fd = -1;
>> +       }
>> +
>> +       if (do_fork) {
>> +               pid_t child = fork();
>> +               if (child < 0)
>> +                       err(EXIT_FAILURE, _("fork failed"));
>> +               if (child != 0) {
>> +                       int status;
>> +                       if ((waitpid(child, &status, 0) == child) &&
>> +                            WIFEXITED(status)) {
>> +                               exit(WEXITSTATUS(status));
>> +                       }
>> +                       exit(EXIT_FAILURE);
>> +               }
>> +       }
>> +
>> +       execvp(argv[optind], argv + optind);
>> +
>> +       err(EXIT_FAILURE, _("exec %s failed"), argv[optind]);
>> +}
>> --
>> 1.7.5.4
>>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] enter: new command (light wrapper around setns)
  2013-01-11 11:10   ` Eric W. Biederman
@ 2013-01-11 13:13     ` Ángel González
  2013-01-12  8:59     ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 24+ messages in thread
From: Ángel González @ 2013-01-11 13:13 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: mtk.manpages, util-linux, Neil Horman, Karel Zak, Serge E. Hallyn

On 11/01/13 12:10, Eric W. Biederman wrote:
> "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes:
> 
>> Hi Eric,
>>
>> On Fri, Jan 11, 2013 at 11:29 AM, Eric W. Biederman
>> <ebiederm@xmission.com> wrote:
>>>
>>> Inspired by unshare, enter is a simple wrapper around setns that
>>> allows running a new process in the context of an existing process.
>>
>> The name "enter" seems way too generic (far more so than even
>> "unshare"). How about "nsexec" or "execns" or some such?
> 
> Enter unlike exec is the right concept, and the name is free.

What about enterns ?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] enter: new command (light wrapper around setns)
  2013-01-11 10:29 [PATCH] enter: new command (light wrapper around setns) Eric W. Biederman
  2013-01-11 10:54 ` Michael Kerrisk (man-pages)
@ 2013-01-11 16:13 ` Karel Zak
  2013-01-11 22:11   ` Eric W. Biederman
                     ` (2 more replies)
  1 sibling, 3 replies; 24+ messages in thread
From: Karel Zak @ 2013-01-11 16:13 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: util-linux, Neil Horman, Serge E. Hallyn, Michael Kerrisk (man-pages)

On Fri, Jan 11, 2013 at 02:29:24AM -0800, Eric W. Biederman wrote:
> 
> Inspired by unshare, enter is a simple wrapper around setns that
> allows running a new process in the context of an existing process.

 It would be really nice to have "ns" in the name -- for example
 "enterns" sounds good.

> While doing a final check on this patch I just realized I am a week or
> two late to the discussion.

 Yep :-)

> Little things like retaining the the ability for unshare to be suid root
> safely and sanely become intractable if you call setns() and join a
> user namespace.  

 Do you have any example (use case) with suid unshare(1)? 

> Supporting the ability for the command to be setuid root does not
> work in combination with the user namespace.  As after entering
> the user namespace you can not reliably change your uid back to
> your uid without setuid as your uid may not be mapped.
> 
> When joining an existing mount namespace you most likely want to change
> your root directory and your working directory to the directory of the
> process whoose mount namespace you are entering.  Something you don't
> even think about when just unsharing a mount namespace.
> 
> Then there is the practical wish to call fork after entering a pid
> namespace and before launching a command.  You don't always want that
> but almost always so that the command will actually be run in the new
> pid namespace with a new pid, instead of having it's children in the new
> pid namespace.
> 
> I really can't see support for using setns being in the same binary as
> unshare that just mixes two different but closely related things that
> will want to evolve in different directions.
> 
> My inclination is to send a follow up patch to remove setns and migrate
> from unshare. 

 unnecessary, "git revert" works fine :-)

> And a second patch to add pid and user namespace support
> to unshare.  But since I am going against the way that seems to have
> already been decided I will hold off on those patches until after we
> there is agreement on this one.

 well, the decision has been based on little different context. 
 
 I have no problem to revert the change if there is a real use case 
 with suid and if the setns() goals will be incompatible with the 
 way how people use unshare(1) command.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] enter: new command (light wrapper around setns)
  2013-01-11 16:13 ` Karel Zak
@ 2013-01-11 22:11   ` Eric W. Biederman
  2013-01-12  9:01     ` Michael Kerrisk (man-pages)
  2013-01-11 22:46   ` [PATCH] nsenter: " Eric W. Biederman
  2013-01-11 22:53   ` [PATCH] unshare: Add support for the pid and user namespaces Eric W. Biederman
  2 siblings, 1 reply; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-11 22:11 UTC (permalink / raw)
  To: Karel Zak
  Cc: util-linux, Neil Horman, Serge E. Hallyn, Michael Kerrisk (man-pages)

Karel Zak <kzak@redhat.com> writes:

> On Fri, Jan 11, 2013 at 02:29:24AM -0800, Eric W. Biederman wrote:
>> 
>> Inspired by unshare, enter is a simple wrapper around setns that
>> allows running a new process in the context of an existing process.
>
>  It would be really nice to have "ns" in the name -- for example
>  "enterns" sounds good.

enterns might work.  I am still trying to reconcile that name with
changing the working directory and the root directory.  Those really
aren't namespaces.

But name slightly less generic seems to be the popular vote.  Short of
something better my vote is for nsenter.  enterns sounds way too much
like interns which has a rather different meaning.

>> While doing a final check on this patch I just realized I am a week or
>> two late to the discussion.
>
>  Yep :-)
>
>> Little things like retaining the the ability for unshare to be suid root
>> safely and sanely become intractable if you call setns() and join a
>> user namespace.  
>
>  Do you have any example (use case) with suid unshare(1)? 

No.  Mostly I know that someone added support to unshare for being
run suid, and changing the uids and gids back.

I hope my recent changes to the user namespace allowing unshare to
create user namespaces unprivielged and to create other namespaces with
only privilege in the user namespace to be sufficient.

>> Supporting the ability for the command to be setuid root does not
>> work in combination with the user namespace.  As after entering
>> the user namespace you can not reliably change your uid back to
>> your uid without setuid as your uid may not be mapped.
>> 
>> When joining an existing mount namespace you most likely want to change
>> your root directory and your working directory to the directory of the
>> process whoose mount namespace you are entering.  Something you don't
>> even think about when just unsharing a mount namespace.
>> 
>> Then there is the practical wish to call fork after entering a pid
>> namespace and before launching a command.  You don't always want that
>> but almost always so that the command will actually be run in the new
>> pid namespace with a new pid, instead of having it's children in the new
>> pid namespace.
>> 
>> I really can't see support for using setns being in the same binary as
>> unshare that just mixes two different but closely related things that
>> will want to evolve in different directions.
>> 
>> My inclination is to send a follow up patch to remove setns and migrate
>> from unshare. 
>
>  unnecessary, "git revert" works fine :-)
>
>> And a second patch to add pid and user namespace support
>> to unshare.  But since I am going against the way that seems to have
>> already been decided I will hold off on those patches until after we
>> there is agreement on this one.
>
>  well, the decision has been based on little different context. 

Yes.

>  I have no problem to revert the change if there is a real use case 
>  with suid and if the setns() goals will be incompatible with the 
>  way how people use unshare(1) command.

So I don't know about the suid case.  So that might be worth some
discussion.  Looking closer I don't actually think unsharing the user
namespace is compatible with a suid /usr/sbin/unshare.

If suid handling is removed from the discussion I don't see any
fundamental incompatibility between unshare and nsenter.  At the same
time I don't see any shared code between the two pieces of code either.
Nor do I see any ordering requirements that would need unshare and setns
to be called in the same binary.

So in net I really think we will have simpler more robust code by
leaving the two binaries separate.  Especially since unshare and nsenter
are the raw shell utilities you drag out to debug something or to build
things of when you don't need a sophisticated user space wrapper.

Except for debugging I expect most of the usage is going to be something
like:
nsexec -t $(pidof foo) -muinpUrw /bin/bash -e "cmd"

Anyway I will respin my patch with the name changed from enter to
nsenter and see where we can go from there.

Eric


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH] nsenter: new command (light wrapper around setns)
  2013-01-11 16:13 ` Karel Zak
  2013-01-11 22:11   ` Eric W. Biederman
@ 2013-01-11 22:46   ` Eric W. Biederman
  2013-01-11 23:45     ` Mike Frysinger
                       ` (2 more replies)
  2013-01-11 22:53   ` [PATCH] unshare: Add support for the pid and user namespaces Eric W. Biederman
  2 siblings, 3 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-11 22:46 UTC (permalink / raw)
  To: Karel Zak
  Cc: util-linux, Neil Horman, Serge E. Hallyn, Michael Kerrisk (man-pages)


Inspired by unshare, nsenter is a simple wrapper around setns that
allows running a new process in the context of an existing process.

Full paths may be specified to the namespace arguments so that
namespace file descriptors may be used wherever they reside in the
filesystem.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 configure.ac            |   11 ++
 sys-utils/Makemodule.am |    7 +
 sys-utils/nsenter.1     |  101 +++++++++++++++++
 sys-utils/nsenter.c     |  286 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 405 insertions(+), 0 deletions(-)
 create mode 100644 sys-utils/nsenter.1
 create mode 100644 sys-utils/nsenter.c

diff --git a/configure.ac b/configure.ac
index e937736..52deda8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -867,6 +867,17 @@ if test "x$build_unshare" = xyes; then
   AC_CHECK_FUNCS([unshare])
 fi
 
+AC_ARG_ENABLE([nsenter],
+  AS_HELP_STRING([--disable-nsenter], [do not build nsenter]),
+  [], enable_nsenter=check
+)
+UL_BUILD_INIT([nsenter])
+UL_REQUIRES_LINUX([nsenter])
+UL_REQUIRES_SYSCALL_CHECK([setns], [UL_CHECK_SYSCALL([setns])])
+AM_CONDITIONAL(BUILD_NSENTER, test "x$build_nsenter" = xyes)
+if test "x$build_nsenter" = xyes; then
+  AC_CHECK_FUNCS([setns])
+fi
 
 AC_ARG_ENABLE([arch],
   AS_HELP_STRING([--enable-arch], [do build arch]),
diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
index 5636f70..e9396f2 100644
--- a/sys-utils/Makemodule.am
+++ b/sys-utils/Makemodule.am
@@ -290,6 +290,13 @@ unshare_SOURCES = sys-utils/unshare.c
 unshare_LDADD = $(LDADD) libcommon.la
 endif
 
+if BUILD_NSENTER
+usrbin_exec_PROGRAMS += nsenter
+dist_man_MANS += sys-utils/nsenter.1
+nsenter_SOURCES = sys-utils/nsenter.c
+nsenter_LDADD = $(LDADD) libcommon.la
+endif
+
 if BUILD_ARCH
 bin_PROGRAMS += arch
 dist_man_MANS += sys-utils/arch.1
diff --git a/sys-utils/nsenter.1 b/sys-utils/nsenter.1
new file mode 100644
index 0000000..3a837c3
--- /dev/null
+++ b/sys-utils/nsenter.1
@@ -0,0 +1,101 @@
+.TH NSENTER 1 "January 2013" "util-linux" "User Commands"
+.SH NAME
+nsenter \- run program with namespaces of other processes
+.SH SYNOPSIS
+.B nsenter
+.RI [ options ]
+program
+.RI [ arguments ]
+.SH DESCRIPTION
+Enters the contexts of one or more other processes and then executes specified
+program. Enterable namespaces are:
+.TP
+.BR "mount namespace"
+mounting and unmounting filesystems will not affect rest of the system
+(\fBCLONE_NEWNS\fP flag), except for filesystems which are explicitly marked as
+shared (by mount --make-shared). See /proc/self/mountinfo for the shared flags.
+.TP
+.BR "UTS namespace"
+setting hostname, domainname will not affect rest of the system
+(\fBCLONE_NEWUTS\fP flag).
+.TP
+.BR "IPC namespace"
+process will have independent namespace for System V message queues, semaphore
+sets and shared memory segments (\fBCLONE_NEWIPC\fP flag).
+.TP
+.BR "network namespace"
+process will have independent IPv4 and IPv6 stacks, IP routing tables, firewall
+rules, the \fI/proc/net\fP and \fI/sys/class/net\fP directory trees, sockets
+etc. (\fBCLONE_NEWNET\fP flag).
+.TP
+.BR "pid namespace"
+children will have a distinct set of pid to process mappings thantheir parent.
+(\fBCLONE_NEWPID\fP flag).
+.TP
+.BR "user namespace"
+process will have distinct set of uids, gids and capabilities. (\fBCLONE_NEWUSER\fP flag).
+.TP
+See the \fBclone\fR(2) for exact semantics of the flags.
+.SH OPTIONS
+.TP
+.BR \-h , " \-\-help"
+Print a help message,
+.TP
+.BR \-t , " \-\-target " \fIpid\fP
+Specify a target process to get contexts from.  The paths to the contexts specified by pid are: /proc/[pid]/ns/mnt, /proc/[pid]/ns/uts, /proc/[pid]/ns/ipc, /proc/[pid]/ns/net, /proc/[pid]/ns/pid, /proc/[pid]/ns/user, /proc/[pid]/root, /proc/[pid]/cwd for the mount namespace, the uts namespace, the ipc namespace, the net namespace, the pid namespace, the user namespace, the root directory and the working directory respectively.
+.TP
+.BR \-m , " \-\-mount"=[\fIfile\fP]
+Enter the mount namespace.
+If no file is specified enter the mount namespace of the target process.
+If file is specified enter the mount namespace specified by file.
+.TP
+.BR \-u , " \-\-uts"=[\fIfile\fP]
+Enter the uts namespace.
+If no file is specified enter the uts namespace of the target process.
+If file is specified enter the uts namespace specified by file.
+.TP
+.BR \-i , " \-\-ipc "=[\fIfile\fP]
+Enter the IPC namespace.
+If no file is specified enter the IPC namespace of the target process.
+If file is specified enter the uts namespace specified by file.
+.TP
+.BR \-n , " \-\-net"=[\fIfile\fP]
+Enter the network namespace.
+If no file is specified enter the network namespace of the target process.
+If file is specified enter the network namespace specified by file.
+.TP
+.BR \-p , " \-\-pid"=[\fIfile\fP]
+Enter the pid namespace.
+If no file is specified enter the pid namespace of the target process.
+If file is specified enter the pid namespace specified by file.
+.TP
+.BR \-U , " \-\-user"=[\fIfile\fP]
+Enter the user namespace.
+If no file is specified enter the user namespace of the target process.
+If file is specified enter the user namespace specified by file.
+.TP
+.BR \-r , " \-\-root"=[\fIdirectory\fP]
+Set the root directory.  
+If no directory is specified set the root directory to the root directory of the target process.
+If directory is specified set the root directory to the specified directory.
+.TP
+.BR \-w , " \-\-wd"=[\fIdirectory\fP]
+Set the working directory.
+If no directory is specified set the working directory to the working directory of the target process.
+If directory is specified set the working directory to the specified directory.
+.TP
+.BR \-e , " \-\-exec"
+Don't fork before exec'ing the specified program.  By default when entering
+a pid namespace enter calls fork before calling exec so that the children will
+be in the newly entered pid namespace.
+.SH NOTES
+.SH SEE ALSO
+.BR setns (2),
+.BR clone (2)
+.SH BUGS
+None known so far.
+.SH AUTHOR
+Eric Biederman <ebiederm@xmission.com>
+.SH AVAILABILITY
+The nsenter command is part of the util-linux package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c
new file mode 100644
index 0000000..e1f3995
--- /dev/null
+++ b/sys-utils/nsenter.c
@@ -0,0 +1,286 @@
+/*
+ * nsenter(1) - command-line interface for setns(2)
+ *
+ * Copyright (C) 2012-2013 Eric Biederman <ebiederm@xmission.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <dirent.h>
+#include <errno.h>
+#include <getopt.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "nls.h"
+#include "c.h"
+#include "closestream.h"
+
+#ifndef CLONE_NEWSNS
+# define CLONE_NEWNS 0x00020000
+#endif
+#ifndef CLONE_NEWUTS
+# define CLONE_NEWUTS 0x04000000
+#endif
+#ifndef CLONE_NEWIPC
+# define CLONE_NEWIPC 0x08000000
+#endif
+#ifndef CLONE_NEWNET
+# define CLONE_NEWNET 0x40000000
+#endif
+#ifndef CLONE_NEWUSER
+# define CLONE_NEWUSER 0x10000000
+#endif
+#ifndef CLONE_NEWPID
+# define CLONE_NEWPID 0x20000000
+#endif
+
+#ifndef HAVE_SETNS
+# include <sys/syscall.h>
+static int setns(int fd, int nstype)
+{
+	return syscall(SYS_setns, fd, nstype);
+}
+#endif /* HAVE_SETNS */
+
+static struct namespace_file{
+	int nstype;
+	char *name;
+	int fd;
+} namespace_files[] = {
+	/* Careful the order is signifcant in this array.
+	 *
+	 * The user namespace comes first, so that it is entered
+	 * first.  This gives an unprivileged user the potential to
+	 * enter the other namespaces.
+	 */
+	{ .nstype = CLONE_NEWUSER, .name = "ns/user", .fd = -1 },
+	{ .nstype = CLONE_NEWIPC,  .name = "ns/ipc",  .fd = -1 },
+	{ .nstype = CLONE_NEWUTS,  .name = "ns/uts",  .fd = -1 },
+	{ .nstype = CLONE_NEWNET,  .name = "ns/net",  .fd = -1 },
+	{ .nstype = CLONE_NEWPID,  .name = "ns/pid",  .fd = -1 },
+	{ .nstype = CLONE_NEWNS,   .name = "ns/mnt",  .fd = -1 },
+	{}
+};
+
+static void usage(int status)
+{
+	FILE *out = status == EXIT_SUCCESS ? stdout : stderr;
+
+	fputs(USAGE_HEADER, out);
+	fprintf(out, _(" %s [options] <program> [args...]\n"),
+		program_invocation_short_name);
+
+	fputs(USAGE_OPTIONS, out);
+	fputs(_(" -t, --target <pid>   target process to get namespaces from\n"
+		" -m, --mount [<file>] enter mount namespace\n"
+		" -u, --uts   [<file>] enter UTS namespace (hostname etc)\n"
+		" -i, --ipc   [<file>] enter System V IPC namespace\n"
+		" -n, --net   [<file>] enter network namespace\n"
+		" -p, --pid   [<file>] enter pid namespace\n"
+		" -U, --user  [<file>] enter user namespace\n"
+		" -e, --exec           don't fork before exec'ing <program>\n"
+		" -r, --root  [<dir>]  set the root directory\n"
+		" -w, --wd    [<dir>]  set the working directory\n"), out);
+	fputs(USAGE_SEPARATOR, out);
+	fputs(USAGE_HELP, out);
+	fputs(USAGE_VERSION, out);
+	fprintf(out, USAGE_MAN_TAIL("nsenter(1)"));
+
+	exit(status);
+}
+
+static pid_t namespace_target_pid = 0;
+static int root_fd = -1;
+static int wd_fd = -1;
+
+static void open_target_fd(int *fd, const char *type, char *path)
+{
+	char pathbuf[PATH_MAX];
+
+	if (!path && namespace_target_pid) {
+		snprintf(pathbuf, sizeof(pathbuf), "/proc/%u/%s",
+			namespace_target_pid, type);
+		path = pathbuf;
+	}
+	if (!path)
+		err(EXIT_FAILURE, _("No filename and no target pid supplied for %s"),
+		    type);
+
+	if (*fd >= 0)
+		close(*fd);
+
+	*fd = open(path, O_RDONLY);
+	if (*fd < 0)
+		err(EXIT_FAILURE, _("open of '%s' failed"), path);
+}
+
+static void open_namespace_fd(int nstype, char *path)
+{
+	struct namespace_file *nsfile;
+
+	for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
+		if (nstype != nsfile->nstype)
+			continue;
+
+		open_target_fd(&nsfile->fd, nsfile->name, path);
+		return;
+	}
+	/* This should never happen */
+	err(EXIT_FAILURE, "Unrecognized namespace type");
+}
+
+int main(int argc, char *argv[])
+{
+	static const struct option longopts[] = {
+		{ "help", no_argument, NULL, 'h' },
+		{ "version", no_argument, NULL, 'V'},
+		{ "target", required_argument, NULL, 't' },
+		{ "mount", optional_argument, NULL, 'm' },
+		{ "uts", optional_argument, NULL, 'u' },
+		{ "ipc", optional_argument, NULL, 'i' },
+		{ "net", optional_argument, NULL, 'n' },
+		{ "pid", optional_argument, NULL, 'p' },
+		{ "user", optional_argument, NULL, 'U' },
+		{ "exec", no_argument, NULL, 'e' },
+		{ "root", optional_argument, NULL, 'r' },
+		{ "wd", optional_argument, NULL, 'w' },
+		{ NULL, 0, NULL, 0 }
+	};
+
+	struct namespace_file *nsfile;
+	int do_fork = 0;
+	char *end;
+	int c;
+
+	setlocale(LC_MESSAGES, "");
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	textdomain(PACKAGE);
+	atexit(close_stdout);
+
+	while((c = getopt_long(argc, argv, "hVt:m::u::i::n::p::U::er::w::", longopts, NULL)) != -1) {
+		switch(c) {
+		case 'h':
+			usage(EXIT_SUCCESS);
+		case 'V':
+			printf(UTIL_LINUX_VERSION);
+			return EXIT_SUCCESS;
+		case 't':
+			errno = 0;
+			namespace_target_pid = strtoul(optarg, &end, 10);
+			if (!*optarg || (*optarg && *end) || errno != 0) {
+				err(EXIT_FAILURE,
+				    _("Pid '%s' is not a valid number"),
+				    optarg);
+			}
+			break;
+		case 'm':
+			open_namespace_fd(CLONE_NEWNS, optarg);
+			break;
+		case 'u':
+			open_namespace_fd(CLONE_NEWUTS, optarg);
+			break;
+		case 'i':
+			open_namespace_fd(CLONE_NEWIPC, optarg);
+			break;
+		case 'n':
+			open_namespace_fd(CLONE_NEWNET, optarg);
+			break;
+		case 'p':
+			do_fork = 1;
+			open_namespace_fd(CLONE_NEWPID, optarg);
+			break;
+		case 'U':
+			open_namespace_fd(CLONE_NEWUSER, optarg);
+			break;
+		case 'e':
+			do_fork = 0;
+			break;
+		case 'r':
+			open_target_fd(&root_fd, "root", optarg);
+			break;
+		case 'w':
+			open_target_fd(&wd_fd, "cwd", optarg);
+			break;
+		default:
+			usage(EXIT_FAILURE);
+		}
+	}
+
+	if(optind >= argc)
+		usage(EXIT_FAILURE);
+
+	/*
+	 * Now that we know which namespaces we want to enter, enter them.
+	 */
+	for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
+		if (nsfile->fd < 0)
+			continue;
+		if (setns(nsfile->fd, nsfile->nstype))
+			err(EXIT_FAILURE, _("setns of '%s' failed"),
+			    nsfile->name);
+		close(nsfile->fd);
+		nsfile->fd = -1;
+	}
+
+	/* Remember the current working directory if I'm not changing it */
+	if (root_fd >= 0 && wd_fd < 0) {
+		wd_fd = open(".", O_RDONLY);
+		if (wd_fd < 0)
+			err(EXIT_FAILURE, _("open of . failed"));
+	}
+
+	/* Change the root directory */
+	if (root_fd >= 0) {
+		if (fchdir(root_fd) < 0)
+			err(EXIT_FAILURE, _("fchdir to root_fd failed"));
+
+		if (chroot(".") < 0)
+			err(EXIT_FAILURE, _("chroot failed"));
+
+		close(root_fd);
+		root_fd = -1;
+	}
+		
+	/* Change the working directory */
+	if (wd_fd >= 0) {
+		if (fchdir(wd_fd) < 0)
+			err(EXIT_FAILURE, _("fchdir to wd_fd failed"));
+
+		close(wd_fd);
+		wd_fd = -1;
+	}
+
+	if (do_fork) {
+		pid_t child = fork();
+		if (child < 0)
+			err(EXIT_FAILURE, _("fork failed"));
+		if (child != 0) {
+			int status;
+			if ((waitpid(child, &status, 0) == child) &&
+			     WIFEXITED(status)) {
+				exit(WEXITSTATUS(status));
+			}
+			exit(EXIT_FAILURE);
+		}
+	}
+
+	execvp(argv[optind], argv + optind);
+
+	err(EXIT_FAILURE, _("exec %s failed"), argv[optind]);
+}
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH] unshare: Add support for the pid and user namespaces
  2013-01-11 16:13 ` Karel Zak
  2013-01-11 22:11   ` Eric W. Biederman
  2013-01-11 22:46   ` [PATCH] nsenter: " Eric W. Biederman
@ 2013-01-11 22:53   ` Eric W. Biederman
  2013-01-17 12:35     ` Karel Zak
  2 siblings, 1 reply; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-11 22:53 UTC (permalink / raw)
  To: Karel Zak
  Cc: util-linux, Neil Horman, Serge E. Hallyn, Michael Kerrisk (man-pages)


- Update the unshare application to support the pid and user namespaces.
- Update the man page for the new options
- Fix typo in the man page where UTS was spelled UTC.
- Remove the vestigal support for running a suid unshare.
  After unsharing a user namespace setuid(getuid()) won't work because
  no uid or gid mappings have been specified yet. So it is just easier not
  to have any support for running suid.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---

This is on top of unshare with Neil's unshare patch reverted.

 sys-utils/unshare.1 |   19 +++++++++++++++----
 sys-utils/unshare.c |   27 ++++++++++++++++++---------
 2 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/sys-utils/unshare.1 b/sys-utils/unshare.1
index 1325e34..8cdc6e5 100644
--- a/sys-utils/unshare.1
+++ b/sys-utils/unshare.1
@@ -1,7 +1,7 @@
 .\" Process this file with
 .\" groff -man -Tascii lscpu.1
 .\"
-.TH UNSHARE 1 "October 2008" "util-linux" "User Commands"
+.TH UNSHARE 1 "January 2013" "util-linux" "User Commands"
 .SH NAME
 unshare \- run program with some namespaces unshared from parent
 .SH SYNOPSIS
@@ -31,6 +31,13 @@ process will have independent IPv4 and IPv6 stacks, IP routing tables, firewall
 rules, the \fI/proc/net\fP and \fI/sys/class/net\fP directory trees, sockets
 etc. (\fBCLONE_NEWNET\fP flag).
 .TP
+.BR "pid namespace"
+children will have a distinct set of pid to process mappings than their parent.
+(\fBCLONE_NEWPID\fP flag).
+.TP
+.BR "user namespace"
+process will have distinct set of uids, gids and capabilities. (\fBCLONE_NEWUSER\fP flag).
+.TP
 See the \fBclone\fR(2) for exact semantics of the flags.
 .SH OPTIONS
 .TP
@@ -41,16 +48,20 @@ Print a help message,
 Unshare the mount namespace,
 .TP
 .BR \-u , " \-\-uts"
-Unshare the UTC namespace,
+Unshare the UTS namespace,
 .TP
 .BR \-i , " \-\-ipc"
 Unshare the IPC namespace,
 .TP
 .BR \-n , " \-\-net"
 Unshare the network namespace.
+.TP
+.BR \-p , " \-\-pid"
+Unshare the pid namespace.
+.TP
+.BR \-U , " \-\-user"
+Unshare the user namespace.
 .SH NOTES
-The unshare command drops potential privileges before executing the
-target program. This allows to setuid unshare.
 .SH SEE ALSO
 .BR unshare (2),
 .BR clone (2)
diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c
index 9de997b..00cc2cf 100644
--- a/sys-utils/unshare.c
+++ b/sys-utils/unshare.c
@@ -41,6 +41,12 @@
 #ifndef CLONE_NEWNET
 # define CLONE_NEWNET 0x40000000
 #endif
+#ifndef CLONE_NEWUSER
+# define CLONE_NEWUSER 0x10000000
+#endif
+#ifndef CLONE_NEWPID
+# define CLONE_NEWPID 0x20000000
+#endif
 
 #ifndef HAVE_UNSHARE
 # include <sys/syscall.h>
@@ -63,7 +69,9 @@ static void usage(int status)
 	fputs(_(" -m, --mount       unshare mounts namespace\n"
 		" -u, --uts         unshare UTS namespace (hostname etc)\n"
 		" -i, --ipc         unshare System V IPC namespace\n"
-		" -n, --net         unshare network namespace\n"), out);
+		" -n, --net         unshare network namespace\n"
+		" -p, --pid         unshare pid namespace\n"
+		" -U, --user        unshare user namespace\n"), out);
 
 	fputs(USAGE_SEPARATOR, out);
 	fputs(USAGE_HELP, out);
@@ -82,6 +90,8 @@ int main(int argc, char *argv[])
 		{ "uts", no_argument, 0, 'u' },
 		{ "ipc", no_argument, 0, 'i' },
 		{ "net", no_argument, 0, 'n' },
+		{ "pid", no_argument, 0, 'p' },
+		{ "user", no_argument, 0, 'U' },
 		{ NULL, 0, 0, 0 }
 	};
 
@@ -94,7 +104,7 @@ int main(int argc, char *argv[])
 	textdomain(PACKAGE);
 	atexit(close_stdout);
 
-	while((c = getopt_long(argc, argv, "hVmuin", longopts, NULL)) != -1) {
+	while((c = getopt_long(argc, argv, "hVmuinpU", longopts, NULL)) != -1) {
 		switch(c) {
 		case 'h':
 			usage(EXIT_SUCCESS);
@@ -113,6 +123,12 @@ int main(int argc, char *argv[])
 		case 'n':
 			unshare_flags |= CLONE_NEWNET;
 			break;
+		case 'p':
+			unshare_flags |= CLONE_NEWPID;
+			break;
+		case 'U':
+			unshare_flags |= CLONE_NEWUSER;
+			break;
 		default:
 			usage(EXIT_FAILURE);
 		}
@@ -124,13 +140,6 @@ int main(int argc, char *argv[])
 	if(-1 == unshare(unshare_flags))
 		err(EXIT_FAILURE, _("unshare failed"));
 
-	/* drop potential root euid/egid if we had been setuid'd */
-	if (setgid(getgid()) < 0)
-		err(EXIT_FAILURE, _("cannot set group id"));
-
-	if (setuid(getuid()) < 0)
-		err(EXIT_FAILURE, _("cannot set user id"));
-
 	execvp(argv[optind], argv + optind);
 
 	err(EXIT_FAILURE, _("exec %s failed"), argv[optind]);
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH] nsenter: new command (light wrapper around setns)
  2013-01-11 22:46   ` [PATCH] nsenter: " Eric W. Biederman
@ 2013-01-11 23:45     ` Mike Frysinger
  2013-01-14  8:28       ` Karel Zak
  2013-01-15 18:51     ` [PATCH] nsenter: new command (light wrapper around setns) Serge E. Hallyn
  2013-01-17 12:34     ` Karel Zak
  2 siblings, 1 reply; 24+ messages in thread
From: Mike Frysinger @ 2013-01-11 23:45 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Karel Zak, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)

[-- Attachment #1: Type: Text/Plain, Size: 1610 bytes --]

On Friday 11 January 2013 17:46:38 Eric W. Biederman wrote:
> --- /dev/null
> +++ b/sys-utils/nsenter.c
>
> +#ifndef CLONE_NEWSNS
> +# define CLONE_NEWNS 0x00020000
> +#endif
> +#ifndef CLONE_NEWUTS
> +# define CLONE_NEWUTS 0x04000000
> +#endif
> +#ifndef CLONE_NEWIPC
> +# define CLONE_NEWIPC 0x08000000
> +#endif
> +#ifndef CLONE_NEWNET
> +# define CLONE_NEWNET 0x40000000
> +#endif
> +#ifndef CLONE_NEWUSER
> +# define CLONE_NEWUSER 0x10000000
> +#endif
> +#ifndef CLONE_NEWPID
> +# define CLONE_NEWPID 0x20000000
> +#endif

this logic really should be in a common header and shared with unshare.c

> +static struct namespace_file{
> +	int nstype;
> +	char *name;

const

> +	/* Careful the order is signifcant in this array.

significant

> +static void open_target_fd(int *fd, const char *type, char *path)

path should be const

> +			namespace_target_pid = strtoul(optarg, &end, 10);
> +			if (!*optarg || (*optarg && *end) || errno != 0) {
> +				err(EXIT_FAILURE,
> +				    _("Pid '%s' is not a valid number"),
> +				    optarg);
> +			}

we really should introduce an xstroul() helper

> +	if (do_fork) {
> +		pid_t child = fork();
> +		if (child < 0)
> +			err(EXIT_FAILURE, _("fork failed"));
> +		if (child != 0) {
> +			int status;
> +			if ((waitpid(child, &status, 0) == child) &&
> +			     WIFEXITED(status)) {
> +				exit(WEXITSTATUS(status));
> +			}
> +			exit(EXIT_FAILURE);

shouldn't this inform the user if the child was killed by a signal ?  maybe:
	if (WIFSIGNALED(status))
		kill(getpid(), WTERMSIG(status));

normalizing the status into EXIT_FAILURE doesn't seem right ...
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] enter: new command (light wrapper around setns)
  2013-01-11 11:10   ` Eric W. Biederman
  2013-01-11 13:13     ` Ángel González
@ 2013-01-12  8:59     ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 24+ messages in thread
From: Michael Kerrisk (man-pages) @ 2013-01-12  8:59 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: util-linux, Neil Horman, Karel Zak, Serge E. Hallyn

On Fri, Jan 11, 2013 at 12:10 PM, Eric W. Biederman
<ebiederm@xmission.com> wrote:
> "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> writes:
>
>> Hi Eric,
>>
>> On Fri, Jan 11, 2013 at 11:29 AM, Eric W. Biederman
>> <ebiederm@xmission.com> wrote:
>>>
>>> Inspired by unshare, enter is a simple wrapper around setns that
>>> allows running a new process in the context of an existing process.
>>
>> The name "enter" seems way too generic (far more so than even
>> "unshare"). How about "nsexec" or "execns" or some such?
>
> Enter unlike exec is the right concept, and the name is free.
>
>> Aside from that, what is the purpose of the -f "fork" option?
>
> To tell when you are tired, and should go to bed.  There is no fork
> option ony an exec option.  And the exec option is documented and
> explained.

That's the truth. Thanks for pointing me in the right direction.

Cheers,

Michael



>>> Full paths may be specified to the namespace arguments so that
>>> namespace file descriptors may be used wherever they reside in the
>>> filesystem.
>>>
>>> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
>>> ---
>>>
>>> While doing a final check on this patch I just realized I am a week or
>>> two late to the discussion.  So much for waiting until my code had
>>> merged into the kernel before submitting patches.  I have been
>>> developing enter off and on as I have been developing these patches
>>> and it seems to be stable and feature complete at this point.
>>>
>>> I really don't like the the idea of adding setns support into unshare.
>>> Creating new namespaces and using existing namespaces are related
>>> but different concepts and place different demands on the evolotion
>>> of the code.  Especially when the pid and user namespaces come into
>>> play.
>>>
>>> Little things like retaining the the ability for unshare to be suid root
>>> safely and sanely become intractable if you call setns() and join a
>>> user namespace.
>>>
>>> Supporting the ability for the command to be setuid root does not
>>> work in combination with the user namespace.  As after entering
>>> the user namespace you can not reliably change your uid back to
>>> your uid without setuid as your uid may not be mapped.
>>>
>>> When joining an existing mount namespace you most likely want to change
>>> your root directory and your working directory to the directory of the
>>> process whoose mount namespace you are entering.  Something you don't
>>> even think about when just unsharing a mount namespace.
>>>
>>> Then there is the practical wish to call fork after entering a pid
>>> namespace and before launching a command.  You don't always want that
>>> but almost always so that the command will actually be run in the new
>>> pid namespace with a new pid, instead of having it's children in the new
>>> pid namespace.
>>>
>>> I really can't see support for using setns being in the same binary as
>>> unshare that just mixes two different but closely related things that
>>> will want to evolve in different directions.
>>>
>>> My inclination is to send a follow up patch to remove setns and migrate
>>> from unshare.  And a second patch to add pid and user namespace support
>>> to unshare.  But since I am going against the way that seems to have
>>> already been decided I will hold off on those patches until after we
>>> there is agreement on this one.
>>>
>>> Eric
>>>
>>>  configure.ac            |   11 ++
>>>  sys-utils/Makemodule.am |    7 +
>>>  sys-utils/enter.1       |  101 +++++++++++++++++
>>>  sys-utils/enter.c       |  286 +++++++++++++++++++++++++++++++++++++++++++++++
>>>  4 files changed, 405 insertions(+), 0 deletions(-)
>>>  create mode 100644 sys-utils/enter.1
>>>  create mode 100644 sys-utils/enter.c
>>>
>>> diff --git a/configure.ac b/configure.ac
>>> index e937736..b0c9c6f 100644
>>> --- a/configure.ac
>>> +++ b/configure.ac
>>> @@ -867,6 +867,17 @@ if test "x$build_unshare" = xyes; then
>>>    AC_CHECK_FUNCS([unshare])
>>>  fi
>>>
>>> +AC_ARG_ENABLE([enter],
>>> +  AS_HELP_STRING([--disable-enter], [do not build enter]),
>>> +  [], enable_enter=check
>>> +)
>>> +UL_BUILD_INIT([enter])
>>> +UL_REQUIRES_LINUX([enter])
>>> +UL_REQUIRES_SYSCALL_CHECK([setns], [UL_CHECK_SYSCALL([setns])])
>>> +AM_CONDITIONAL(BUILD_ENTER, test "x$build_enter" = xyes)
>>> +if test "x$build_enter" = xyes; then
>>> +  AC_CHECK_FUNCS([setns])
>>> +fi
>>>
>>>  AC_ARG_ENABLE([arch],
>>>    AS_HELP_STRING([--enable-arch], [do build arch]),
>>> diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
>>> index 5636f70..6ad09b2 100644
>>> --- a/sys-utils/Makemodule.am
>>> +++ b/sys-utils/Makemodule.am
>>> @@ -290,6 +290,13 @@ unshare_SOURCES = sys-utils/unshare.c
>>>  unshare_LDADD = $(LDADD) libcommon.la
>>>  endif
>>>
>>> +if BUILD_UNSHARE
>>> +usrbin_exec_PROGRAMS += enter
>>> +dist_man_MANS += sys-utils/enter.1
>>> +enter_SOURCES = sys-utils/enter.c
>>> +enter_LDADD = $(LDADD) libcommon.la
>>> +endif
>>> +
>>>  if BUILD_ARCH
>>>  bin_PROGRAMS += arch
>>>  dist_man_MANS += sys-utils/arch.1
>>> diff --git a/sys-utils/enter.1 b/sys-utils/enter.1
>>> new file mode 100644
>>> index 0000000..0829ee2
>>> --- /dev/null
>>> +++ b/sys-utils/enter.1
>>> @@ -0,0 +1,101 @@
>>> +.TH ENTER 1 "January 2013" "util-linux" "User Commands"
>>> +.SH NAME
>>> +enter \- run program with namespaces of other processes
>>> +.SH SYNOPSIS
>>> +.B enter
>>> +.RI [ options ]
>>> +program
>>> +.RI [ arguments ]
>>> +.SH DESCRIPTION
>>> +Enters the contexts of one or more other processes and then executes specified
>>> +program. Enterable namespaces are:
>>> +.TP
>>> +.BR "mount namespace"
>>> +mounting and unmounting filesystems will not affect rest of the system
>>> +(\fBCLONE_NEWNS\fP flag), except for filesystems which are explicitly marked as
>>> +shared (by mount --make-shared). See /proc/self/mountinfo for the shared flags.
>>> +.TP
>>> +.BR "UTS namespace"
>>> +setting hostname, domainname will not affect rest of the system
>>> +(\fBCLONE_NEWUTS\fP flag).
>>> +.TP
>>> +.BR "IPC namespace"
>>> +process will have independent namespace for System V message queues, semaphore
>>> +sets and shared memory segments (\fBCLONE_NEWIPC\fP flag).
>>> +.TP
>>> +.BR "network namespace"
>>> +process will have independent IPv4 and IPv6 stacks, IP routing tables, firewall
>>> +rules, the \fI/proc/net\fP and \fI/sys/class/net\fP directory trees, sockets
>>> +etc. (\fBCLONE_NEWNET\fP flag).
>>> +.TP
>>> +.BR "pid namespace"
>>> +children will have a distinct set of pid to process mappings thantheir parent.
>>> +(\fBCLONE_NEWPID\fP flag).
>>> +.TP
>>> +.BR "user namespace"
>>> +process will have distinct set of uids, gids and capabilities. (\fBCLONE_NEWUSER\fP flag).
>>> +.TP
>>> +See the \fBclone\fR(2) for exact semantics of the flags.
>>> +.SH OPTIONS
>>> +.TP
>>> +.BR \-h , " \-\-help"
>>> +Print a help message,
>>> +.TP
>>> +.BR \-t , " \-\-target " \fIpid\fP
>>> +Specify a target process to get contexts from.
>>> +.TP
>>> +.BR \-m , " \-\-mount"=[\fIfile\fP]
>>> +Enter the mount namespace.
>>> +If no file is specified enter the mount namespace of the target process.
>>> +If file is specified enter the mount namespace specified by file.
>>> +.TP
>>> +.BR \-u , " \-\-uts"=[\fIfile\fP]
>>> +Enter the uts namespace.
>>> +If no file is specified enter the uts namespace of the target process.
>>> +If file is specified enter the uts namespace specified by file.
>>> +.TP
>>> +.BR \-i , " \-\-ipc "=[\fIfile\fP]
>>> +Enter the IPC namespace.
>>> +If no file is specified enter the IPC namespace of the target process.
>>> +If file is specified enter the uts namespace specified by file.
>>> +.TP
>>> +.BR \-n , " \-\-net"=[\fIfile\fP]
>>> +Enter the network namespace.
>>> +If no file is specified enter the network namespace of the target process.
>>> +If file is specified enter the network namespace specified by file.
>>> +.TP
>>> +.BR \-p , " \-\-pid"=[\fIfile\fP]
>>> +Enter the pid namespace.
>>> +If no file is specified enter the pid namespace of the target process.
>>> +If file is specified enter the pid namespace specified by file.
>>> +.TP
>>> +.BR \-U , " \-\-user"=[\fIfile\fP]
>>> +Enter the user namespace.
>>> +If no file is specified enter the user namespace of the target process.
>>> +If file is specified enter the user namespace specified by file.
>>> +.TP
>>> +.BR \-r , " \-\-root"=[\fIdirectory\fP]
>>> +Set the root directory.
>>> +If no directory is specified set the root directory to the root directory of the target process.
>>> +If directory is specified set the root directory to the specified directory.
>>> +.TP
>>> +.BR \-w , " \-\-wd"=[\fIdirectory\fP]
>>> +Set the working directory.
>>> +If no directory is specified set the working directory to the working directory of the target process.
>>> +If directory is specified set the working directory to the specified directory.
>>> +.TP
>>> +.BR \-e , " \-\-exec"
>>> +Don't fork before exec'ing the specified program.  By default when entering
>>> +a pid namespace enter calls fork before calling exec so that the children will
>>> +be in the newly entered pid namespace.
>>> +.SH NOTES
>>> +.SH SEE ALSO
>>> +.BR setns (2),
>>> +.BR clone (2)
>>> +.SH BUGS
>>> +None known so far.
>>> +.SH AUTHOR
>>> +Eric Biederman <ebiederm@xmission.com>
>>> +.SH AVAILABILITY
>>> +The enter command is part of the util-linux package and is available from
>>> +ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
>>> diff --git a/sys-utils/enter.c b/sys-utils/enter.c
>>> new file mode 100644
>>> index 0000000..d7bd540
>>> --- /dev/null
>>> +++ b/sys-utils/enter.c
>>> @@ -0,0 +1,286 @@
>>> +/*
>>> + * enter(1) - command-line interface for setns(2)
>>> + *
>>> + * Copyright (C) 2012-2013 Eric Biederman <ebiederm@xmission.com>
>>> + *
>>> + * This program is free software; you can redistribute it and/or modify it
>>> + * under the terms of the GNU General Public License as published by the
>>> + * Free Software Foundation; version 2.
>>> + *
>>> + * This program is distributed in the hope that it will be useful, but
>>> + * WITHOUT ANY WARRANTY; without even the implied warranty of
>>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>>> + * General Public License for more details.
>>> + *
>>> + * You should have received a copy of the GNU General Public License along
>>> + * with this program; if not, write to the Free Software Foundation, Inc.,
>>> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>>> + */
>>> +
>>> +#include <sys/types.h>
>>> +#include <sys/wait.h>
>>> +#include <dirent.h>
>>> +#include <errno.h>
>>> +#include <getopt.h>
>>> +#include <sched.h>
>>> +#include <stdio.h>
>>> +#include <stdlib.h>
>>> +#include <unistd.h>
>>> +
>>> +#include "nls.h"
>>> +#include "c.h"
>>> +#include "closestream.h"
>>> +
>>> +#ifndef CLONE_NEWSNS
>>> +# define CLONE_NEWNS 0x00020000
>>> +#endif
>>> +#ifndef CLONE_NEWUTS
>>> +# define CLONE_NEWUTS 0x04000000
>>> +#endif
>>> +#ifndef CLONE_NEWIPC
>>> +# define CLONE_NEWIPC 0x08000000
>>> +#endif
>>> +#ifndef CLONE_NEWNET
>>> +# define CLONE_NEWNET 0x40000000
>>> +#endif
>>> +#ifndef CLONE_NEWUSER
>>> +# define CLONE_NEWUSER 0x10000000
>>> +#endif
>>> +#ifndef CLONE_NEWPID
>>> +# define CLONE_NEWPID 0x20000000
>>> +#endif
>>> +
>>> +#ifndef HAVE_SETNS
>>> +# include <sys/syscall.h>
>>> +static int setns(int fd, int nstype)
>>> +{
>>> +       return syscall(SYS_setns, fd, nstype);
>>> +}
>>> +#endif /* HAVE_SETNS */
>>> +
>>> +static struct namespace_file{
>>> +       int nstype;
>>> +       char *name;
>>> +       int fd;
>>> +} namespace_files[] = {
>>> +       /* Careful the order is signifcant in this array.
>>> +        *
>>> +        * The user namespace comes first, so that it is entered
>>> +        * first.  This gives an unprivileged user the potential to
>>> +        * enter the other namespaces.
>>> +        */
>>> +       { .nstype = CLONE_NEWUSER, .name = "ns/user", .fd = -1 },
>>> +       { .nstype = CLONE_NEWIPC,  .name = "ns/ipc",  .fd = -1 },
>>> +       { .nstype = CLONE_NEWUTS,  .name = "ns/uts",  .fd = -1 },
>>> +       { .nstype = CLONE_NEWNET,  .name = "ns/net",  .fd = -1 },
>>> +       { .nstype = CLONE_NEWPID,  .name = "ns/pid",  .fd = -1 },
>>> +       { .nstype = CLONE_NEWNS,   .name = "ns/mnt",  .fd = -1 },
>>> +       {}
>>> +};
>>> +
>>> +static void usage(int status)
>>> +{
>>> +       FILE *out = status == EXIT_SUCCESS ? stdout : stderr;
>>> +
>>> +       fputs(USAGE_HEADER, out);
>>> +       fprintf(out, _(" %s [options] <program> [args...]\n"),
>>> +               program_invocation_short_name);
>>> +
>>> +       fputs(USAGE_OPTIONS, out);
>>> +       fputs(_(" -t, --target <pid>   target process to get namespaces from\n"
>>> +               " -m, --mount [<file>] enter mount namespace\n"
>>> +               " -u, --uts   [<file>] enter UTS namespace (hostname etc)\n"
>>> +               " -i, --ipc   [<file>] enter System V IPC namespace\n"
>>> +               " -n, --net   [<file>] enter network namespace\n"
>>> +               " -p, --pid   [<file>] enter pid namespace\n"
>>> +               " -U, --user  [<file>] enter user namespace\n"
>>> +               " -e, --exec           don't fork before exec'ing <program>\n"
>>> +               " -r, --root  [<dir>]  set the root directory\n"
>>> +               " -w, --wd    [<dir>]  set the working directory\n"), out);
>>> +       fputs(USAGE_SEPARATOR, out);
>>> +       fputs(USAGE_HELP, out);
>>> +       fputs(USAGE_VERSION, out);
>>> +       fprintf(out, USAGE_MAN_TAIL("enter(1)"));
>>> +
>>> +       exit(status);
>>> +}
>>> +
>>> +static pid_t namespace_target_pid = 0;
>>> +static int root_fd = -1;
>>> +static int wd_fd = -1;
>>> +
>>> +static void open_target_fd(int *fd, const char *type, char *path)
>>> +{
>>> +       char pathbuf[PATH_MAX];
>>> +
>>> +       if (!path && namespace_target_pid) {
>>> +               snprintf(pathbuf, sizeof(pathbuf), "/proc/%u/%s",
>>> +                       namespace_target_pid, type);
>>> +               path = pathbuf;
>>> +       }
>>> +       if (!path)
>>> +               err(EXIT_FAILURE, _("No filename and no target pid supplied for %s"),
>>> +                   type);
>>> +
>>> +       if (*fd >= 0)
>>> +               close(*fd);
>>> +
>>> +       *fd = open(path, O_RDONLY);
>>> +       if (*fd < 0)
>>> +               err(EXIT_FAILURE, _("open of '%s' failed"), path);
>>> +}
>>> +
>>> +static void open_namespace_fd(int nstype, char *path)
>>> +{
>>> +       struct namespace_file *nsfile;
>>> +
>>> +       for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
>>> +               if (nstype != nsfile->nstype)
>>> +                       continue;
>>> +
>>> +               open_target_fd(&nsfile->fd, nsfile->name, path);
>>> +               return;
>>> +       }
>>> +       /* This should never happen */
>>> +       err(EXIT_FAILURE, "Unrecognized namespace type");
>>> +}
>>> +
>>> +int main(int argc, char *argv[])
>>> +{
>>> +       static const struct option longopts[] = {
>>> +               { "help", no_argument, NULL, 'h' },
>>> +               { "version", no_argument, NULL, 'V'},
>>> +               { "target", required_argument, NULL, 't' },
>>> +               { "mount", optional_argument, NULL, 'm' },
>>> +               { "uts", optional_argument, NULL, 'u' },
>>> +               { "ipc", optional_argument, NULL, 'i' },
>>> +               { "net", optional_argument, NULL, 'n' },
>>> +               { "pid", optional_argument, NULL, 'p' },
>>> +               { "user", optional_argument, NULL, 'U' },
>>> +               { "exec", no_argument, NULL, 'e' },
>>> +               { "root", optional_argument, NULL, 'r' },
>>> +               { "wd", optional_argument, NULL, 'w' },
>>> +               { NULL, 0, NULL, 0 }
>>> +       };
>>> +
>>> +       struct namespace_file *nsfile;
>>> +       int do_fork = 0;
>>> +       char *end;
>>> +       int c;
>>> +
>>> +       setlocale(LC_MESSAGES, "");
>>> +       bindtextdomain(PACKAGE, LOCALEDIR);
>>> +       textdomain(PACKAGE);
>>> +       atexit(close_stdout);
>>> +
>>> +       while((c = getopt_long(argc, argv, "hVt:m::u::i::n::p::U::er::w::", longopts, NULL)) != -1) {
>>> +               switch(c) {
>>> +               case 'h':
>>> +                       usage(EXIT_SUCCESS);
>>> +               case 'V':
>>> +                       printf(UTIL_LINUX_VERSION);
>>> +                       return EXIT_SUCCESS;
>>> +               case 't':
>>> +                       errno = 0;
>>> +                       namespace_target_pid = strtoul(optarg, &end, 10);
>>> +                       if (!*optarg || (*optarg && *end) || errno != 0) {
>>> +                               err(EXIT_FAILURE,
>>> +                                   _("Pid '%s' is not a valid number"),
>>> +                                   optarg);
>>> +                       }
>>> +                       break;
>>> +               case 'm':
>>> +                       open_namespace_fd(CLONE_NEWNS, optarg);
>>> +                       break;
>>> +               case 'u':
>>> +                       open_namespace_fd(CLONE_NEWUTS, optarg);
>>> +                       break;
>>> +               case 'i':
>>> +                       open_namespace_fd(CLONE_NEWIPC, optarg);
>>> +                       break;
>>> +               case 'n':
>>> +                       open_namespace_fd(CLONE_NEWNET, optarg);
>>> +                       break;
>>> +               case 'p':
>>> +                       do_fork = 1;
>>> +                       open_namespace_fd(CLONE_NEWPID, optarg);
>>> +                       break;
>>> +               case 'U':
>>> +                       open_namespace_fd(CLONE_NEWUSER, optarg);
>>> +                       break;
>>> +               case 'e':
>>> +                       do_fork = 0;
>>> +                       break;
>>> +               case 'r':
>>> +                       open_target_fd(&root_fd, "root", optarg);
>>> +                       break;
>>> +               case 'w':
>>> +                       open_target_fd(&wd_fd, "cwd", optarg);
>>> +                       break;
>>> +               default:
>>> +                       usage(EXIT_FAILURE);
>>> +               }
>>> +       }
>>> +
>>> +       if(optind >= argc)
>>> +               usage(EXIT_FAILURE);
>>> +
>>> +       /*
>>> +        * Now that we know which namespaces we want to enter, enter them.
>>> +        */
>>> +       for (nsfile = namespace_files; nsfile->nstype; nsfile++) {
>>> +               if (nsfile->fd < 0)
>>> +                       continue;
>>> +               if (setns(nsfile->fd, nsfile->nstype))
>>> +                       err(EXIT_FAILURE, _("setns of '%s' failed"),
>>> +                           nsfile->name);
>>> +               close(nsfile->fd);
>>> +               nsfile->fd = -1;
>>> +       }
>>> +
>>> +       /* Remember the current working directory if I'm not changing it */
>>> +       if (root_fd >= 0 && wd_fd < 0) {
>>> +               wd_fd = open(".", O_RDONLY);
>>> +               if (wd_fd < 0)
>>> +                       err(EXIT_FAILURE, _("open of . failed"));
>>> +       }
>>> +
>>> +       /* Change the root directory */
>>> +       if (root_fd >= 0) {
>>> +               if (fchdir(root_fd) < 0)
>>> +                       err(EXIT_FAILURE, _("fchdir to root_fd failed"));
>>> +
>>> +               if (chroot(".") < 0)
>>> +                       err(EXIT_FAILURE, _("chroot failed"));
>>> +
>>> +               close(root_fd);
>>> +               root_fd = -1;
>>> +       }
>>> +
>>> +       /* Change the working directory */
>>> +       if (wd_fd >= 0) {
>>> +               if (fchdir(wd_fd) < 0)
>>> +                       err(EXIT_FAILURE, _("fchdir to wd_fd failed"));
>>> +
>>> +               close(wd_fd);
>>> +               wd_fd = -1;
>>> +       }
>>> +
>>> +       if (do_fork) {
>>> +               pid_t child = fork();
>>> +               if (child < 0)
>>> +                       err(EXIT_FAILURE, _("fork failed"));
>>> +               if (child != 0) {
>>> +                       int status;
>>> +                       if ((waitpid(child, &status, 0) == child) &&
>>> +                            WIFEXITED(status)) {
>>> +                               exit(WEXITSTATUS(status));
>>> +                       }
>>> +                       exit(EXIT_FAILURE);
>>> +               }
>>> +       }
>>> +
>>> +       execvp(argv[optind], argv + optind);
>>> +
>>> +       err(EXIT_FAILURE, _("exec %s failed"), argv[optind]);
>>> +}
>>> --
>>> 1.7.5.4
>>>



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] enter: new command (light wrapper around setns)
  2013-01-11 22:11   ` Eric W. Biederman
@ 2013-01-12  9:01     ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 24+ messages in thread
From: Michael Kerrisk (man-pages) @ 2013-01-12  9:01 UTC (permalink / raw)
  To: Eric W. Biederman; +Cc: Karel Zak, util-linux, Neil Horman, Serge E. Hallyn

On Fri, Jan 11, 2013 at 11:11 PM, Eric W. Biederman
<ebiederm@xmission.com> wrote:
> Karel Zak <kzak@redhat.com> writes:
>
>> On Fri, Jan 11, 2013 at 02:29:24AM -0800, Eric W. Biederman wrote:
>>>
>>> Inspired by unshare, enter is a simple wrapper around setns that
>>> allows running a new process in the context of an existing process.
>>
>>  It would be really nice to have "ns" in the name -- for example
>>  "enterns" sounds good.
>
> enterns might work.  I am still trying to reconcile that name with
> changing the working directory and the root directory.  Those really
> aren't namespaces.
>
> But name slightly less generic seems to be the popular vote.  Short of
> something better my vote is for nsenter.  enterns sounds way too much
> like interns which has a rather different meaning.

"nsenter" sounds good to me.

Cheers,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] nsenter: new command (light wrapper around setns)
  2013-01-11 23:45     ` Mike Frysinger
@ 2013-01-14  8:28       ` Karel Zak
  2013-01-17  0:33         ` [PATCH 0/5] nsenter review comment fixes Eric W. Biederman
  0 siblings, 1 reply; 24+ messages in thread
From: Karel Zak @ 2013-01-14  8:28 UTC (permalink / raw)
  To: Mike Frysinger
  Cc: Eric W. Biederman, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)

On Fri, Jan 11, 2013 at 06:45:14PM -0500, Mike Frysinger wrote:
> path should be const
> 
> > +			namespace_target_pid = strtoul(optarg, &end, 10);
> > +			if (!*optarg || (*optarg && *end) || errno != 0) {
> > +				err(EXIT_FAILURE,
> > +				    _("Pid '%s' is not a valid number"),
> > +				    optarg);
> > +			}
> 
> we really should introduce an xstroul() helper

see include/strutils.h

  namespace_target_pid = strtoul_or_err(optarg, _("failed to parse pid"));

    Karel



-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] nsenter: new command (light wrapper around setns)
  2013-01-11 22:46   ` [PATCH] nsenter: " Eric W. Biederman
  2013-01-11 23:45     ` Mike Frysinger
@ 2013-01-15 18:51     ` Serge E. Hallyn
  2013-01-17 12:34     ` Karel Zak
  2 siblings, 0 replies; 24+ messages in thread
From: Serge E. Hallyn @ 2013-01-15 18:51 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Karel Zak, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)

Quoting Eric W. Biederman (ebiederm@xmission.com):
> 
> Inspired by unshare, nsenter is a simple wrapper around setns that
> allows running a new process in the context of an existing process.
> 
> Full paths may be specified to the namespace arguments so that
> namespace file descriptors may be used wherever they reside in the
> filesystem.
> 
> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

Core code looks good, thanks

Acked-by: Serge Hallyn <serge.hallyn@canonical.com>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 0/5] nsenter review comment fixes.
  2013-01-14  8:28       ` Karel Zak
@ 2013-01-17  0:33         ` Eric W. Biederman
  2013-01-17  0:34           ` [PATCH 1/5] nsenter: Enhance waiting for a child process Eric W. Biederman
                             ` (6 more replies)
  0 siblings, 7 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-17  0:33 UTC (permalink / raw)
  To: Karel Zak
  Cc: Mike Frysinger, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)


Fair enough review comments all.  Here are my tested incremental fixes.

 include/namespace.h |   43 +++++++++++++++++++++++
 sys-utils/nsenter.c |   94 +++++++++++++++++++++++----------------------------
 sys-utils/unshare.c |   29 +---------------
 3 files changed, 86 insertions(+), 80 deletions(-)

Eric W. Biederman (5):
      nsenter: Enhance waiting for a child process
      nsenter: Properly spell significant in a comment.
      nsenter: Add const to declarations where possible.
      nsenter: Replace a bare strtoul with strtoul_or_err
      unshare,nsenter:  Move the old libc handling into a common header namespace.h

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 1/5] nsenter: Enhance waiting for a child process
  2013-01-17  0:33         ` [PATCH 0/5] nsenter review comment fixes Eric W. Biederman
@ 2013-01-17  0:34           ` Eric W. Biederman
  2013-01-17  0:34           ` [PATCH 2/5] nsenter: Properly spell significant in a comment Eric W. Biederman
                             ` (5 subsequent siblings)
  6 siblings, 0 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-17  0:34 UTC (permalink / raw)
  To: Karel Zak
  Cc: Mike Frysinger, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)


In the case of a pid namespace we need to fork a child process instead
of calling exec.  Move all of that logic out of line into a function
continue_as_child, making the logic of the primary case easier to
understand.

Update the logic for waiting for a child process to suspend ourselves
when the child processes suspends and to continue the child process
when we are unsuspsended.  This supports the bash suspend command and
various editors that suspend themselves.

If the child process exits with a signal update the logic to run
kill(getpid(), WTERMSIG(status)) so the caller sees the same exit code
that nsenter observed.

There will always be permission to send signals to our children and
the tty is not changing so there is no need for the intermediate
process to forward signals to it's child.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 sys-utils/nsenter.c |   48 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c
index e1f3995..ad01355 100644
--- a/sys-utils/nsenter.c
+++ b/sys-utils/nsenter.c
@@ -145,6 +145,39 @@ static void open_namespace_fd(int nstype, char *path)
 	err(EXIT_FAILURE, "Unrecognized namespace type");
 }
 
+static void continue_as_child(void)
+{
+	pid_t child = fork();
+	int status;
+	pid_t ret;
+
+	if (child < 0)
+		err(EXIT_FAILURE, _("fork failed"));
+
+	/* Only the child returns */
+	if (child == 0)
+		return;
+
+	for (;;) {
+		ret = waitpid(child, &status, WUNTRACED);
+		if ((ret == child) && (WIFSTOPPED(status))) {
+			/* The child suspended so suspend us as well */
+			kill(getpid(), SIGSTOP);
+			kill(child, SIGCONT);
+		} else {
+			break;
+		}
+	}
+	/* Return the child's exit code if possible */
+	if (WIFEXITED(status)) {
+		exit(WEXITSTATUS(status));
+	}
+	else if (WIFSIGNALED(status)) {
+		kill(getpid(), WTERMSIG(status));
+	}
+	exit(EXIT_FAILURE);
+}
+
 int main(int argc, char *argv[])
 {
 	static const struct option longopts[] = {
@@ -266,19 +299,8 @@ int main(int argc, char *argv[])
 		wd_fd = -1;
 	}
 
-	if (do_fork) {
-		pid_t child = fork();
-		if (child < 0)
-			err(EXIT_FAILURE, _("fork failed"));
-		if (child != 0) {
-			int status;
-			if ((waitpid(child, &status, 0) == child) &&
-			     WIFEXITED(status)) {
-				exit(WEXITSTATUS(status));
-			}
-			exit(EXIT_FAILURE);
-		}
-	}
+	if (do_fork)
+		continue_as_child();
 
 	execvp(argv[optind], argv + optind);
 
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 2/5] nsenter: Properly spell significant in a comment.
  2013-01-17  0:33         ` [PATCH 0/5] nsenter review comment fixes Eric W. Biederman
  2013-01-17  0:34           ` [PATCH 1/5] nsenter: Enhance waiting for a child process Eric W. Biederman
@ 2013-01-17  0:34           ` Eric W. Biederman
  2013-01-17  0:35           ` [PATCH 3/5] nsenter: Add const to declarations where possible Eric W. Biederman
                             ` (4 subsequent siblings)
  6 siblings, 0 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-17  0:34 UTC (permalink / raw)
  To: Karel Zak
  Cc: Mike Frysinger, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)


Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 sys-utils/nsenter.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c
index ad01355..d7d65f9 100644
--- a/sys-utils/nsenter.c
+++ b/sys-utils/nsenter.c
@@ -63,7 +63,7 @@ static struct namespace_file{
 	char *name;
 	int fd;
 } namespace_files[] = {
-	/* Careful the order is signifcant in this array.
+	/* Careful the order is significant in this array.
 	 *
 	 * The user namespace comes first, so that it is entered
 	 * first.  This gives an unprivileged user the potential to
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 3/5] nsenter: Add const to declarations where possible.
  2013-01-17  0:33         ` [PATCH 0/5] nsenter review comment fixes Eric W. Biederman
  2013-01-17  0:34           ` [PATCH 1/5] nsenter: Enhance waiting for a child process Eric W. Biederman
  2013-01-17  0:34           ` [PATCH 2/5] nsenter: Properly spell significant in a comment Eric W. Biederman
@ 2013-01-17  0:35           ` Eric W. Biederman
  2013-01-17  0:35           ` [PATCH 4/5] nsenter: Replace a bare strtoul with strtoul_or_err Eric W. Biederman
                             ` (3 subsequent siblings)
  6 siblings, 0 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-17  0:35 UTC (permalink / raw)
  To: Karel Zak
  Cc: Mike Frysinger, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)


Make it clear where functions do not modify their arguments.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 sys-utils/nsenter.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c
index d7d65f9..5b8d9c4 100644
--- a/sys-utils/nsenter.c
+++ b/sys-utils/nsenter.c
@@ -60,7 +60,7 @@ static int setns(int fd, int nstype)
 
 static struct namespace_file{
 	int nstype;
-	char *name;
+	const char *name;
 	int fd;
 } namespace_files[] = {
 	/* Careful the order is significant in this array.
@@ -109,7 +109,7 @@ static pid_t namespace_target_pid = 0;
 static int root_fd = -1;
 static int wd_fd = -1;
 
-static void open_target_fd(int *fd, const char *type, char *path)
+static void open_target_fd(int *fd, const char *type, const char *path)
 {
 	char pathbuf[PATH_MAX];
 
@@ -130,7 +130,7 @@ static void open_target_fd(int *fd, const char *type, char *path)
 		err(EXIT_FAILURE, _("open of '%s' failed"), path);
 }
 
-static void open_namespace_fd(int nstype, char *path)
+static void open_namespace_fd(int nstype, const char *path)
 {
 	struct namespace_file *nsfile;
 
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 4/5] nsenter: Replace a bare strtoul with strtoul_or_err
  2013-01-17  0:33         ` [PATCH 0/5] nsenter review comment fixes Eric W. Biederman
                             ` (2 preceding siblings ...)
  2013-01-17  0:35           ` [PATCH 3/5] nsenter: Add const to declarations where possible Eric W. Biederman
@ 2013-01-17  0:35           ` Eric W. Biederman
  2013-01-17  0:36           ` [PATCH 5/5] unshare,nsenter: Move the old libc handling into a common header namespace.h Eric W. Biederman
                             ` (2 subsequent siblings)
  6 siblings, 0 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-17  0:35 UTC (permalink / raw)
  To: Karel Zak
  Cc: Mike Frysinger, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)


This is shorter code and makes things a bit clearer and less
error prone if anyone happens to copy the code.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 sys-utils/nsenter.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c
index 5b8d9c4..cc54ebe 100644
--- a/sys-utils/nsenter.c
+++ b/sys-utils/nsenter.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include "strutils.h"
 #include "nls.h"
 #include "c.h"
 #include "closestream.h"
@@ -198,7 +199,6 @@ int main(int argc, char *argv[])
 
 	struct namespace_file *nsfile;
 	int do_fork = 0;
-	char *end;
 	int c;
 
 	setlocale(LC_MESSAGES, "");
@@ -214,13 +214,7 @@ int main(int argc, char *argv[])
 			printf(UTIL_LINUX_VERSION);
 			return EXIT_SUCCESS;
 		case 't':
-			errno = 0;
-			namespace_target_pid = strtoul(optarg, &end, 10);
-			if (!*optarg || (*optarg && *end) || errno != 0) {
-				err(EXIT_FAILURE,
-				    _("Pid '%s' is not a valid number"),
-				    optarg);
-			}
+			namespace_target_pid = strtoul_or_err(optarg, _("failed to parse pid"));
 			break;
 		case 'm':
 			open_namespace_fd(CLONE_NEWNS, optarg);
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 5/5] unshare,nsenter:  Move the old libc handling into a common header namespace.h
  2013-01-17  0:33         ` [PATCH 0/5] nsenter review comment fixes Eric W. Biederman
                             ` (3 preceding siblings ...)
  2013-01-17  0:35           ` [PATCH 4/5] nsenter: Replace a bare strtoul with strtoul_or_err Eric W. Biederman
@ 2013-01-17  0:36           ` Eric W. Biederman
  2013-01-17  3:11           ` [PATCH 0/5] nsenter review comment fixes Mike Frysinger
  2013-01-17 12:35           ` Karel Zak
  6 siblings, 0 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-17  0:36 UTC (permalink / raw)
  To: Karel Zak
  Cc: Mike Frysinger, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)


Move the defitions of CLONE_NEWNS, CLONE_NEWUTS, CLONE_NEWIPC,
CLONE_NEWNET, CLONE_NEWUSER, CLONE_NEWPID into namespace.h in case
sched.h does not provide those definitions.  Are there systems
around that are old enough that still need this?

Move the definitions of unshare() and setns() into namespace.h
for supporting old versions of libc that does not provice these.
I have tested this support with setns as I still have systems
old enough that glibc does not wrap setns.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 include/namespace.h |   43 +++++++++++++++++++++++++++++++++++++++++++
 sys-utils/nsenter.c |   28 +---------------------------
 sys-utils/unshare.c |   29 +----------------------------
 3 files changed, 45 insertions(+), 55 deletions(-)
 create mode 100644 include/namespace.h

diff --git a/include/namespace.h b/include/namespace.h
new file mode 100644
index 0000000..8ccc3f6
--- /dev/null
+++ b/include/namespace.h
@@ -0,0 +1,43 @@
+/* Compat code so unshare and setns can be used with older libcs */
+#ifndef UTIL_LINUX_NAMESPACE_H
+#define UTIL_LINUX_NAMESPACE_H
+
+#include <sched.h>
+
+#ifndef CLONE_NEWSNS
+# define CLONE_NEWNS 0x00020000
+#endif
+#ifndef CLONE_NEWUTS
+# define CLONE_NEWUTS 0x04000000
+#endif
+#ifndef CLONE_NEWIPC
+# define CLONE_NEWIPC 0x08000000
+#endif
+#ifndef CLONE_NEWNET
+# define CLONE_NEWNET 0x40000000
+#endif
+#ifndef CLONE_NEWUSER
+# define CLONE_NEWUSER 0x10000000
+#endif
+#ifndef CLONE_NEWPID
+# define CLONE_NEWPID 0x20000000
+#endif
+
+#ifndef HAVE_UNSHARE
+# include <sys/syscall.h>
+
+static inline int unshare(int flags)
+{
+	return syscall(SYS_unshare, flags);
+}
+#endif
+
+#ifndef HAVE_SETNS
+# include <sys/syscall.h>
+static inline int setns(int fd, int nstype)
+{
+	return syscall(SYS_setns, fd, nstype);
+}
+#endif /* HAVE_SETNS */
+
+#endif /* UTIL_LINUX_NAMESPACE_H */
diff --git a/sys-utils/nsenter.c b/sys-utils/nsenter.c
index cc54ebe..a2d464e 100644
--- a/sys-utils/nsenter.c
+++ b/sys-utils/nsenter.c
@@ -31,33 +31,7 @@
 #include "nls.h"
 #include "c.h"
 #include "closestream.h"
-
-#ifndef CLONE_NEWSNS
-# define CLONE_NEWNS 0x00020000
-#endif
-#ifndef CLONE_NEWUTS
-# define CLONE_NEWUTS 0x04000000
-#endif
-#ifndef CLONE_NEWIPC
-# define CLONE_NEWIPC 0x08000000
-#endif
-#ifndef CLONE_NEWNET
-# define CLONE_NEWNET 0x40000000
-#endif
-#ifndef CLONE_NEWUSER
-# define CLONE_NEWUSER 0x10000000
-#endif
-#ifndef CLONE_NEWPID
-# define CLONE_NEWPID 0x20000000
-#endif
-
-#ifndef HAVE_SETNS
-# include <sys/syscall.h>
-static int setns(int fd, int nstype)
-{
-	return syscall(SYS_setns, fd, nstype);
-}
-#endif /* HAVE_SETNS */
+#include "namespace.h"
 
 static struct namespace_file{
 	int nstype;
diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c
index 00cc2cf..9b849ee 100644
--- a/sys-utils/unshare.c
+++ b/sys-utils/unshare.c
@@ -28,34 +28,7 @@
 #include "nls.h"
 #include "c.h"
 #include "closestream.h"
-
-#ifndef CLONE_NEWSNS
-# define CLONE_NEWNS 0x00020000
-#endif
-#ifndef CLONE_NEWUTS
-# define CLONE_NEWUTS 0x04000000
-#endif
-#ifndef CLONE_NEWIPC
-# define CLONE_NEWIPC 0x08000000
-#endif
-#ifndef CLONE_NEWNET
-# define CLONE_NEWNET 0x40000000
-#endif
-#ifndef CLONE_NEWUSER
-# define CLONE_NEWUSER 0x10000000
-#endif
-#ifndef CLONE_NEWPID
-# define CLONE_NEWPID 0x20000000
-#endif
-
-#ifndef HAVE_UNSHARE
-# include <sys/syscall.h>
-
-static int unshare(int flags)
-{
-	return syscall(SYS_unshare, flags);
-}
-#endif
+#include "namespace.h"
 
 static void usage(int status)
 {
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/5] nsenter review comment fixes.
  2013-01-17  0:33         ` [PATCH 0/5] nsenter review comment fixes Eric W. Biederman
                             ` (4 preceding siblings ...)
  2013-01-17  0:36           ` [PATCH 5/5] unshare,nsenter: Move the old libc handling into a common header namespace.h Eric W. Biederman
@ 2013-01-17  3:11           ` Mike Frysinger
  2013-01-17 12:35           ` Karel Zak
  6 siblings, 0 replies; 24+ messages in thread
From: Mike Frysinger @ 2013-01-17  3:11 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Karel Zak, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)

[-- Attachment #1: Type: Text/Plain, Size: 163 bytes --]

On Wednesday 16 January 2013 19:33:29 Eric W. Biederman wrote:
> Fair enough review comments all.  Here are my tested incremental fixes.

all lgtm.  thanks!
-mike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] nsenter: new command (light wrapper around setns)
  2013-01-11 22:46   ` [PATCH] nsenter: " Eric W. Biederman
  2013-01-11 23:45     ` Mike Frysinger
  2013-01-15 18:51     ` [PATCH] nsenter: new command (light wrapper around setns) Serge E. Hallyn
@ 2013-01-17 12:34     ` Karel Zak
  2 siblings, 0 replies; 24+ messages in thread
From: Karel Zak @ 2013-01-17 12:34 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: util-linux, Neil Horman, Serge E. Hallyn, Michael Kerrisk (man-pages)

On Fri, Jan 11, 2013 at 02:46:38PM -0800, Eric W. Biederman wrote:
>  configure.ac            |   11 ++
>  sys-utils/Makemodule.am |    7 +
>  sys-utils/nsenter.1     |  101 +++++++++++++++++
>  sys-utils/nsenter.c     |  286 +++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 405 insertions(+), 0 deletions(-)
>  create mode 100644 sys-utils/nsenter.1
>  create mode 100644 sys-utils/nsenter.c

 Applied (and setns() stuff reverted from unshare), thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] unshare: Add support for the pid and user namespaces
  2013-01-11 22:53   ` [PATCH] unshare: Add support for the pid and user namespaces Eric W. Biederman
@ 2013-01-17 12:35     ` Karel Zak
  2013-01-17 12:56       ` Eric W. Biederman
  0 siblings, 1 reply; 24+ messages in thread
From: Karel Zak @ 2013-01-17 12:35 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: util-linux, Neil Horman, Serge E. Hallyn, Michael Kerrisk (man-pages)

On Fri, Jan 11, 2013 at 02:53:34PM -0800, Eric W. Biederman wrote:
>  sys-utils/unshare.1 |   19 +++++++++++++++----
>  sys-utils/unshare.c |   27 ++++++++++++++++++---------
>  2 files changed, 33 insertions(+), 13 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 0/5] nsenter review comment fixes.
  2013-01-17  0:33         ` [PATCH 0/5] nsenter review comment fixes Eric W. Biederman
                             ` (5 preceding siblings ...)
  2013-01-17  3:11           ` [PATCH 0/5] nsenter review comment fixes Mike Frysinger
@ 2013-01-17 12:35           ` Karel Zak
  6 siblings, 0 replies; 24+ messages in thread
From: Karel Zak @ 2013-01-17 12:35 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: Mike Frysinger, util-linux, Neil Horman, Serge E. Hallyn,
	Michael Kerrisk (man-pages)

On Wed, Jan 16, 2013 at 04:33:29PM -0800, Eric W. Biederman wrote:
>  include/namespace.h |   43 +++++++++++++++++++++++
>  sys-utils/nsenter.c |   94 +++++++++++++++++++++++----------------------------
>  sys-utils/unshare.c |   29 +---------------
>  3 files changed, 86 insertions(+), 80 deletions(-)
> 
> Eric W. Biederman (5):
>       nsenter: Enhance waiting for a child process
>       nsenter: Properly spell significant in a comment.
>       nsenter: Add const to declarations where possible.
>       nsenter: Replace a bare strtoul with strtoul_or_err
>       unshare,nsenter:  Move the old libc handling into a common header namespace.h

 All applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] unshare: Add support for the pid and user namespaces
  2013-01-17 12:35     ` Karel Zak
@ 2013-01-17 12:56       ` Eric W. Biederman
  0 siblings, 0 replies; 24+ messages in thread
From: Eric W. Biederman @ 2013-01-17 12:56 UTC (permalink / raw)
  To: Karel Zak
  Cc: util-linux, Neil Horman, Serge E. Hallyn, Michael Kerrisk (man-pages)

Karel Zak <kzak@redhat.com> writes:

> On Fri, Jan 11, 2013 at 02:53:34PM -0800, Eric W. Biederman wrote:
>>  sys-utils/unshare.1 |   19 +++++++++++++++----
>>  sys-utils/unshare.c |   27 ++++++++++++++++++---------
>>  2 files changed, 33 insertions(+), 13 deletions(-)
>
>  Applied, thanks.

I was begining to wonder as one of the later patches you applied was on
top of this one.

Thanks for getting all of these.

Eric

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2013-01-17 12:56 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-11 10:29 [PATCH] enter: new command (light wrapper around setns) Eric W. Biederman
2013-01-11 10:54 ` Michael Kerrisk (man-pages)
2013-01-11 11:10   ` Eric W. Biederman
2013-01-11 13:13     ` Ángel González
2013-01-12  8:59     ` Michael Kerrisk (man-pages)
2013-01-11 16:13 ` Karel Zak
2013-01-11 22:11   ` Eric W. Biederman
2013-01-12  9:01     ` Michael Kerrisk (man-pages)
2013-01-11 22:46   ` [PATCH] nsenter: " Eric W. Biederman
2013-01-11 23:45     ` Mike Frysinger
2013-01-14  8:28       ` Karel Zak
2013-01-17  0:33         ` [PATCH 0/5] nsenter review comment fixes Eric W. Biederman
2013-01-17  0:34           ` [PATCH 1/5] nsenter: Enhance waiting for a child process Eric W. Biederman
2013-01-17  0:34           ` [PATCH 2/5] nsenter: Properly spell significant in a comment Eric W. Biederman
2013-01-17  0:35           ` [PATCH 3/5] nsenter: Add const to declarations where possible Eric W. Biederman
2013-01-17  0:35           ` [PATCH 4/5] nsenter: Replace a bare strtoul with strtoul_or_err Eric W. Biederman
2013-01-17  0:36           ` [PATCH 5/5] unshare,nsenter: Move the old libc handling into a common header namespace.h Eric W. Biederman
2013-01-17  3:11           ` [PATCH 0/5] nsenter review comment fixes Mike Frysinger
2013-01-17 12:35           ` Karel Zak
2013-01-15 18:51     ` [PATCH] nsenter: new command (light wrapper around setns) Serge E. Hallyn
2013-01-17 12:34     ` Karel Zak
2013-01-11 22:53   ` [PATCH] unshare: Add support for the pid and user namespaces Eric W. Biederman
2013-01-17 12:35     ` Karel Zak
2013-01-17 12:56       ` Eric W. Biederman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.