* [Devel] [PATCH hci-8.2 v2 1/3] ve/kernfs: count repeated slashes in a permission path as one
2026-12-01 12:09 [Devel] [PATCH hci-8.2 v2 0/3] ve: count repeated slashes in a permission path as one Pavel Tikhomirov
@ 2026-12-01 12:09 ` Pavel Tikhomirov
2026-12-01 12:09 ` [Devel] [PATCH hci-8.2 v2 2/3] fs/proc, ve: " Pavel Tikhomirov
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Pavel Tikhomirov @ 2026-12-01 12:09 UTC (permalink / raw)
To: Konstantin Khorenko; +Cc: devel, Sashiko
kernfs_perms_set() stops at the first empty component of the path and
applies the mode to the node it reached so far:
rule applied to
cpuN/cache/uevent rw cpuN/cache/uevent
cpuN/cache//uevent rw cpuN/cache
vzctl writes such rules: it passes the cpuN/cache directory with a
trailing slash and appends "/<child>" for each child, so in every
Container cpuN/cache ends up "rw" without "x". A recent mongod 8.0
(tcmalloc) reads cpuN/cache/indexM/shared_cpu_list on start, gets EACCES
and aborts.
Walk the path with kernfs_walk_and_get(), which skips empty components
as a path lookup does.
https://virtuozzo.atlassian.net/browse/VSTOR-158149
Fixes: 57739dce06d0 ("ve/kernfs: add new interface to control per-VE nodes visibility")
Feature: sysfs: per-CT entries visibility and permissions configuration
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
fs/kernfs/ve.c | 29 +++++------------------------
1 file changed, 5 insertions(+), 24 deletions(-)
diff --git a/fs/kernfs/ve.c b/fs/kernfs/ve.c
index 1097fd30598e3..963760b3ac73d 100644
--- a/fs/kernfs/ve.c
+++ b/fs/kernfs/ve.c
@@ -252,33 +252,14 @@ int kernfs_perms_show(struct seq_file *m, void *v, struct kmapset_key *key)
int kernfs_perms_set(char *path, struct ve_struct *ve, int mask,
struct kernfs_node *root, struct kmapset_key *key)
{
- struct kernfs_node *kn = root, *nkn;
- char *sep = path, *dname;
- int ret = 0;
+ struct kernfs_node *kn;
+ int ret;
- kernfs_get(kn);
- do {
- dname = sep;
-
- sep = strchr(sep, '/');
- if (sep)
- *sep++ = 0;
-
- if (!*dname)
- break;
-
- nkn = kernfs_find_and_get(kn, dname);
- if (!nkn) {
- ret = -ENOENT;
- goto out;
- }
-
- kernfs_put(kn);
- kn = nkn;
- } while (sep);
+ kn = kernfs_walk_and_get(root, path);
+ if (!kn)
+ return -ENOENT;
ret = ve_perms_apply(&kn->ve_perms_map, key, ve_is_super(ve), mask);
-out:
kernfs_put(kn);
return ret;
}
--
2.56.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread* [Devel] [PATCH hci-8.2 v2 2/3] fs/proc, ve: count repeated slashes in a permission path as one
2026-12-01 12:09 [Devel] [PATCH hci-8.2 v2 0/3] ve: count repeated slashes in a permission path as one Pavel Tikhomirov
2026-12-01 12:09 ` [Devel] [PATCH hci-8.2 v2 1/3] ve/kernfs: " Pavel Tikhomirov
@ 2026-12-01 12:09 ` Pavel Tikhomirov
2026-12-01 12:37 ` Konstantin Khorenko
2026-12-01 12:09 ` [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: check repeated slashes in a permission path Pavel Tikhomirov
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Pavel Tikhomirov @ 2026-12-01 12:09 UTC (permalink / raw)
To: Konstantin Khorenko; +Cc: devel, Sashiko
proc_perms_set() walks the path the same way as kernfs_perms_set() and
stops at the first empty component: a rule for "sys//kernel" sets sys,
and one with a leading slash ends at the proc root and is rejected with
EINVAL.
Skip empty components as a path lookup does. procfs has no helper that
walks a path this way.
https://virtuozzo.atlassian.net/browse/VSTOR-158149
Fixes: 39c029dcf7fa ("fs/proc, ve: add per-VE ve.proc_permissions")
Feature: kernfs: per-CT entries visibility and permissions configuration
Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
fs/proc/ve.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/proc/ve.c b/fs/proc/ve.c
index d957510c353a8..f6784a7024c93 100644
--- a/fs/proc/ve.c
+++ b/fs/proc/ve.c
@@ -143,8 +143,9 @@ static int proc_perms_set(char *path, struct ve_struct *ve, int mask)
if (sep)
*sep++ = 0;
+ /* Repeated slashes count as one, as in a path lookup */
if (!*dname)
- break;
+ continue;
nde = pde_subdir_find(de, dname, strlen(dname));
if (!nde) {
@@ -158,7 +159,7 @@ static int proc_perms_set(char *path, struct ve_struct *ve, int mask)
} while (sep);
read_unlock(&proc_subdir_lock);
- /* empty or leading-slash path walks to nothing, reject it */
+ /* empty or all-slash path walks to nothing, reject it */
if (de == &proc_root) {
ret = -EINVAL;
goto out;
--
2.56.0
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread* [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: check repeated slashes in a permission path
2026-12-01 12:09 [Devel] [PATCH hci-8.2 v2 0/3] ve: count repeated slashes in a permission path as one Pavel Tikhomirov
2026-12-01 12:09 ` [Devel] [PATCH hci-8.2 v2 1/3] ve/kernfs: " Pavel Tikhomirov
2026-12-01 12:09 ` [Devel] [PATCH hci-8.2 v2 2/3] fs/proc, ve: " Pavel Tikhomirov
@ 2026-12-01 12:09 ` Pavel Tikhomirov
2026-12-01 12:37 ` Konstantin Khorenko
2026-12-01 12:18 ` [Devel] [PATCH hci-8.2 v2 0/3] ve: count repeated slashes in a permission path as one Vasileios Almpanis
2026-12-01 12:37 ` Konstantin Khorenko
4 siblings, 1 reply; 8+ messages in thread
From: Pavel Tikhomirov @ 2026-12-01 12:09 UTC (permalink / raw)
To: Konstantin Khorenko; +Cc: devel, Sashiko
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@sashiko.virtuozzo.com>
Signed-off-by: Pavel Tikhomirov <ptikhomirov@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
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 8+ messages in thread