OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2 v2 0/3] ve: count repeated slashes in a permission path as one
@ 2026-12-01 12:09 Pavel Tikhomirov
  2026-12-01 12:09 ` [Devel] [PATCH hci-8.2 v2 1/3] ve/kernfs: " Pavel Tikhomirov
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Pavel Tikhomirov @ 2026-12-01 12:09 UTC (permalink / raw)
  To: Konstantin Khorenko; +Cc: devel, Sashiko

A ve.sysfs_permissions rule with an empty path component is applied to
the node before it, not to the one the path names:

  rule                     applied to
  cpuN/cache/uevent rw     cpuN/cache/uevent
  cpuN/cache//uevent rw    cpuN/cache

vzctl writes such rules for cpuN/cache, so in every Container this
directory is "rw" without "x" and nothing below it can be looked up.
A recent mongod 8.0 reads cpuN/cache/indexM/shared_cpu_list on start,
gets EACCES and aborts (vzt-criu-docker, react-express-mongodb).

Patch 1 skips empty components in ve.sysfs_permissions, as a path
lookup does, patch 2 does the same in ve.proc_permissions, patch 3 adds
a selftest.

https://virtuozzo.atlassian.net/browse/VSTOR-158149

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
Changes in v2:
- patch 2: fix the comment above the proc root check, only an empty or all-slash path ends there now (Sashiko)
- Link to v1: http://lore.virtuozzo.com/20261201-ve-perms-skip-slashes-v1-0-a444e8767c3e@virtuozzo.com

---
Pavel Tikhomirov (3):
      ve/kernfs: count repeated slashes in a permission path as one
      fs/proc, ve: count repeated slashes in a permission path as one
      selftests/ve: check repeated slashes in a permission path

 fs/kernfs/ve.c                             | 29 +++++------------------------
 fs/proc/ve.c                               |  5 +++--
 tools/testing/selftests/ve/ve_perms_test.c | 28 ++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 26 deletions(-)
---
base-commit: beda1840d22b7707e3f8e18f413afbfffef93d25
change-id: 20261201-ve-perms-skip-slashes-3b989857978a

Best regards,
--  
Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

_______________________________________________
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 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

* Re: [Devel] [PATCH hci-8.2 v2 0/3] 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
                   ` (2 preceding siblings ...)
  2026-12-01 12:09 ` [Devel] [PATCH hci-8.2 v2 3/3] selftests/ve: check repeated slashes in a permission path Pavel Tikhomirov
@ 2026-12-01 12:18 ` Vasileios Almpanis
  2026-12-01 12:37 ` Konstantin Khorenko
  4 siblings, 0 replies; 8+ messages in thread
From: Vasileios Almpanis @ 2026-12-01 12:18 UTC (permalink / raw)
  To: Pavel Tikhomirov; +Cc: devel, Sashiko

On Tue, 01 Dec 2026 13:09:13 +0100, Pavel Tikhomirov <ptikhomirov@virtuozzo.com> wrote:
> ve: count repeated slashes in a permission path as one
> 
> A ve.sysfs_permissions rule with an empty path component is applied to
> the node before it, not to the one the path names:
> 
>   rule                     applied to
>   cpuN/cache/uevent rw     cpuN/cache/uevent
>   cpuN/cache//uevent rw    cpuN/cache
> 
> [...]

Reviewed-by: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>

-- 
Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Devel] [PATCH hci-8.2 v2 0/3] 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
                   ` (3 preceding siblings ...)
  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, 0 replies; 8+ messages in thread
From: Konstantin Khorenko @ 2026-12-01 12:37 UTC (permalink / raw)
  To: Pavel Tikhomirov; +Cc: devel

I won't apply this version, please send v3 with the changes below.
v2 crossed my v1 reply; only two of its points are left.

On Tue, 1 Dec 2026 13:09:13 +0100, Pavel Tikhomirov wrote:
> - patch 2: fix the comment above the proc root check, only an empty or all-slash path ends there now (Sashiko)

1. Patch 2 message: "sys//kernel" fails with -ENOENT with or without
   the patch, /proc/sys has no proc_dir_entry children; take an entry
   that exists. "the same way as kernfs_perms_set()" names the loop
   patch 1 removes.
2. Patch 3: the proc case "//interrupts" has only leading slashes; put
   an empty component inside the path, as the sysfs case does. The
   test comment wants one line.

Item 1 of my v1 reply (say what else changes in patch 1) is dropped,
as you answered. So is the box table remark.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [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 2/3] fs/proc, ve: " Pavel Tikhomirov
@ 2026-12-01 12:37   ` Konstantin Khorenko
  0 siblings, 0 replies; 8+ messages in thread
From: Konstantin Khorenko @ 2026-12-01 12:37 UTC (permalink / raw)
  To: Pavel Tikhomirov; +Cc: devel

Item 1 of the cover letter reply.

On Tue, 1 Dec 2026 13:09:15 +0100, Pavel Tikhomirov wrote:
> 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,

/proc/sys has no proc_dir_entry children: "sys//kernel" fails with
-ENOENT with or without this patch. Take an entry that exists, such
as "bus//pci". After patch 1 kernfs_perms_set() no longer walks this
way; name the old loop instead.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [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 3/3] selftests/ve: check repeated slashes in a permission path Pavel Tikhomirov
@ 2026-12-01 12:37   ` Konstantin Khorenko
  0 siblings, 0 replies; 8+ messages in thread
From: Konstantin Khorenko @ 2026-12-01 12:37 UTC (permalink / raw)
  To: Pavel Tikhomirov; +Cc: devel

Item 2 of the cover letter reply.

On Tue, 1 Dec 2026 13:09:16 +0100, Pavel Tikhomirov wrote:
> +	.slashed	= "//interrupts",

Only leading slashes: a walk that skips them but still stops at an
inner empty component passes this case. Put an empty component
inside the path, as the sysfs case does.

> +/*
> + * 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.
> + */

One line is enough for a test comment.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-01 12:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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: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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox