linux/init
Christian Brauner 9a8e296958
fs: make userspace_init_fs a dynamically-initialized pointer
Change userspace_init_fs from a declared-but-unused extern struct to
a dynamically initialized pointer. Add init_userspace_fs() which is
called early in kernel_init() (PID 1) to record PID 1's fs_struct
as the canonical userspace filesystem state.

Wire up __override_init_fs() and __revert_init_fs() to actually swap
current->fs to/from userspace_init_fs. Previously these were no-ops
that stored current->fs back to itself.

Fix nullfs_userspace_init() to compare against userspace_init_fs
instead of &init_fs. When PID 1 unshares its filesystem state, revert
userspace_init_fs to init_fs's root (nullfs) so that stale filesystem
state is not silently inherited by kworkers and usermodehelpers.

At this stage PID 1's fs still points to rootfs (set by
init_mount_tree), so userspace_init_fs points to rootfs and
scoped_with_init_fs() is functionally equivalent to its previous no-op
behavior.

Link: https://patch.msgid.link/20260601-work-kthread-nullfs-v4-5-77ee053060e0@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-06-29 10:44:05 +02:00
..
.gitignore
.kunitconfig initramfs_test: kunit tests for initramfs unpacking 2025-03-08 12:13:04 +01:00
calibrate.c calibrate: update header inclusion 2025-11-27 14:24:45 -08:00
do_mounts_initrd.c init: remove /proc/sys/kernel/real-root-dev 2026-01-12 17:22:27 +01:00
do_mounts_rd.c initrd: remove deprecated code path (linuxrc) 2026-01-12 17:22:22 +01:00
do_mounts.c init: do_mounts: use kmalloc() for allocations of temporary buffers 2026-05-22 12:12:20 +02:00
do_mounts.h fs: use nullfs unconditionally as the real rootfs 2026-01-14 11:23:39 +01:00
init_task.c fs: add real_fs to track task's actual fs_struct 2026-06-29 10:43:45 +02:00
initramfs_internal.h init: add initramfs_internal.h 2025-03-04 09:52:36 +01:00
initramfs_test.c init/initramfs_test: wait_for_initramfs() before running 2026-05-27 15:11:02 +02:00
initramfs.c initramfs: Refactor to use hex2bin() instead of custom approach 2026-05-21 09:32:46 +02:00
Kconfig mm.git review status for mm-hotfixes-stable..mm-nonmm-stable 2026-06-21 13:20:19 -07:00
main.c fs: make userspace_init_fs a dynamically-initialized pointer 2026-06-29 10:44:05 +02:00
Makefile initramfs_test: kunit tests for initramfs unpacking 2025-03-08 12:13:04 +01:00
noinitramfs.c
version-timestamp.c ns: drop custom reference count initialization for initial namespaces 2025-11-11 10:01:32 +01:00
version.c