#
18b19abc |
| 29-Sep-2025 |
Linus Torvalds <torvalds@linux-foundation.org> |
Merge tag 'namespace-6.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull namespace updates from Christian Brauner: "This contains a larger set of changes around the generic name
Merge tag 'namespace-6.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull namespace updates from Christian Brauner: "This contains a larger set of changes around the generic namespace infrastructure of the kernel.
Each specific namespace type (net, cgroup, mnt, ...) embedds a struct ns_common which carries the reference count of the namespace and so on.
We open-coded and cargo-culted so many quirks for each namespace type that it just wasn't scalable anymore. So given there's a bunch of new changes coming in that area I've started cleaning all of this up.
The core change is to make it possible to correctly initialize every namespace uniformly and derive the correct initialization settings from the type of the namespace such as namespace operations, namespace type and so on. This leaves the new ns_common_init() function with a single parameter which is the specific namespace type which derives the correct parameters statically. This also means the compiler will yell as soon as someone does something remotely fishy.
The ns_common_init() addition also allows us to remove ns_alloc_inum() and drops any special-casing of the initial network namespace in the network namespace initialization code that Linus complained about.
Another part is reworking the reference counting. The reference counting was open-coded and copy-pasted for each namespace type even though they all followed the same rules. This also removes all open accesses to the reference count and makes it private and only uses a very small set of dedicated helpers to manipulate them just like we do for e.g., files.
In addition this generalizes the mount namespace iteration infrastructure introduced a few cycles ago. As reminder, the vfs makes it possible to iterate sequentially and bidirectionally through all mount namespaces on the system or all mount namespaces that the caller holds privilege over. This allow userspace to iterate over all mounts in all mount namespaces using the listmount() and statmount() system call.
Each mount namespace has a unique identifier for the lifetime of the systems that is exposed to userspace. The network namespace also has a unique identifier working exactly the same way. This extends the concept to all other namespace types.
The new nstree type makes it possible to lookup namespaces purely by their identifier and to walk the namespace list sequentially and bidirectionally for all namespace types, allowing userspace to iterate through all namespaces. Looking up namespaces in the namespace tree works completely locklessly.
This also means we can move the mount namespace onto the generic infrastructure and remove a bunch of code and members from struct mnt_namespace itself.
There's a bunch of stuff coming on top of this in the future but for now this uses the generic namespace tree to extend a concept introduced first for pidfs a few cycles ago. For a while now we have supported pidfs file handles for pidfds. This has proven to be very useful.
This extends the concept to cover namespaces as well. It is possible to encode and decode namespace file handles using the common name_to_handle_at() and open_by_handle_at() apis.
As with pidfs file handles, namespace file handles are exhaustive, meaning it is not required to actually hold a reference to nsfs in able to decode aka open_by_handle_at() a namespace file handle. Instead the FD_NSFS_ROOT constant can be passed which will let the kernel grab a reference to the root of nsfs internally and thus decode the file handle.
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 trivially.
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.
The namespace file handle layout is exposed as uapi and has a stable and extensible format. For now it simply contains the namespace identifier, the namespace type, and the inode number. The stable format means that userspace may construct its own namespace file handles without going through name_to_handle_at() as they are already allowed for pidfs and cgroup file handles"
* tag 'namespace-6.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (65 commits) ns: drop assert ns: move ns type into struct ns_common nstree: make struct ns_tree private ns: add ns_debug() ns: simplify ns_common_init() further cgroup: add missing ns_common include ns: use inode initializer for initial namespaces selftests/namespaces: verify initial namespace inode numbers ns: rename to __ns_ref nsfs: port to ns_ref_*() helpers net: port to ns_ref_*() helpers uts: port to ns_ref_*() helpers ipv4: use check_net() net: use check_net() net-sysfs: use check_net() user: port to ns_ref_*() helpers time: port to ns_ref_*() helpers pid: port to ns_ref_*() helpers ipc: port to ns_ref_*() helpers cgroup: port to ns_ref_*() helpers ...
show more ...
|
Revision tags: v6.17 |
|
#
6e65f4e8 |
| 25-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
Merge patch series "ns: tweak ns common handling"
Christian Brauner <brauner@kernel.org> says:
This contains three minor tweaks for namespace handling:
* Make struct ns_tree private. There's no ne
Merge patch series "ns: tweak ns common handling"
Christian Brauner <brauner@kernel.org> says:
This contains three minor tweaks for namespace handling:
* Make struct ns_tree private. There's no need for anything to access that directly.
* Drop a debug assert that would trigger in conditions that are benign.
* Move the type of the namespace out of struct proc_ns_operations and into struct ns_common. This eliminates a pointer dereference and also allows assertions to work when the namespace type is disabled and the operations field set to NULL.
* patches from https://lore.kernel.org/20250924-work-namespaces-fixes-v1-0-8fb682c8678e@kernel.org: ns: drop assert ns: move ns type into struct ns_common nstree: make struct ns_tree private
Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|
#
af075603 |
| 24-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
ns: drop assert
Otherwise we warn when e.g., no namespaces are configured but the initial namespace for is still around.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <braun
ns: drop assert
Otherwise we warn when e.g., no namespaces are configured but the initial namespace for is still around.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|
#
4055526d |
| 24-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
ns: move ns type into struct ns_common
It's misplaced in struct proc_ns_operations and ns->ops might be NULL if the namespace is compiled out but we still want to know the type of the namespace for
ns: move ns type into struct ns_common
It's misplaced in struct proc_ns_operations and ns->ops might be NULL if the namespace is compiled out but we still want to know the type of the namespace for the initial namespace struct.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|
#
d969328c |
| 22-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
Merge patch series "ns: minor tweaks"
Christian Brauner <brauner@kernel.org> says:
* Add a missing include into the cgroup namespace header. * Simplify ns_common_init{_inum}() and derive the namesp
Merge patch series "ns: minor tweaks"
Christian Brauner <brauner@kernel.org> says:
* Add a missing include into the cgroup namespace header. * Simplify ns_common_init{_inum}() and derive the namespace operations from the namespace type. * Add debug asserts into ns_common_init{_inum}() to catch bugs.
* patches from https://lore.kernel.org/20250922-work-namespace-ns_common-fixes-v1-0-3c26aeb30831@kernel.org: ns: add ns_debug() ns: simplify ns_common_init() further cgroup: add missing ns_common include
Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|
#
5890f504 |
| 22-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
ns: add ns_debug()
Add ns_debug() that asserts that the correct operations are used for the namespace type.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
|
Revision tags: v6.17-rc7 |
|
#
1f84344c |
| 19-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
Merge patch series "ns: rework reference counting"
Christian Brauner <brauner@kernel.org> says:
Stop open accesses to the reference counts and cargo-culting the same code in all namespace. Use a se
Merge patch series "ns: rework reference counting"
Christian Brauner <brauner@kernel.org> says:
Stop open accesses to the reference counts and cargo-culting the same code in all namespace. Use a set of dedicated helpers and make the actual count private.
* patches from https://lore.kernel.org/20250918-work-namespace-ns_ref-v1-0-1b0a98ee041e@kernel.org: ns: rename to __ns_ref nsfs: port to ns_ref_*() helpers net: port to ns_ref_*() helpers uts: port to ns_ref_*() helpers ipv4: use check_net() net: use check_net() net-sysfs: use check_net() user: port to ns_ref_*() helpers time: port to ns_ref_*() helpers pid: port to ns_ref_*() helpers ipc: port to ns_ref_*() helpers cgroup: port to ns_ref_*() helpers mnt: port to ns_ref_*() helpers ns: add reference count helpers
Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|
#
024596a4 |
| 18-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
ns: rename to __ns_ref
Make it easier to grep and rename to ns_count.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
|
#
bb57289f |
| 19-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
Merge patch series "ns: rework common initialization"
Christian Brauner <brauner@kernel.org> says:
The current scheme still involves a lot of open-coding and copy-pasing and bleeds a lot of unneces
Merge patch series "ns: rework common initialization"
Christian Brauner <brauner@kernel.org> says:
The current scheme still involves a lot of open-coding and copy-pasing and bleeds a lot of unnecessary details into actual namespace implementers. Encapsulate it in the common helpers and simplify it all.
* patches from https://lore.kernel.org/20250917-work-namespace-ns_common-v1-0-1b3bda8ef8f2@kernel.org: ns: add ns_common_free() nscommon: simplify initialization net: centralize ns_common initialization mnt: simplify ns_common_init() handling nsfs: add inode number for anon namespace cgroup: split namespace into separate header nscommon: move to separate file mnt: expose pointer to init_mnt_ns uts: split namespace into separate header
Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|
#
be5f21d3 |
| 17-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
ns: add ns_common_free()
And drop ns_free_inum(). Anything common that can be wasted centrally should be wasted in the new common helper.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christi
ns: add ns_common_free()
And drop ns_free_inum(). Anything common that can be wasted centrally should be wasted in the new common helper.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|
#
5612ff3e |
| 17-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
nscommon: simplify initialization
There's a lot of information that namespace implementers don't need to know about at all. Encapsulate this all in the initialization helper.
Reviewed-by: Jan Kara
nscommon: simplify initialization
There's a lot of information that namespace implementers don't need to know about at all. Encapsulate this all in the initialization helper.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|
#
86cdbae5 |
| 17-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
mnt: simplify ns_common_init() handling
Assign the reserved MNT_NS_ANON_INO sentinel to anonymous mount namespaces and cleanup the initial mount ns allocation. This is just a preparatory patch and t
mnt: simplify ns_common_init() handling
Assign the reserved MNT_NS_ANON_INO sentinel to anonymous mount namespaces and cleanup the initial mount ns allocation. This is just a preparatory patch and the ns->inum check in ns_common_init() will be dropped in the next patch.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|
#
f74ca6da |
| 17-Sep-2025 |
Christian Brauner <brauner@kernel.org> |
nscommon: move to separate file
It's really awkward spilling the ns common infrastructure into multiple headers. Move it to a separate file.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Chri
nscommon: move to separate file
It's really awkward spilling the ns common infrastructure into multiple headers. Move it to a separate file.
Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
show more ...
|