ns: support file handles
Get series with b4
b4 am [email protected] change-id 20250905-work-namespace-c68826dda0d4Versions newest first
- v2 Latest33 patches 37 repliesIn review
- v132 patches 47 repliesSuperseded
Changes in v2 from the cover letter
- Address various review comments.
- Use a common NS_GET_ID ioctl() instead of individual ioctls.
- Link to v1: https://lore.kernel.org/[email protected]
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/33 | pidfs: validate extensible ioctlsfs/ include/ | +15 | 0 replies | |
| 2/33 | nsfs: drop tautological ioctl() checkfs/ | +1 | 0 replies | |
| 3/33 | nsfs: validate extensible ioctlsfs/ | +3 | 0 replies | |
| 4/33 | block: use extensible_ioctl_valid()block/ | +3 | 4 replies | |
| 5/33 | ns: move to_ns_common() to ns_common.hinclude/ include/ | +20 | 0 replies | |
| 6/33 | nsfs: add nsfs.h headerinclude/ include/ | +27 | 0 replies | |
| 7/33 | ns: uniformly initialize ns_commoninclude/ | +16 | 0 replies | |
| 8/33 | cgroup: use ns_common_init()kernel/ | +4 | 1 reply | |
| 9/33 | ipc: use ns_common_init()ipc/ | +1 | 0 replies | |
| 10/33 | mnt: use ns_common_init()fs/ | +6 | 0 replies | |
| 11/33 | net: use ns_common_init()net/ | +33 | 4 replies | |
| 12/33 | pid: use ns_common_init()kernel/ | +1 | 0 replies | |
| 13/33 | time: use ns_common_init()kernel/ | +2 | 0 replies | |
| 14/33 | user: use ns_common_init()kernel/ | +2 | 0 replies | |
| 15/33 | uts: use ns_common_init()kernel/ | +2 | 0 replies | |
| 16/33 | ns: remove ns_alloc_inum()include/ | +0 | 0 replies | |
| 17/33 | nstree: make iterator genericinclude/ include/ include/ +2 more | +335 | 1 reply | |
| 18/33 | mnt: support ns lookupfs/ fs/ fs/ | +35 | 9 replies | |
| 19/33 | cgroup: support ns lookupkernel/ kernel/ | +7 | 1 reply | |
| 20/33 | ipc: support ns lookupipc/ ipc/ ipc/ | +6 | 1 reply | |
| 21/33 | net: support ns lookupinclude/ net/ | +7 | 3 replies | |
| 22/33 | pid: support ns lookupkernel/ | +4 | 1 reply | |
| 23/33 | time: support ns lookupinclude/ init/ kernel/ | +17 | 1 reply | |
| 24/33 | user: support ns lookupkernel/ | +6 | 3 replies | |
| 25/33 | uts: support ns lookupkernel/ | +6 | 1 reply | |
| 26/33 | ns: add to_<type>_ns() to respective headersinclude/ include/ include/ +11 more | +34 | 1 reply | |
| 27/33 | nsfs: add current_in_namespace()include/ | +15 | 1 reply | |
| 28/33 | nsfs: support file handlesfs/ include/ include/ | +173 | 2 replies | |
| 29/33 | nsfs: support exhaustive file handlesfs/ fs/ fs/ +1 more | +18 | 1 reply | |
| 30/33 | nsfs: add missing id retrieval supportfs/ include/ | +17 | 1 reply | |
| 31/33 | tools: update nsfs.h uapi headertools/ | +15 | 0 replies | |
| 32/33 | selftests/namespaces: add identifier selfteststools/ tools/ tools/ +1 more | +1001 | 0 replies | |
| 33/33 | selftests/namespaces: add file handle selfteststools/ tools/ tools/ | +1431 | 0 replies |
Reviews trailers per patch
30 of 33 patches have a Reviewed-by or Acked-by.
| Patch | Aleksa Sarai | Jan Kara | Jens Axboe | Thomas Gleixner | Tejun Heo | Amir Goldstein |
|---|---|---|---|---|---|---|
| 1/33 | R-b | R-b | ||||
| 2/33 | ||||||
| 3/33 | R-b | |||||
| 4/33 | R-b | R-b | ||||
| 5/33 | R-b | |||||
| 6/33 | R-b | |||||
| 7/33 | R-b | |||||
| 8/33 | R-b | A-b | ||||
| 9/33 | R-b | |||||
| 10/33 | R-b | |||||
| 11/33 | R-b | |||||
| 12/33 | R-b | |||||
| 13/33 | R-b | R-b | ||||
| 14/33 | R-b | |||||
| 15/33 | R-b | |||||
| 16/33 | R-b | |||||
| 17/33 | R-b | |||||
| 18/33 | R-b | |||||
| 19/33 | R-b | A-b | ||||
| 20/33 | R-b | |||||
| 21/33 | R-b | |||||
| 22/33 | R-b | |||||
| 23/33 | R-b | R-b | ||||
| 24/33 | R-b | |||||
| 25/33 | R-b | |||||
| 26/33 | R-b | R-b | ||||
| 27/33 | R-b | R-b | ||||
| 28/33 | R-b | R-b | ||||
| 29/33 | R-b | R-b | ||||
| 30/33 | R-b | |||||
| 31/33 | ||||||
| 32/33 | ||||||
| 33/33 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 6 reviewers.
Cover letter [PATCH v2 00/33] ns: support file handles
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.
---
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/[email protected]
---
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