]> git.proxmox.com Git - mirror_lxc.git/blobdiff - src/tests/mount_injection.c
seccomp: document path calculation
[mirror_lxc.git] / src / tests / mount_injection.c
index 3d58b9c3ffd3c6496c38e2e1d5d20b15498a6f0a..3ea15f43317ee54a1bb5f6b1a14d9b573b9ebec2 100644 (file)
@@ -386,16 +386,54 @@ static int do_unpriv_container_test()
        return perform_container_test(NAME"unprivileged", config_items);
 }
 
+static bool lxc_setup_shmount(const char *shmount_path)
+{
+       int ret;
+
+       ret = mkdir_p(shmount_path, 0711);
+       if (ret < 0 && errno != EEXIST) {
+               fprintf(stderr, "Failed to create directory \"%s\"\n", shmount_path);
+               return false;
+       }
+
+       /* Prepare host mountpoint */
+       ret = mount("tmpfs", shmount_path, "tmpfs", 0, "size=100k,mode=0711");
+       if (ret < 0) {
+               fprintf(stderr, "Failed to mount \"%s\"\n", shmount_path);
+               return false;
+       }
+
+       ret = mount(shmount_path, shmount_path, "none", MS_REC | MS_SHARED, "");
+       if (ret < 0) {
+               fprintf(stderr, "Failed to make shared \"%s\"\n", shmount_path);
+               return false;
+       }
+
+       return true;
+}
+
+static void lxc_teardown_shmount(char *shmount_path)
+{
+       (void)umount2(shmount_path, MNT_DETACH);
+       (void)recursive_destroy(shmount_path);
+}
+
 int main(int argc, char *argv[])
 {
+       if (!lxc_setup_shmount("/tmp/mount_injection_test"))
+               exit(EXIT_FAILURE);
+
        if (do_priv_container_test()) {
                fprintf(stderr, "Privileged mount injection test failed\n");
-               return -1;
+               exit(EXIT_FAILURE);
        }
 
-       if(do_unpriv_container_test()) {
+       if (do_unpriv_container_test()) {
                fprintf(stderr, "Unprivileged mount injection test failed\n");
-               return -1;
+               exit(EXIT_FAILURE);
        }
-       return 0;
+
+       lxc_teardown_shmount("/tmp/mount_injection_test");
+
+       exit(EXIT_SUCCESS);
 }