[CRIU] [PATCH 4/4] zdtm: add a test to check non-root shared bind-mounts

Andrey Vagin avagin at openvz.org
Mon Nov 10 14:24:56 PST 2014


Here is an example from a fedora container:
65 64 252:0 /vz/private/1 / rw,relatime shared:29 - ext4 /dev/mapper/centos_pcs-root rw,data=ordered
77 65 252:0 /vz/private/1/var/tmp/systemd-httpd.service-XLnJPNc/tmp /var/tmp rw,relatime shared:41 - ext4 /dev/mapper/centos_pcs-root rw,data=ordered

We can see non-root shared mount, which is mounted to the root
mount from the same shared group. The test emulates this situation.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm.sh                                |   6 ++
 test/zdtm/.gitignore                        |   2 +
 test/zdtm/live/static/Makefile              |   3 +
 test/zdtm/live/static/mntns_shared_bind.c   | 122 ++++++++++++++++++++++++++++
 test/zdtm/live/static/mntns_shared_bind02.c |   1 +
 5 files changed, 134 insertions(+)
 create mode 100644 test/zdtm/live/static/mntns_shared_bind.c
 create mode 120000 test/zdtm/live/static/mntns_shared_bind02.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 1eb8701..9157f07 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -182,6 +182,8 @@ static/cgroup01
 static/cgroup02
 ns/static/clean_mntns
 static/remap_dead_pid
+ns/static/mntns_shared_bind
+ns/static/mntns_shared_bind02
 "
 
 TEST_CR_KERNEL="
@@ -242,6 +244,8 @@ ns/static/mntns_link_remap
 ns/static/mntns_link_ghost
 ns/static/console
 ns/static/rtc
+ns/static/mntns_shared_bind
+ns/static/mntns_shared_bind02
 "
 
 # Add tests which can be executed in an user namespace
@@ -290,6 +294,8 @@ deleted_dev
 mntns_open
 mntns_link_remap
 mntns_link_ghost
+mntns_shared_bind
+mntns_shared_bind02
 sockets00
 "
 
diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore
index fef561d..9fe8409 100644
--- a/test/zdtm/.gitignore
+++ b/test/zdtm/.gitignore
@@ -63,6 +63,8 @@
 /live/static/mntns_link_ghost
 /live/static/mntns_link_remap
 /live/static/mntns_open
+/live/static/mntns_shared_bind
+/live/static/mntns_shared_bind02
 /live/static/mountpoints
 /live/static/mprotect00
 /live/static/msgque
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 756fee8..b5c1a6a 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -177,6 +177,8 @@ TST_DIR		=				\
 		mntns_open			\
 		mntns_link_remap		\
 		mntns_link_ghost		\
+		mntns_shared_bind		\
+		mntns_shared_bind02		\
 
 TST_DIR_FILE	=				\
 		chroot				\
@@ -292,6 +294,7 @@ socket_listen6: override CFLAGS += -D ZDTM_IPV6
 sigpending:		override LDLIBS += -lrt
 vdso01:			override LDLIBS += -lrt
 mntns_link_remap:	override CFLAGS += -DZDTM_LINK_REMAP
+mntns_shared_bind02:		override CFLAGS += -DSHARED_BIND02
 maps02:		get_smaps_bits.o
 mlock_setuid:		get_smaps_bits.o
 
diff --git a/test/zdtm/live/static/mntns_shared_bind.c b/test/zdtm/live/static/mntns_shared_bind.c
new file mode 100644
index 0000000..28b5ffa
--- /dev/null
+++ b/test/zdtm/live/static/mntns_shared_bind.c
@@ -0,0 +1,122 @@
+#define _GNU_SOURCE
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sched.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include "zdtmtst.h"
+
+#ifndef CLONE_NEWNS
+#define CLONE_NEWNS     0x00020000
+#endif
+
+const char *test_doc	= "Check shared non-root bind-mounts";
+const char *test_author	= "Andrew Vagin <avagin at gmail.com>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+
+int main(int argc, char **argv)
+{
+	char path[PATH_MAX], bpath[PATH_MAX], spath[PATH_MAX];
+	pid_t pid;
+	int status;
+	task_waiter_t t;
+
+	test_init(argc, argv);
+
+	task_waiter_init(&t);
+
+	snprintf(path, sizeof(path), "%s/test", dirname);
+	snprintf(bpath, sizeof(bpath), "%s/test.bind", dirname);
+	snprintf(spath, sizeof(spath), "%s/test/sub", dirname);
+	if (mkdir(dirname, 0700)) {
+		err("mkdir");
+		return 1;
+	}
+
+	if (mount(NULL, "/", NULL, MS_SHARED, NULL)) {
+		err("mount");
+		return 1;
+	}
+
+#ifdef SHARED_BIND02
+	/* */
+	if (mount(dirname, dirname, "tmpfs", 0, NULL) ||
+	    mount(NULL, dirname, NULL, MS_SHARED, NULL)) {
+		err("mount");
+		return 1;
+	}
+#endif
+
+	if (mkdir(path, 0700) ||
+	    mkdir(spath, 0700) ||
+	    mkdir(bpath, 0700)) {
+		err("mkdir");
+		return 1;
+	}
+
+	pid = fork();
+	if (pid < 0) {
+		err("fork");
+		return 1;
+	}
+	if (pid == 0) {
+		unshare(CLONE_NEWNS);
+		if (mount(path, bpath, NULL, MS_BIND, NULL)) {
+			err("mount");
+			return 1;
+		}
+
+		task_waiter_complete(&t, 1);
+		task_waiter_wait4(&t, 2);
+
+
+		if (umount(bpath)) {
+			fail("umount");
+			return 1;
+		}
+
+		return 0;
+	}
+
+	task_waiter_wait4(&t, 1);
+
+	if (mount("test", spath, "tmpfs", 0, NULL)) {
+		err("mount");
+		return 1;
+	}
+
+
+	test_daemon();
+	test_waitsig();
+
+	if (umount(spath)) {
+		fail("umount");
+		return 1;
+	}
+	task_waiter_complete(&t, 2);
+
+	if (waitpid(pid, &status, 0) != pid) {
+		err("waitpid %d", pid);
+		return 1;
+	}
+
+	if (status) {
+		err("%d/%d/%d/%d", WIFEXITED(status), WEXITSTATUS(status), WIFSIGNALED(status), WTERMSIG(status));
+		return 1;
+	}
+
+	pass();
+
+	return 0;
+}
diff --git a/test/zdtm/live/static/mntns_shared_bind02.c b/test/zdtm/live/static/mntns_shared_bind02.c
new file mode 120000
index 0000000..5efca67
--- /dev/null
+++ b/test/zdtm/live/static/mntns_shared_bind02.c
@@ -0,0 +1 @@
+mntns_shared_bind.c
\ No newline at end of file
-- 
1.9.3



More information about the CRIU mailing list