@@ -2017,4 +2017,48 @@ TEST_F(mount_setattr, mount_detached1_onto_detached2_then_close_detached1_then_m
2017
2017
EXPECT_EQ (close (fd_tree2 ), 0 );
2018
2018
}
2019
2019
2020
+ TEST_F (mount_setattr , two_detached_mounts_referring_to_same_anonymous_mount_namespace )
2021
+ {
2022
+ int fd_tree1 = - EBADF , fd_tree2 = - EBADF ;
2023
+
2024
+ /*
2025
+ * Copy the following mount tree:
2026
+ *
2027
+ * |-/mnt/A testing tmpfs
2028
+ * `-/mnt/A/AA testing tmpfs
2029
+ * `-/mnt/A/AA/B testing tmpfs
2030
+ * `-/mnt/A/AA/B/BB testing tmpfs
2031
+ */
2032
+ fd_tree1 = sys_open_tree (- EBADF , "/mnt/A" ,
2033
+ AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
2034
+ AT_RECURSIVE | OPEN_TREE_CLOEXEC |
2035
+ OPEN_TREE_CLONE );
2036
+ ASSERT_GE (fd_tree1 , 0 );
2037
+
2038
+ /*
2039
+ * Create an O_PATH file descriptors with a separate struct file
2040
+ * that refers to the same detached mount tree as @fd_tree1
2041
+ */
2042
+ fd_tree2 = sys_open_tree (fd_tree1 , "" ,
2043
+ AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW |
2044
+ AT_EMPTY_PATH | OPEN_TREE_CLOEXEC );
2045
+ ASSERT_GE (fd_tree2 , 0 );
2046
+
2047
+ /*
2048
+ * Copy the following mount tree:
2049
+ *
2050
+ * |-/tmp/target1 testing tmpfs
2051
+ * `-/tmp/target1/AA testing tmpfs
2052
+ * `-/tmp/target1/AA/B testing tmpfs
2053
+ * `-/tmp/target1/AA/B/BB testing tmpfs
2054
+ */
2055
+ ASSERT_EQ (move_mount (fd_tree2 , "" , - EBADF , "/tmp/target1" , MOVE_MOUNT_F_EMPTY_PATH ), 0 );
2056
+
2057
+ /*
2058
+ * This must fail as this would mean adding the same mount tree
2059
+ * into the same mount tree.
2060
+ */
2061
+ ASSERT_NE (move_mount (fd_tree1 , "" , - EBADF , "/tmp/target1" , MOVE_MOUNT_F_EMPTY_PATH ), 0 );
2062
+ }
2063
+
2020
2064
TEST_HARNESS_MAIN
0 commit comments