linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nathan Lynch <ntl@pobox.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: linux-arch@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Linux Containers <containers@lists.osdl.org>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 2/7] ns: Introduce the setns syscall
Date: Wed, 11 May 2011 14:21:14 -0500	[thread overview]
Message-ID: <1305141681.1236.48.camel@orca.stoopid.dyndns.org> (raw)
In-Reply-To: <1304735101-1824-2-git-send-email-ebiederm@xmission.com>

Hi Eric,

On Fri, 2011-05-06 at 19:24 -0700, Eric W. Biederman wrote:
> With the networking stack today there is demand to handle
> multiple network stacks at a time.  Not in the context
> of containers but in the context of people doing interesting
> things with routing.
> 
> There is also demand in the context of containers to have
> an efficient way to execute some code in the container itself.
> If nothing else it is very useful ad a debugging technique.
> 
> Both problems can be solved by starting some form of login
> daemon in the namespaces people want access to, or you
> can play games by ptracing a process and getting the
> traced process to do things you want it to do. However
> it turns out that a login daemon or a ptrace puppet
> controller are more code, they are more prone to
> failure, and generally they are less efficient than
> simply changing the namespace of a process to a
> specified one.
> 
> Pieces of this puzzle can also be solved by instead of
> coming up with a general purpose system call coming up
> with targed system calls perhaps socketat that solve
> a subset of the larger problem.  Overall that appears
> to be more work for less reward.
> 
> int setns(int fd, int nstype);
> 
> The fd argument is a file descriptor referring to a proc
> file of the namespace you want to switch the process to.
> 
> In the setns system call the nstype is 0 or specifies
> an clone flag of the namespace you intend to change
> to prevent changing a namespace unintentionally.

I don't understand exactly what the nstype argument buys us - why would
correct code ever need to specify a value other than 0?  And reusing the
CLONE_NEW* values in this interface is kind of ugly when setns is
precisely _not_ creating new namespaces.

Is there some fundamental reason it couldn't be

int setns(int fd);

or is there a use case I'm missing?

 
> +SYSCALL_DEFINE2(setns, int, fd, int, nstype)
> +{
> +	const struct proc_ns_operations *ops;
> +	struct task_struct *tsk = current;
> +	struct nsproxy *new_nsproxy;
> +	struct proc_inode *ei;
> +	struct file *file;
> +	int err;
> +
> +	if (!capable(CAP_SYS_ADMIN))
> +		return -EPERM;
> +
> +	file = proc_ns_fget(fd);
> +	if (IS_ERR(file))
> +		return PTR_ERR(file);
> +
> +	err = -EINVAL;
> +	ei = PROC_I(file->f_dentry->d_inode);
> +	ops = ei->ns_ops;
> +	if (nstype && (ops->type != nstype))
> +		goto out;
> +
> +	new_nsproxy = create_new_namespaces(0, tsk, tsk->fs);

create_new_namespaces() can fail; shouldn't this be checked?


> +	err = ops->install(new_nsproxy, ei->ns);
> +	if (err) {
> +		free_nsproxy(new_nsproxy);
> +		goto out;
> +	}
> +	switch_task_namespaces(tsk, new_nsproxy);
> +out:
> +	fput(file);
> +	return err;
> +}
> +

  parent reply	other threads:[~2011-05-11 19:21 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-07  2:23 [PATCH 0/7] Network namespace manipulation with file descriptors Eric W. Biederman
2011-05-07  2:24 ` [PATCH 1/7] ns: proc files for namespace naming policy Eric W. Biederman
2011-05-07  2:24   ` [PATCH 3/7] ns proc: Add support for the network namespace Eric W. Biederman
2011-05-07  2:24     ` Eric W. Biederman
2011-05-07 22:41     ` Daniel Lezcano
2011-05-11 19:21     ` Nathan Lynch
2011-05-11 21:34       ` Eric W. Biederman
2011-05-11 21:42         ` Nathan Lynch
2011-05-07  2:24   ` [PATCH 4/7] ns proc: Add support for the uts namespace Eric W. Biederman
2011-05-07  2:24     ` Eric W. Biederman
2011-05-07 22:42     ` Daniel Lezcano
2011-05-07  2:24   ` [PATCH 5/7] ns proc: Add support for the ipc namespace Eric W. Biederman
2011-05-07  2:24     ` Eric W. Biederman
2011-05-07 22:44     ` Daniel Lezcano
     [not found]   ` <1304735101-1824-1-git-send-email-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2011-05-07  2:24     ` [PATCH 2/7] ns: Introduce the setns syscall Eric W. Biederman
2011-05-07  2:24       ` Eric W. Biederman
     [not found]       ` <1304735101-1824-2-git-send-email-ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2011-05-07  8:01         ` Rémi Denis-Courmont
2011-05-07  8:01           ` Rémi Denis-Courmont
2011-05-07 13:57           ` Eric W. Biederman
2011-05-07 13:57             ` Eric W. Biederman
2011-05-07 22:39       ` Daniel Lezcano
2011-05-08  3:51       ` Matt Helsley
2011-05-11 19:21       ` Nathan Lynch [this message]
2011-05-11 19:21         ` Nathan Lynch
2011-05-11 20:33         ` Eric W. Biederman
2011-05-11 20:33           ` Eric W. Biederman
2011-05-07  2:25     ` [PATCH 6/7] net: Allow setting the network namespace by fd Eric W. Biederman
2011-05-07  2:25       ` Eric W. Biederman
2011-05-07 22:46       ` Daniel Lezcano
2011-05-07 22:46         ` Daniel Lezcano
2011-05-07  2:25   ` [PATCH 7/7] ns: Wire up the setns system call Eric W. Biederman
2011-05-07  2:25     ` Eric W. Biederman
2011-05-07  8:27     ` Geert Uytterhoeven
2011-05-07 14:09       ` Eric W. Biederman
2011-05-07 14:09         ` Eric W. Biederman
2011-05-07 18:22         ` Geert Uytterhoeven
2011-05-07 18:22           ` Geert Uytterhoeven
2011-05-07 13:59     ` Mike Frysinger
2011-05-07 20:06     ` James Bottomley
2011-05-07 20:06       ` James Bottomley
2011-05-08  2:19       ` Eric W. Biederman
2011-05-08  4:02         ` James Bottomley
2011-05-08  4:02           ` James Bottomley
2011-05-07 22:37   ` [PATCH 1/7] ns: proc files for namespace naming policy Daniel Lezcano
2011-05-11 19:20   ` Nathan Lynch
2011-05-11 22:52     ` Eric W. Biederman
2011-05-11 22:52       ` Eric W. Biederman
     [not found] ` <m1tyd7p7tq.fsf-+imSwln9KH6u2/kzUuoCbdi2O/JbrIOy@public.gmane.org>
2011-05-07  6:58   ` [PATCH 0/7] Network namespace manipulation with file descriptors Alex Bligh
2011-05-07  6:58     ` Alex Bligh
2011-05-07 14:18     ` Eric W. Biederman
2011-05-07 14:18       ` Eric W. Biederman
2011-05-08 12:31       ` Alex Bligh
2011-05-08 12:31         ` Alex Bligh
     [not found]       ` <m1fwoqoapn.fsf-+imSwln9KH6u2/kzUuoCbdi2O/JbrIOy@public.gmane.org>
2011-05-17 11:11         ` David Lamparter
2011-05-17 11:11           ` David Lamparter
2011-05-17 14:33           ` Eric W. Biederman
2011-05-17 15:35             ` David Lamparter
2011-05-17 15:35               ` David Lamparter
2011-05-22  4:19               ` Renato Westphal
2011-05-22  4:19                 ` Renato Westphal
2011-05-09 19:04 ` David Miller
2011-05-09 19:59   ` Eric W. Biederman
2011-05-09 19:59     ` Eric W. Biederman
2011-05-09 20:40     ` David Miller
2011-05-09 20:54       ` Eric W. Biederman
2011-05-09 20:55         ` David Miller
2011-05-10 21:56       ` Luck, Tony
2011-05-10 23:02 ` Eric W. Biederman
2011-05-10 23:02   ` Eric W. Biederman
2011-05-18 12:43 ` Identifying network namespaces (was: Network namespace manipulation with file descriptors) David Lamparter
2011-05-18 13:03   ` Alexey Dobriyan
     [not found]     ` <BANLkTikmrC86hk=W84UBwhJLe_uGAN4w9w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-05-18 13:33       ` David Lamparter
2011-05-18 13:33         ` David Lamparter
2011-05-18 14:13         ` Alexey Dobriyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1305141681.1236.48.camel@orca.stoopid.dyndns.org \
    --to=ntl@pobox.com \
    --cc=containers@lists.osdl.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).