From: Serge Hallyn <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
To: Chen Hanxiao <chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Eric W. Biederman"
<ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
Subject: Re: [PATCH RFC] setns: return 0 directly if try to reassociate with current namespace
Date: Wed, 8 Oct 2014 14:57:40 +0000 [thread overview]
Message-ID: <20141008145740.GD30569@ubuntumail> (raw)
In-Reply-To: <1412759587-21320-1-git-send-email-chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
Quoting Chen Hanxiao (chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org):
> We could use setns to join the current ns,
> which did a lot of unnecessary work.
> This patch will check this senario and
> return 0 directly.
>
> Signed-off-by: Chen Hanxiao <chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
Plus it's just asking for trouble.
I would ack this, except you need to fclose(file) on the
return paths. So just set err = 0 and goto out.
> ---
> kernel/nsproxy.c | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
> index ef42d0a..66eea63 100644
> --- a/kernel/nsproxy.c
> +++ b/kernel/nsproxy.c
> @@ -236,6 +236,34 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
> ops = ei->ns_ops;
> if (nstype && (ops->type != nstype))
> goto out;
> + switch (ops->type) {
> + case CLONE_NEWIPC:
> + if (ei->ns == tsk->nsproxy->ipc_ns)
> + return 0;
> + break;
> + case CLONE_NEWNET:
> + if (ei->ns == tsk->nsproxy->net_ns)
> + return 0;
> + break;
> + case CLONE_NEWNS:
> + if (ei->ns == tsk->nsproxy->mnt_ns)
> + return 0;
> + break;
> + case CLONE_NEWPID:
> + if (ei->ns == tsk->nsproxy->pid_ns_for_children)
> + return 0;
> + break;
> + case CLONE_NEWUSER:
> + if (ei->ns == current_user_ns())
> + return 0;
> + break;
> + case CLONE_NEWUTS:
> + if (ei->ns == tsk->nsproxy->uts_ns)
> + return 0;
> + break;
> + default:
> + goto out;
> + }
>
> new_nsproxy = create_new_namespaces(0, tsk, current_user_ns(), tsk->fs);
> if (IS_ERR(new_nsproxy)) {
> --
> 1.9.0
>
WARNING: multiple messages have this Message-ID (diff)
From: Serge Hallyn <serge.hallyn@ubuntu.com>
To: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Cc: containers@lists.linux-foundation.org,
linux-kernel@vger.kernel.org,
"Eric W. Biederman" <ebiederm@xmission.com>
Subject: Re: [PATCH RFC] setns: return 0 directly if try to reassociate with current namespace
Date: Wed, 8 Oct 2014 14:57:40 +0000 [thread overview]
Message-ID: <20141008145740.GD30569@ubuntumail> (raw)
In-Reply-To: <1412759587-21320-1-git-send-email-chenhanxiao@cn.fujitsu.com>
Quoting Chen Hanxiao (chenhanxiao@cn.fujitsu.com):
> We could use setns to join the current ns,
> which did a lot of unnecessary work.
> This patch will check this senario and
> return 0 directly.
>
> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Plus it's just asking for trouble.
I would ack this, except you need to fclose(file) on the
return paths. So just set err = 0 and goto out.
> ---
> kernel/nsproxy.c | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
> index ef42d0a..66eea63 100644
> --- a/kernel/nsproxy.c
> +++ b/kernel/nsproxy.c
> @@ -236,6 +236,34 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
> ops = ei->ns_ops;
> if (nstype && (ops->type != nstype))
> goto out;
> + switch (ops->type) {
> + case CLONE_NEWIPC:
> + if (ei->ns == tsk->nsproxy->ipc_ns)
> + return 0;
> + break;
> + case CLONE_NEWNET:
> + if (ei->ns == tsk->nsproxy->net_ns)
> + return 0;
> + break;
> + case CLONE_NEWNS:
> + if (ei->ns == tsk->nsproxy->mnt_ns)
> + return 0;
> + break;
> + case CLONE_NEWPID:
> + if (ei->ns == tsk->nsproxy->pid_ns_for_children)
> + return 0;
> + break;
> + case CLONE_NEWUSER:
> + if (ei->ns == current_user_ns())
> + return 0;
> + break;
> + case CLONE_NEWUTS:
> + if (ei->ns == tsk->nsproxy->uts_ns)
> + return 0;
> + break;
> + default:
> + goto out;
> + }
>
> new_nsproxy = create_new_namespaces(0, tsk, current_user_ns(), tsk->fs);
> if (IS_ERR(new_nsproxy)) {
> --
> 1.9.0
>
next prev parent reply other threads:[~2014-10-08 14:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-08 9:13 [PATCH RFC] setns: return 0 directly if try to reassociate with current namespace Chen Hanxiao
2014-10-08 9:13 ` Chen Hanxiao
[not found] ` <1412759587-21320-1-git-send-email-chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2014-10-08 14:57 ` Serge Hallyn [this message]
2014-10-08 14:57 ` Serge Hallyn
2014-10-08 17:55 ` Eric W. Biederman
2014-10-08 17:55 ` Eric W. Biederman
[not found] ` <87r3yih2e2.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2014-10-08 20:13 ` Serge Hallyn
2014-10-08 20:13 ` Serge Hallyn
2014-10-09 4:14 ` Chen, Hanxiao
2014-10-09 4:14 ` Chen, Hanxiao
[not found] ` <5871495633F38949900D2BF2DC04883E5E0FAC-ZEd+hNNJ6a5ZYpXjqAkB5jz3u5zwRJJDAzI0kPv9QBlmR6Xm/wNWPw@public.gmane.org>
2014-10-09 5:52 ` Eric W. Biederman
2014-10-09 5:52 ` Eric W. Biederman
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=20141008145740.GD30569@ubuntumail \
--to=serge.hallyn-gewih/nmzzlqt0dzr+alfa@public.gmane.org \
--cc=chenhanxiao-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.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 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.