namespace: keep the private nullfs instance in knullfs

The private nullfs instance that kernel threads are confined to is only
ever reachable through init_task's root and pwd. The following patches
point mounts at it as well, so keep it in a global.

No functional changes.

Link: https://patch.msgid.link/20261002-work-mount-fixes-4-v1-14-dd44b89d44ce@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2026-10-02 15:52:45 +02:00
parent 67b69b8a6e
commit 4209cd7f54
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2
2 changed files with 7 additions and 5 deletions

View File

@ -6,6 +6,7 @@
#include <linux/fs_pin.h>
extern struct file_system_type nullfs_fs_type;
extern struct vfsmount *knullfs;
extern struct list_head notify_list;
struct mnt_namespace {

View File

@ -80,6 +80,7 @@ static u64 mnt_id_ctr = MNT_UNIQUE_ID_OFFSET;
static struct hlist_head *mount_hashtable __ro_after_init;
static struct hlist_head *mountpoint_hashtable __ro_after_init;
static struct kmem_cache *mnt_cache __ro_after_init;
struct vfsmount *knullfs __ro_after_init; /* private nullfs instance */
static DECLARE_RWSEM(namespace_sem);
static HLIST_HEAD(unmounted); /* protected by namespace_sem */
static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */
@ -6335,7 +6336,7 @@ static void __init init_mount_tree(void)
*
* (1) nullfs with mount id 1
* (2) mutable rootfs with mount id 2
* (3) private nullfs for kthreads (SB_KERNMOUNT)
* (3) private nullfs for kthreads (SB_KERNMOUNT), kept in knullfs
*
* with (2) mounted on top of (1). The init_task's root and pwd
* are pointed at (3) so all kthreads start isolated in nullfs.
@ -6370,11 +6371,11 @@ static void __init init_mount_tree(void)
init_mnt_ns.nr_mounts++;
}
nullfs_mnt = kern_mount(&nullfs_fs_type);
if (IS_ERR(nullfs_mnt))
knullfs = kern_mount(&nullfs_fs_type);
if (IS_ERR(knullfs))
panic("VFS: Failed to create private nullfs instance");
root.mnt = nullfs_mnt;
root.dentry = nullfs_mnt->mnt_root;
root.mnt = knullfs;
root.dentry = knullfs->mnt_root;
init_task.nsproxy->mnt_ns = &init_mnt_ns;
get_mnt_ns(&init_mnt_ns);