@@ -1909,4 +1909,34 @@ TEST_F(mount_setattr, move_mount_detached_fail)
1909
1909
EXPECT_EQ (close (fd_tree_subdir ), 0 );
1910
1910
}
1911
1911
1912
+ TEST_F (mount_setattr , attach_detached_mount_then_umount_then_close )
1913
+ {
1914
+ int fd_tree = - EBADF ;
1915
+ struct statx stx ;
1916
+
1917
+ fd_tree = sys_open_tree (- EBADF , "/mnt" ,
1918
+ AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
1919
+ AT_RECURSIVE | OPEN_TREE_CLOEXEC |
1920
+ OPEN_TREE_CLONE );
1921
+ ASSERT_GE (fd_tree , 0 );
1922
+
1923
+ ASSERT_EQ (statx (fd_tree , "A" , 0 , 0 , & stx ), 0 );
1924
+ /* We copied with AT_RECURSIVE so /mnt/A must be a mountpoint. */
1925
+ ASSERT_TRUE (stx .stx_attributes & STATX_ATTR_MOUNT_ROOT );
1926
+
1927
+ /* Attach the mount to the caller's mount namespace. */
1928
+ ASSERT_EQ (move_mount (fd_tree , "" , - EBADF , "/tmp/target1" , MOVE_MOUNT_F_EMPTY_PATH ), 0 );
1929
+
1930
+ ASSERT_EQ (statx (- EBADF , "/tmp/target1" , 0 , 0 , & stx ), 0 );
1931
+ ASSERT_TRUE (stx .stx_attributes & STATX_ATTR_MOUNT_ROOT );
1932
+
1933
+ ASSERT_EQ (umount2 ("/tmp/target1" , MNT_DETACH ), 0 );
1934
+
1935
+ /*
1936
+ * This tests whether dissolve_on_fput() handles a NULL mount
1937
+ * namespace correctly, i.e., that it doesn't splat.
1938
+ */
1939
+ EXPECT_EQ (close (fd_tree ), 0 );
1940
+ }
1941
+
1912
1942
TEST_HARNESS_MAIN
0 commit comments