From: Christian Brauner <christian.brauner@ubuntu.com>
To: "Michal Koutný" <mkoutny@suse.com>
Cc: linux-kernel@vger.kernel.org,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Stéphane Graber" <stgraber@ubuntu.com>,
"Linux Containers" <containers@lists.linux-foundation.org>,
"Eric W . Biederman" <ebiederm@xmission.com>,
"Serge Hallyn" <serge@hallyn.com>, "Jann Horn" <jannh@google.com>,
"Michael Kerrisk" <mtk.manpages@gmail.com>,
"Aleksa Sarai" <cyphar@cyphar.com>,
linux-api@vger.kernel.org, systemd-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 2/3] nsproxy: attach to namespaces via pidfds
Date: Wed, 24 Jun 2020 13:54:56 +0200 [thread overview]
Message-ID: <20200624115456.rvzlgn77jol2a2oc@wittgenstein> (raw)
In-Reply-To: <20200624114437.GA117125@blackbook>
On Wed, Jun 24, 2020 at 01:44:37PM +0200, Michal Koutný wrote:
> Hi.
>
> On Tue, May 05, 2020 at 04:04:31PM +0200, Christian Brauner <christian.brauner@ubuntu.com> wrote:
> > -SYSCALL_DEFINE2(setns, int, fd, int, nstype)
> > +SYSCALL_DEFINE2(setns, int, fd, int, flags)
> > [...]
> > - file = proc_ns_fget(fd);
> > - if (IS_ERR(file))
> > - return PTR_ERR(file);
> > + int err = 0;
> >
> > - err = -EINVAL;
> > - ns = get_proc_ns(file_inode(file));
> > - if (nstype && (ns->ops->type != nstype))
> > + file = fget(fd);
> > + if (!file)
> > + return -EBADF;
> > +
> > + if (proc_ns_file(file)) {
> > + ns = get_proc_ns(file_inode(file));
> > + if (flags && (ns->ops->type != flags))
> > + err = -EINVAL;
> > + flags = ns->ops->type;
> > + } else if (pidfd_pid(file)) {
> > + err = check_setns_flags(flags);
> > + } else {
> > + err = -EBADF;
> > + }
> > + if (err)
> > goto out;
> >
> > - err = prepare_nsset(ns->ops->type, &nsset);
> > + err = prepare_nsset(flags, &nsset);
> > if (err)
> > goto out;
> This modification changed the returned error when a valid file
> descriptor is passed but it doesn't represent a namespace (nor pidfd).
> The error is now EBADF although originally and per man page it
> was/should be EINVAL.
>
> A change like below would restore it, however, I see it may be less
> consistent with other pidfd calls(?), then I'd suggest updating the
> manpage to capture this.
>
> --- a/kernel/nsproxy.c
> +++ b/kernel/nsproxy.c
> @@ -531,7 +531,7 @@ SYSCALL_DEFINE2(setns, int, fd, int, flags)
> } else if (!IS_ERR(pidfd_pid(file))) {
> err = check_setns_flags(flags);
> } else {
> - err = -EBADF;
> + err = -EINVAL;
> }
> if (err)
> goto out;
>
> I noticed this breaks systemd self tests [1].
Yep, I already have a fix for this in my tree based on a previous report
from LTP. It's sitting in linux-next:
https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=fixes&id=e571d4ee334719727f22cce30c4c74471d4ef68a
with selftests:
https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=fixes&id=86f56395feb2b106b125c47e72192e37da5dd088
I'll send it to Linus this week.
Thanks!
Christian
next prev parent reply other threads:[~2020-06-24 11:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-05 14:04 [PATCH v4 0/3] nsproxy: attach to multiple namespaces Christian Brauner
2020-05-05 14:04 ` [PATCH v4 1/3] nsproxy: add struct nsset Christian Brauner
2020-05-08 4:04 ` Serge E. Hallyn
2020-05-05 14:04 ` [PATCH v4 2/3] nsproxy: attach to namespaces via pidfds Christian Brauner
2020-05-08 4:30 ` Serge E. Hallyn
2020-06-24 11:44 ` Michal Koutný
2020-06-24 11:54 ` Christian Brauner [this message]
2020-06-24 12:01 ` Michal Koutný
2020-05-05 14:04 ` [PATCH v4 3/3] selftests/pidfd: add pidfd setns tests Christian Brauner
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=20200624115456.rvzlgn77jol2a2oc@wittgenstein \
--to=christian.brauner@ubuntu.com \
--cc=containers@lists.linux-foundation.org \
--cc=cyphar@cyphar.com \
--cc=ebiederm@xmission.com \
--cc=jannh@google.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=mtk.manpages@gmail.com \
--cc=serge@hallyn.com \
--cc=stgraber@ubuntu.com \
--cc=systemd-devel@lists.freedesktop.org \
--cc=viro@zeniv.linux.org.uk \
/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