From: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>, Amir Goldstein <amir73il@gmail.com>,
linux-fsdevel@vger.kernel.org
Cc: "Josef Bacik" <josef@toxicpanda.com>,
"Jeff Layton" <jlayton@kernel.org>, "Mike Yuan" <me@yhndnzj.com>,
"Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>,
"Lennart Poettering" <mzxreary@0pointer.de>,
"Daan De Meyer" <daan.j.demeyer@gmail.com>,
"Aleksa Sarai" <cyphar@cyphar.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Jens Axboe" <axboe@kernel.dk>, "Tejun Heo" <tj@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Chuck Lever" <chuck.lever@oracle.com>,
linux-nfs@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
cgroups@vger.kernel.org, netdev@vger.kernel.org,
"Christian Brauner" <brauner@kernel.org>,
"Thomas Gleixner" <tglx@linutronix.de>
Subject: [PATCH v2 00/33] ns: support file handles
Date: Fri, 12 Sep 2025 13:52:23 +0200 [thread overview]
Message-ID: <20250912-work-namespace-v2-0-1a247645cef5@kernel.org> (raw)
For a while now we have supported file handles for pidfds. This has
proven to be very useful.
Extend the concept to cover namespaces as well. After this patchset it
is possible to encode and decode namespace file handles using the
commong name_to_handle_at() and open_by_handle_at() apis.
Namespaces file descriptors can already be derived from pidfds which
means they aren't subject to overmount protection bugs. IOW, it's
irrelevant if the caller would not have access to an appropriate
/proc/<pid>/ns/ directory as they could always just derive the namespace
based on a pidfd already.
It has the same advantage as pidfds. It's possible to reliably and for
the lifetime of the system refer to a namespace without pinning any
resources and to compare them.
Permission checking is kept simple. If the caller is located in the
namespace the file handle refers to they are able to open it otherwise
they must hold privilege over the owning namespace of the relevant
namespace.
Both the network namespace and the mount namespace already have an
associated cookie that isn't recycled and is fully exposed to userspace.
Move this into ns_common and use the same id space for all namespaces so
they can trivially and reliably be compared.
There's more coming based on the iterator infrastructure but the series
is large enough and focuses on file handles.
Extensive selftests included.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
Changes in v2:
- Address various review comments.
- Use a common NS_GET_ID ioctl() instead of individual ioctls.
- Link to v1: https://lore.kernel.org/20250910-work-namespace-v1-0-4dd56e7359d8@kernel.org
---
Christian Brauner (33):
pidfs: validate extensible ioctls
nsfs: drop tautological ioctl() check
nsfs: validate extensible ioctls
block: use extensible_ioctl_valid()
ns: move to_ns_common() to ns_common.h
nsfs: add nsfs.h header
ns: uniformly initialize ns_common
cgroup: use ns_common_init()
ipc: use ns_common_init()
mnt: use ns_common_init()
net: use ns_common_init()
pid: use ns_common_init()
time: use ns_common_init()
user: use ns_common_init()
uts: use ns_common_init()
ns: remove ns_alloc_inum()
nstree: make iterator generic
mnt: support ns lookup
cgroup: support ns lookup
ipc: support ns lookup
net: support ns lookup
pid: support ns lookup
time: support ns lookup
user: support ns lookup
uts: support ns lookup
ns: add to_<type>_ns() to respective headers
nsfs: add current_in_namespace()
nsfs: support file handles
nsfs: support exhaustive file handles
nsfs: add missing id retrieval support
tools: update nsfs.h uapi header
selftests/namespaces: add identifier selftests
selftests/namespaces: add file handle selftests
block/blk-integrity.c | 8 +-
fs/fhandle.c | 6 +
fs/internal.h | 1 +
fs/mount.h | 10 +-
fs/namespace.c | 156 +--
fs/nsfs.c | 201 ++-
fs/pidfs.c | 2 +-
include/linux/cgroup.h | 5 +
include/linux/exportfs.h | 6 +
include/linux/fs.h | 14 +
include/linux/ipc_namespace.h | 5 +
include/linux/ns_common.h | 29 +
include/linux/nsfs.h | 40 +
include/linux/nsproxy.h | 11 -
include/linux/nstree.h | 89 ++
include/linux/pid_namespace.h | 5 +
include/linux/proc_ns.h | 32 +-
include/linux/time_namespace.h | 9 +
include/linux/user_namespace.h | 5 +
include/linux/utsname.h | 5 +
include/net/net_namespace.h | 6 +
include/uapi/linux/fcntl.h | 1 +
include/uapi/linux/nsfs.h | 15 +-
init/main.c | 2 +
ipc/msgutil.c | 1 +
ipc/namespace.c | 12 +-
ipc/shm.c | 2 +
kernel/Makefile | 2 +-
kernel/cgroup/cgroup.c | 2 +
kernel/cgroup/namespace.c | 24 +-
kernel/nstree.c | 233 ++++
kernel/pid_namespace.c | 13 +-
kernel/time/namespace.c | 23 +-
kernel/user_namespace.c | 17 +-
kernel/utsname.c | 28 +-
net/core/net_namespace.c | 59 +-
tools/include/uapi/linux/nsfs.h | 17 +-
tools/testing/selftests/namespaces/.gitignore | 2 +
tools/testing/selftests/namespaces/Makefile | 7 +
tools/testing/selftests/namespaces/config | 7 +
.../selftests/namespaces/file_handle_test.c | 1429 ++++++++++++++++++++
tools/testing/selftests/namespaces/nsid_test.c | 986 ++++++++++++++
42 files changed, 3257 insertions(+), 270 deletions(-)
---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250905-work-namespace-c68826dda0d4
next reply other threads:[~2025-09-12 11:53 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 11:52 Christian Brauner [this message]
2025-09-12 11:52 ` [PATCH v2 01/33] pidfs: validate extensible ioctls Christian Brauner
2025-09-12 11:52 ` [PATCH v2 02/33] nsfs: drop tautological ioctl() check Christian Brauner
2025-09-12 11:52 ` [PATCH v2 03/33] nsfs: validate extensible ioctls Christian Brauner
2025-09-12 11:52 ` [PATCH v2 04/33] block: use extensible_ioctl_valid() Christian Brauner
2025-09-16 11:18 ` Mark Brown
2025-09-16 13:40 ` Dan Carpenter
2025-09-18 13:17 ` Jan Kara
2025-09-19 12:28 ` Christian Brauner
2025-09-12 11:52 ` [PATCH v2 05/33] ns: move to_ns_common() to ns_common.h Christian Brauner
2025-09-12 11:52 ` [PATCH v2 06/33] nsfs: add nsfs.h header Christian Brauner
2025-09-12 11:52 ` [PATCH v2 07/33] ns: uniformly initialize ns_common Christian Brauner
2025-09-12 11:52 ` [PATCH v2 08/33] cgroup: use ns_common_init() Christian Brauner
2025-09-12 15:48 ` Tejun Heo
2025-09-12 11:52 ` [PATCH v2 09/33] ipc: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 10/33] mnt: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 11/33] net: " Christian Brauner
2025-09-15 11:07 ` Jan Kara
2025-09-15 11:42 ` Christian Brauner
2025-09-15 11:50 ` Jan Kara
2025-09-15 22:59 ` Al Viro
2025-09-12 11:52 ` [PATCH v2 12/33] pid: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 13/33] time: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 14/33] user: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 15/33] uts: " Christian Brauner
2025-09-12 11:52 ` [PATCH v2 16/33] ns: remove ns_alloc_inum() Christian Brauner
2025-09-12 11:52 ` [PATCH v2 17/33] nstree: make iterator generic Christian Brauner
2025-09-15 11:49 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 18/33] mnt: support ns lookup Christian Brauner
2025-09-15 11:48 ` Jan Kara
2025-09-15 13:45 ` Christian Brauner
2025-09-16 3:24 ` Kuniyuki Iwashima
2025-09-16 3:59 ` Al Viro
2025-09-16 3:56 ` Al Viro
2025-09-16 3:59 ` Al Viro
2025-09-16 4:46 ` Al Viro
2025-09-17 9:50 ` Christian Brauner
2025-09-18 10:21 ` Al Viro
2025-09-12 11:52 ` [PATCH v2 19/33] cgroup: " Christian Brauner
2025-09-15 11:53 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 20/33] ipc: " Christian Brauner
2025-09-15 11:56 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 21/33] net: " Christian Brauner
2025-09-15 12:02 ` Jan Kara
2025-09-15 13:47 ` Christian Brauner
2025-09-16 3:59 ` Kuniyuki Iwashima
2025-09-12 11:52 ` [PATCH v2 22/33] pid: " Christian Brauner
2025-09-15 12:04 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 23/33] time: " Christian Brauner
2025-09-15 12:06 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 24/33] user: " Christian Brauner
2025-09-15 12:11 ` Jan Kara
2025-09-15 13:54 ` Christian Brauner
2025-09-15 14:14 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 25/33] uts: " Christian Brauner
2025-09-15 12:59 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 26/33] ns: add to_<type>_ns() to respective headers Christian Brauner
2025-09-15 12:06 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 27/33] nsfs: add current_in_namespace() Christian Brauner
2025-09-15 13:08 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 28/33] nsfs: support file handles Christian Brauner
2025-09-15 13:25 ` Jan Kara
2025-09-15 13:55 ` Christian Brauner
2025-09-12 11:52 ` [PATCH v2 29/33] nsfs: support exhaustive " Christian Brauner
2025-09-15 13:26 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 30/33] nsfs: add missing id retrieval support Christian Brauner
2025-09-15 13:28 ` Jan Kara
2025-09-12 11:52 ` [PATCH v2 31/33] tools: update nsfs.h uapi header Christian Brauner
2025-09-12 11:52 ` [PATCH v2 32/33] selftests/namespaces: add identifier selftests Christian Brauner
2025-09-12 11:52 ` [PATCH v2 33/33] selftests/namespaces: add file handle selftests Christian Brauner
2025-09-16 4:55 ` [PATCH v2 00/33] ns: support file handles Al Viro
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=20250912-work-namespace-v2-0-1a247645cef5@kernel.org \
--to=brauner@kernel.org \
--cc=amir73il@gmail.com \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=chuck.lever@oracle.com \
--cc=cyphar@cyphar.com \
--cc=daan.j.demeyer@gmail.com \
--cc=edumazet@google.com \
--cc=hannes@cmpxchg.org \
--cc=horms@kernel.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kuba@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=me@yhndnzj.com \
--cc=mkoutny@suse.com \
--cc=mzxreary@0pointer.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=zbyszek@in.waw.pl \
/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).