]> git.ipfire.org Git - thirdparty/systemd.git/commit
mount-util: Add mount_fd_clone() helper
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 28 Nov 2025 18:06:37 +0000 (19:06 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 14 Dec 2025 10:31:59 +0000 (11:31 +0100)
commit273c6bc045fdfa50c693d0b88ec2a4cbc9258329
treee0ac819d9b502db02776ddfdf18057926152db7b
parent0859fe3f32774f1e0c787974cc252ff922a1b868
mount-util: Add mount_fd_clone() helper

The kernel prevents you from open_tree()'ing an open_tree() fd unless it
was created from the caller's mount namespace. For various use cases, we
want to be able to open_tree() arbitrary mount file descriptors. Turns
out there's a way go get around it by mounting the mount file descriptor
in a throw-away mount namespace and then open_tree()'ing the mount file
descriptor. Let's implement this as a new helper mount_fd_clone() and
add a test for it.

Because move_mount()'ing the original fd makes it pretty useless as it
can't be move_mount()'ed again, we optionally make a second clone which
can replace the original fd so it can be cloned again later.
src/shared/mount-util.c
src/shared/mount-util.h
src/test/test-mount-util.c