[CRIU] [PATCH 2/4] zdtm: check read-only tmpfs in userns

Andrei Vagin avagin at openvz.org
Wed Oct 26 13:55:22 PDT 2016


From: Andrei Vagin <avagin at virtuozzo.com>

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 test/zdtm/static/Makefile         |  1 +
 test/zdtm/static/tempfs_ro02.c    | 50 +++++++++++++++++++++++++++++++++++++++
 test/zdtm/static/tempfs_ro02.desc |  1 +
 3 files changed, 52 insertions(+)
 create mode 100644 test/zdtm/static/tempfs_ro02.c
 create mode 100644 test/zdtm/static/tempfs_ro02.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index af1254f..27d505c 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -219,6 +219,7 @@ TST_DIR		=				\
 		tempfs_overmounted		\
 		tempfs_overmounted01		\
 		tempfs_ro			\
+		tempfs_ro02			\
 		tempfs_subns			\
 		mnt_ro_bind			\
 		mount_paths			\
diff --git a/test/zdtm/static/tempfs_ro02.c b/test/zdtm/static/tempfs_ro02.c
new file mode 100644
index 0000000..7b70b86
--- /dev/null
+++ b/test/zdtm/static/tempfs_ro02.c
@@ -0,0 +1,50 @@
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <linux/limits.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check read-only tmpfs mount";
+const char *test_author	= "Andrew Vagin <avagin at openvz.org>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+#define TEST_WORD	"testtest"
+
+int main(int argc, char **argv)
+{
+	int fd, ret = 1;
+	char buf[1024], fname[PATH_MAX];
+
+	test_init(argc, argv);
+
+	mkdir(dirname, 0700);
+	if (mount("none", dirname, "tmpfs", MS_RDONLY, "") < 0) {
+		fail("Can't mount tmpfs");
+		return 1;
+	}
+
+	snprintf(fname, sizeof(buf), "%s/test.file", dirname);
+
+	test_daemon();
+	test_waitsig();
+
+
+	fd = open(fname, O_RDWR | O_CREAT, 0777);
+	if (fd >= 0 || errno != EROFS) {
+		pr_perror("open failed -> %d", fd);
+		goto err;
+	}
+
+	pass();
+	ret = 0;
+err:
+	umount2(dirname, MNT_DETACH);
+	rmdir(dirname);
+	return ret;
+}
diff --git a/test/zdtm/static/tempfs_ro02.desc b/test/zdtm/static/tempfs_ro02.desc
new file mode 100644
index 0000000..7657ba4
--- /dev/null
+++ b/test/zdtm/static/tempfs_ro02.desc
@@ -0,0 +1 @@
+{'flavor': 'ns uns', 'flags': 'suid'}
-- 
2.7.4



More information about the CRIU mailing list