@@ -2061,4 +2061,40 @@ TEST_F(mount_setattr, two_detached_mounts_referring_to_same_anonymous_mount_name
2061
2061
ASSERT_NE (move_mount (fd_tree1 , "" , - EBADF , "/tmp/target1" , MOVE_MOUNT_F_EMPTY_PATH ), 0 );
2062
2062
}
2063
2063
2064
+ TEST_F (mount_setattr , two_detached_subtrees_of_same_anonymous_mount_namespace )
2065
+ {
2066
+ int fd_tree1 = - EBADF , fd_tree2 = - EBADF ;
2067
+
2068
+ /*
2069
+ * Copy the following mount tree:
2070
+ *
2071
+ * |-/mnt/A testing tmpfs
2072
+ * `-/mnt/A/AA testing tmpfs
2073
+ * `-/mnt/A/AA/B testing tmpfs
2074
+ * `-/mnt/A/AA/B/BB testing tmpfs
2075
+ */
2076
+ fd_tree1 = sys_open_tree (- EBADF , "/mnt/A" ,
2077
+ AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
2078
+ AT_RECURSIVE | OPEN_TREE_CLOEXEC |
2079
+ OPEN_TREE_CLONE );
2080
+ ASSERT_GE (fd_tree1 , 0 );
2081
+
2082
+ /*
2083
+ * Create an O_PATH file descriptors with a separate struct file that
2084
+ * refers to a subtree of the same detached mount tree as @fd_tree1
2085
+ */
2086
+ fd_tree2 = sys_open_tree (fd_tree1 , "AA" ,
2087
+ AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
2088
+ AT_EMPTY_PATH | OPEN_TREE_CLOEXEC );
2089
+ ASSERT_GE (fd_tree2 , 0 );
2090
+
2091
+ /*
2092
+ * This must fail as it is only possible to attach the root of a
2093
+ * detached mount tree.
2094
+ */
2095
+ ASSERT_NE (move_mount (fd_tree2 , "" , - EBADF , "/tmp/target1" , MOVE_MOUNT_F_EMPTY_PATH ), 0 );
2096
+
2097
+ ASSERT_EQ (move_mount (fd_tree1 , "" , - EBADF , "/tmp/target1" , MOVE_MOUNT_F_EMPTY_PATH ), 0 );
2098
+ }
2099
+
2064
2100
TEST_HARNESS_MAIN
0 commit comments