[PATCH v1] selftests/landlock: Add 9p and FUSE filesystem tests

Mickaël Salaün mic at digikod.net
Fri Jul 4 17:13:42 UTC 2025


FUSE is already supported but v9fs requires some fixes [1].

These tests require /mnt/test-v9fs and /mnt/test-fuse to be already
mounted.  It would be too complex to set up such mount points with the
test fixtures because of the related daemons' lifetime, but it is easy
to run these tests with check-linux.sh from landlock-test-tools [2].

Add new kernel configurations to support these two new filesystems.

Rename and update path_is_fs() to take a path as argument.

Cc: Christian Schoenebeck <linux_oss at crudebyte.com>
Cc: Dominique Martinet <asmadeus at codewreck.org>
Cc: Eric Van Hensbergen <ericvh at kernel.org>
Cc: Günther Noack <gnoack at google.com>
Cc: Latchesar Ionkov <lucho at ionkov.net>
Cc: Tingmao Wang <m at maowtm.org>
Link: https://lore.kernel.org/r/cover.1743971855.git.m@maowtm.org [1]
Link: https://github.com/landlock-lsm/landlock-test-tools/pull/21 [2]
Signed-off-by: Mickaël Salaün <mic at digikod.net>
---
 tools/testing/selftests/landlock/config    |  5 +++
 tools/testing/selftests/landlock/fs_test.c | 45 ++++++++++++++++++----
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/landlock/config b/tools/testing/selftests/landlock/config
index 8fe9b461b1fd..02427db3cb7b 100644
--- a/tools/testing/selftests/landlock/config
+++ b/tools/testing/selftests/landlock/config
@@ -1,13 +1,18 @@
+CONFIG_9P_FS=y
 CONFIG_AF_UNIX_OOB=y
 CONFIG_AUDIT=y
 CONFIG_CGROUPS=y
 CONFIG_CGROUP_SCHED=y
+CONFIG_FUSE_FS=y
 CONFIG_INET=y
 CONFIG_IPV6=y
 CONFIG_KEYS=y
 CONFIG_MPTCP=y
 CONFIG_MPTCP_IPV6=y
 CONFIG_NET=y
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NET_9P=y
+CONFIG_NET_9P_FD=y
 CONFIG_NET_NS=y
 CONFIG_OVERLAY_FS=y
 CONFIG_PROC_FS=y
diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index 73729382d40f..788fa030cbe3 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -176,15 +176,19 @@ static bool supports_filesystem(const char *const filesystem)
 	return res;
 }
 
-static bool cwd_matches_fs(unsigned int fs_magic)
+static bool path_is_fs(const char *path, unsigned int fs_magic)
 {
 	struct statfs statfs_buf;
 
-	if (!fs_magic)
+	if (!fs_magic || !path)
 		return true;
 
-	if (statfs(".", &statfs_buf))
-		return true;
+	/* Hack for the hostfs test because TMP_DIR doesn't exist yet. */
+	if (strcmp(path, TMP_DIR) == 0)
+		path = ".";
+
+	if (statfs(path, &statfs_buf))
+		return false;
 
 	return statfs_buf.f_type == fs_magic;
 }
@@ -5294,7 +5298,7 @@ FIXTURE_VARIANT(layout3_fs)
 {
 	const struct mnt_opt mnt;
 	const char *const file_path;
-	unsigned int cwd_fs_magic;
+	unsigned int fs_magic;
 };
 
 /* clang-format off */
@@ -5342,7 +5346,34 @@ FIXTURE_VARIANT_ADD(layout3_fs, hostfs) {
 		.flags = MS_BIND,
 	},
 	.file_path = TMP_DIR "/dir/file",
-	.cwd_fs_magic = HOSTFS_SUPER_MAGIC,
+	.fs_magic = HOSTFS_SUPER_MAGIC,
+};
+
+/*
+ * This test requires a mounted 9p filesystem e.g., with:
+ * diod -n -l 127.0.0.1:564 -e /mnt/test-v9fs-src
+ * mount.diod -n 127.0.0.1:/mnt/test-v9fs-src /mnt/test-v9fs
+ */
+FIXTURE_VARIANT_ADD(layout3_fs, v9fs) {
+	.mnt = {
+		.source = "/mnt/test-v9fs",
+		.flags = MS_BIND,
+	},
+	.file_path = TMP_DIR "/dir/file",
+	.fs_magic = V9FS_MAGIC,
+};
+
+/*
+ * This test requires a mounted FUSE filesystem e.g., with:
+ * bindfs /mnt/test-fuse-src /mnt/test-fuse
+ */
+FIXTURE_VARIANT_ADD(layout3_fs, fuse) {
+	.mnt = {
+		.source = "/mnt/test-fuse",
+		.flags = MS_BIND,
+	},
+	.file_path = TMP_DIR "/dir/file",
+	.fs_magic = FUSE_SUPER_MAGIC,
 };
 
 static char *dirname_alloc(const char *path)
@@ -5365,7 +5396,7 @@ FIXTURE_SETUP(layout3_fs)
 	char *dir_path = dirname_alloc(variant->file_path);
 
 	if (!supports_filesystem(variant->mnt.type) ||
-	    !cwd_matches_fs(variant->cwd_fs_magic)) {
+	    !path_is_fs(variant->mnt.source, variant->fs_magic)) {
 		self->skip_test = true;
 		SKIP(return, "this filesystem is not supported (setup)");
 	}
-- 
2.50.0




More information about the Linux-security-module-archive mailing list