From: Christian Brauner <christian.brauner@ubuntu.com>
To: "Eric W. Biederman" <ebiederm@xmission.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>,
"Serge Hallyn" <serge@hallyn.com>,
"Aleksa Sarai" <cyphar@cyphar.com>
Subject: Re: [PATCH] nsproxy: attach to namespaces via pidfds
Date: Mon, 27 Apr 2020 18:11:47 +0200 [thread overview]
Message-ID: <20200427161147.6mtsweiw4nrq3cl6@wittgenstein> (raw)
In-Reply-To: <87sggpeyy4.fsf@x220.int.ebiederm.org>
On Mon, Apr 27, 2020 at 10:21:55AM -0500, Eric W. Biederman wrote:
>
> I am still catching up on the what exists for pidfd. Do you have a way
> to safely go from a pidfd to the corresponding proc directory?
Yep, that's possible. The pidfd's fdinfo file contains the same format
for the Pid: and NSpid: fields as /proc/<pid>/status. Here's e.g. what
systemd is doing currently:
int pidfd_get_pid(int fd, pid_t *ret) {
char path[STRLEN("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)];
_cleanup_free_ char *fdinfo = NULL;
char *p;
int r;
if (fd < 0)
return -EBADF;
xsprintf(path, "/proc/self/fdinfo/%i", fd);
r = read_full_file(path, &fdinfo, NULL);
if (r == -ENOENT) /* if fdinfo doesn't exist we assume the process does not exist */
return -ESRCH;
if (r < 0)
return r;
p = startswith(fdinfo, "Pid:");
if (!p) {
p = strstr(fdinfo, "\nPid:");
if (!p)
return -ENOTTY; /* not a pidfd? */
p += 5;
}
p += strspn(p, WHITESPACE);
p[strcspn(p, WHITESPACE)] = 0;
return parse_pid(p, ret);
}
>
> That would make this setns work just an optimization. A nice one but
> just an optimization.
Hm, I tried to describe how it's not just a worthwhile optimization
because it gets the number of syscalls down from 14 to a single syscall
which is kinda excellent for something like attach/exec into a container
which is a fairly common operation but it also gives us a couple of
other nice properties such as atomic attach and appearing in all
namespace at the same time similar to clone with all namespace flags
set.
Thanks!
Christian
next prev parent reply other threads:[~2020-04-27 16:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-27 14:36 Christian Brauner
2020-04-27 15:21 ` Eric W. Biederman
2020-04-27 16:11 ` Christian Brauner [this message]
2020-04-27 17:28 ` Jann Horn
2020-04-27 18:15 ` Christian Brauner
2020-04-27 19:41 ` Jann Horn
2020-04-27 19:48 ` Christian Brauner
2020-04-27 20:06 ` Michael Kerrisk (man-pages)
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=20200427161147.6mtsweiw4nrq3cl6@wittgenstein \
--to=christian.brauner@ubuntu.com \
--cc=containers@lists.linux-foundation.org \
--cc=cyphar@cyphar.com \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=stgraber@ubuntu.com \
--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
all inboxes | Powered by JetHome®