mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] fs: don't reset userspace_init_fs when PID 1 stops sharing it
@ 2026-11-19 13:25 Christian Brauner
  2026-11-19 13:25 ` [PATCH 1/2] fs: let pivot_root() move userspace_init_fs when nobody shares it Christian Brauner
  2026-11-19 13:25 ` [PATCH 2/2] fs: don't reset userspace_init_fs when PID 1 stops sharing it Christian Brauner
  0 siblings, 2 replies; 3+ messages in thread
From: Christian Brauner @ 2026-11-19 13:25 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Alexander Viro, Jan Kara, Akisaira, linux-kernel, regressions,
	Christian Brauner (Amutable),
	stable

In Android's second stage init StartPropertyService() spawns two
threads. They share PID 1's fs_struct via CLONE_FS. So they share
userspace_init_fs. Afterwards SetupMountNamespaces() calls
unshare(CLONE_NEWNS) on the main thread to create a second mount
namespace and setns()s right back into the initial mount namespace.
unshare(CLONE_NEWNS) implies CLONE_FS so PID 1 switches to a private
copy of its fs_struct.

Ever since v7.3 validate_fs_switch() notices that PID 1 stopped sharing
userspace_init_fs and resets root and pwd of userspace_init_fs to
nullfs. But it does that in place and the two property service threads
still use userspace_init_fs. So they suddenly find themselves in nullfs,
libselinux can't open /sys/fs/selinux/access anymore, every property
write is denied and init stalls.

Before commit 14adbd5341aa ("fs: stop sharing fs_struct between
init_task and pid 1") PID 1 shared init_fs with init_task. So
userspace_init_fs was init_fs and the reset was a no-op as the first
stage chroot had already updated init_fs.root.

There are a couple of fixes to not leave stale state behind but it seems
that there is legitimate userspace out there that does need this. So
stop resetting userspace_init_fs for now. I can probably rework this to
something sane but I'm not sure it's worth it. Kthreads and
usermodehelpers keep using what PID 1 left behind, just like they kept
using init_fs before PID 1 got its own fs_struct. Keep the notice
though.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
Christian Brauner (2):
      fs: let pivot_root() move userspace_init_fs when nobody shares it
      fs: don't reset userspace_init_fs when PID 1 stops sharing it

 fs/fs_struct.c | 72 ++++++++++++++++++++++++----------------------------------
 1 file changed, 30 insertions(+), 42 deletions(-)
---
base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
change-id: 20261119-work-fs-pid1_unshare-946f3ff2d1ab


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-19 13:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 13:25 [PATCH 0/2] fs: don't reset userspace_init_fs when PID 1 stops sharing it Christian Brauner
2026-11-19 13:25 ` [PATCH 1/2] fs: let pivot_root() move userspace_init_fs when nobody shares it Christian Brauner
2026-11-19 13:25 ` [PATCH 2/2] fs: don't reset userspace_init_fs when PID 1 stops sharing it Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®