[Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: check repeated slashes in a permission path
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Tue Dec 1 15:09:16 MSK 2026
Each variant names its first file with repeated slashes as well,
"/kernel//vmcoreinfo" in sysfs and "//interrupts" in proc. With the
directories above the file traversable, write a rule for it and check
that the file gets the mode and a VE can read it.
https://virtuozzo.atlassian.net/browse/VSTOR-158149
Feature: kernfs: per-CT entries visibility and permissions configuration
Reviewed-by: Sashiko <no-reply at sashiko.virtuozzo.com>
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
tools/testing/selftests/ve/ve_perms_test.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/tools/testing/selftests/ve/ve_perms_test.c b/tools/testing/selftests/ve/ve_perms_test.c
index 375f98c36f87e..d93e58e6c17b6 100644
--- a/tools/testing/selftests/ve/ve_perms_test.c
+++ b/tools/testing/selftests/ve/ve_perms_test.c
@@ -15,6 +15,7 @@
* - cover the write parser (masks, comments, several entries, replace,
* duplicate op, remove of an absent entry, missing mask) and check each
* entry renders at its true depth, a directory with a trailing slash
+ * - confirm repeated slashes in a path count as one
* - enforce the r and x mask bits end to end from inside a VE
*/
#define _GNU_SOURCE
@@ -46,6 +47,7 @@ FIXTURE_VARIANT(ve_perms)
const char *dir_prefix; /* host mount point: "/proc" or "/sys" */
const char *files[NR_FILES]; /* host-only readable leaves */
const char *dir; /* host-only directory */
+ const char *slashed; /* files[0] with repeated slashes */
};
FIXTURE_VARIANT_ADD(ve_perms, proc)
@@ -54,6 +56,7 @@ FIXTURE_VARIANT_ADD(ve_perms, proc)
.dir_prefix = "/proc",
.files = { "interrupts", "slabinfo" },
.dir = "bus",
+ .slashed = "//interrupts",
};
FIXTURE_VARIANT_ADD(ve_perms, sysfs)
@@ -62,6 +65,7 @@ FIXTURE_VARIANT_ADD(ve_perms, sysfs)
.dir_prefix = "/sys",
.files = { "kernel/vmcoreinfo", "kernel/notes" },
.dir = "power",
+ .slashed = "/kernel//vmcoreinfo",
};
/* The per-VE cgroup file for this ctid and filesystem. */
@@ -373,6 +377,30 @@ static int allow_paths(int cgv2_fd, const char *path, const char *const files[])
return 0;
}
+/*
+ * Repeated slashes count as one, as in a path lookup: "/kernel//vmcoreinfo r"
+ * sets kernel/vmcoreinfo, not the directory before the empty component, and
+ * the VE can read the file.
+ */
+TEST_F(ve_perms, repeated_slashes)
+{
+ const char *file = variant->files[0];
+ char path[PATH_MAX], line[PATH_MAX], buf[8192];
+
+ if (!entry_present(variant->dir_prefix, file))
+ SKIP(return, "%s absent under %s", file, variant->dir_prefix);
+
+ ve_file(path, sizeof(path), self->ctid_a, variant->fs);
+
+ ASSERT_EQ(allow_path(self->cgv2_fd, path, file), 0);
+ ASSERT_EQ(set_entry(self->cgv2_fd, path, variant->slashed, "r"), 0);
+ ASSERT_GT(read_file_at(self->cgv2_fd, path, buf, sizeof(buf)), 0);
+ snprintf(line, sizeof(line), "%s r\n", file);
+ EXPECT_NE(strstr(buf, line), NULL);
+ EXPECT_EQ(ve_open_rel(self->cgv2_fd, self->ctid_a, variant->dir_prefix,
+ file, O_RDONLY), 0);
+}
+
/*
* Enforcement, allowed side: from inside a VE, granting r lets each file be
* read, and granting x on the directory lets it be traversed (the lookup then
--
2.56.0
More information about the Devel
mailing list