]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commit
vfs: fix dumpable race in create_userns_hierarchy()
authorChristian Brauner <brauner@kernel.org>
Mon, 23 Mar 2026 13:32:15 +0000 (14:32 +0100)
committerZorro Lang <zlang@kernel.org>
Tue, 12 May 2026 17:22:35 +0000 (01:22 +0800)
commit8c69a37c4f4c32f49957bc9720e11304de6fca33
tree369c2655537ba76da11bfad19dbf2911cf03b1cc
parent4192c9e2266c8e92b49e3f73fe505101ab36ce1b
vfs: fix dumpable race in create_userns_hierarchy()

All processes in the userns hierarchy share the same mm_struct due to
CLONE_VM. When a child calls setresuid() in switch_ids(), the kernel
clears the dumpable flag on the shared mm. The child immediately
re-sets it via prctl(PR_SET_DUMPABLE, 1), but there is a window
between the two where the parent may be opening /proc/PID/ns/user for
the previous level's child. That open hits ptrace_may_access() which
checks get_dumpable(mm) and, finding it zero, falls back to
ptrace_has_cap(mm->user_ns, mode). Since mm->user_ns is init_user_ns
(the mm was created by real root) and the parent is only ns-root, the
capability check fails and the open returns -EACCES.

Fix this by extending the existing two-way socketpair handshake into a
three-way handshake: the child signals the parent after becoming
dumpable, then blocks until the parent has opened /proc/PID/ns/user
and signals back. Only then does the child proceed to
create_userns_hierarchy() for the next level. This guarantees no
concurrent setresuid() can clear dumpable while the parent's open() is
in flight.

Signed-off-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: Zorro Lang <zlang@kernel.org>
Signed-off-by: Zorro Lang <zlang@kernel.org>
src/vfs/utils.c