OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
* [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount
@ 2026-11-16  6:12 Mirian Shilakadze
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace Mirian Shilakadze
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Mirian Shilakadze @ 2026-11-16  6:12 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

A container can strip ro, nosuid, nodev or noexec from a bind mount the
host gave it with "mount -o remount,rw,bind" and then write host data.
This series lets the host lock those flags on a mount, reports the locks
in statmount() so that criu can carry them over a checkpoint and
restore, and tests both.

Changes since v1, after Pavel's review and Sashiko's:
- one attribute per protection, MOUNT_ATTR_VE_LOCK_RDONLY, _NOSUID,
  _NODEV and _NOEXEC, with MOUNT_ATTR_VE_LOCK as the mask of the four,
  so a lock state that is read back can be set again exactly
- a protection lock can no longer be dropped, attr_clr refuses it, as
  nothing drops the locks lock_mnt_tree() raises
- the gate is capable(CAP_SYS_ADMIN) alone, ve_may_lock_mount() is gone
- one mount per call, a lock with AT_RECURSIVE is refused
- do_remount() tests the locks under s_umount before it touches the
  superblock, and mount_setattr() holds s_umount for read while it
  locks. v1 could return EPERM with the superblock already changed.
- lock_mnt_tree() and the perf header copy are left as they are
- new: patch 2, statmount() reports the locks
- new: patch 3, the selftest

Pavel's other suggestion, a lock that keeps the container from
unmounting or moving the mount, is a separate series on top of this one
(VSTOR-154914). The vzctl and criu sides go to their repos separately.

Tested on a VHI node with the 22.22 release kernel plus this series:
- ve_mount_lock_test 8/8 (2/8 on the stock kernel, which lacks the
  feature), mount_setattr 21/21, statmount 15/15 and statmount_ns 2/2,
  the same as on the stock kernel
- a container started by the current vzctl: without a lock it can still
  remount its read-only bind mount rw. Once the host locks the mount in
  the container's mount namespace, the remount fails with EPERM and a
  write with EROFS, while umount still works. Suspend and resume work,
  the current criu restores the mount unlocked.

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

Mirian Shilakadze (3):
  fs: let the protection flags of a mount be locked from userspace
  fs: report the locks of a mount in statmount()
  selftests/ve: test locking a mount from the host

 fs/namespace.c                                |  67 ++++-
 include/uapi/linux/mount.h                    |  15 +
 tools/testing/selftests/ve/.gitignore         |   1 +
 tools/testing/selftests/ve/Makefile           |   1 +
 .../testing/selftests/ve/ve_mount_lock_test.c | 274 ++++++++++++++++++
 5 files changed, 352 insertions(+), 6 deletions(-)
 create mode 100644 tools/testing/selftests/ve/ve_mount_lock_test.c

-- 
2.43.0

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

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

* [Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace
  2026-11-16  6:12 [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount Mirian Shilakadze
@ 2026-11-16  6:12 ` Mirian Shilakadze
  2026-11-16  6:24   ` no-reply
  2026-11-16 17:13   ` Konstantin Khorenko
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 2/3] fs: report the locks of a mount in statmount() Mirian Shilakadze
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 11+ messages in thread
From: Mirian Shilakadze @ 2026-11-16  6:12 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

A container can strip ro, nosuid, nodev or noexec from a bind mount the
host gave it with "mount -o remount,rw,bind" and then write host data.
Nothing raises the MNT_LOCK_* bits that forbid this on such a mount, and
userspace cannot set them.

Give each of them a mount_setattr() attribute, MOUNT_ATTR_VE_LOCK_RDONLY,
_NOSUID, _NODEV and _NOEXEC, with MOUNT_ATTR_VE_LOCK for all four. A
lock stands only where its protection is set and is never dropped,
attr_clr refuses it. Only CAP_SYS_ADMIN in the initial user namespace
may lock, on one mount at a time.

Locks can now be raised on an attached mount, so remount tests them
again under the lock that guards the change.

Feature: ve: ve generic structures
https://virtuozzo.atlassian.net/browse/VSTOR-155305
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 fs/namespace.c             | 58 ++++++++++++++++++++++++++++++++++----
 include/uapi/linux/mount.h | 15 ++++++++++
 2 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 75cabf7763ef..fa3c1851b7da 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -100,6 +100,7 @@ struct mount_kattr {
 	unsigned int propagation;
 	unsigned int lookup_flags;
 	bool recurse;
+	bool lock_flags;
 	struct user_namespace *mnt_userns;
 	struct mnt_idmap *mnt_idmap;
 };
@@ -3018,8 +3019,9 @@ SYSCALL_DEFINE3(open_tree, int, dfd, const char __user *, filename, unsigned, fl
 /*
  * Don't allow locked mount flags to be cleared.
  *
- * No locks need to be held here while testing the various MNT_LOCK
- * flags because those flags can never be cleared once they are set.
+ * mount_setattr() can lock an attached mount, under the mount hash and
+ * s_umount held for read, so test again under the hash or s_umount held
+ * for write before acting on the result.
  */
 static bool can_change_locked_flags(struct mount *mnt, unsigned int mnt_flags)
 {
@@ -3124,7 +3126,9 @@ static int do_reconfigure_mnt(struct path *path, unsigned int mnt_flags)
 	 */
 	down_read(&sb->s_umount);
 	lock_mount_hash();
-	ret = change_mount_ro_state(mnt, mnt_flags);
+	ret = -EPERM;
+	if (can_change_locked_flags(mnt, mnt_flags))
+		ret = change_mount_ro_state(mnt, mnt_flags);
 	if (ret == 0)
 		set_mount_attributes(mnt, mnt_flags);
 	unlock_mount_hash();
@@ -3479,7 +3483,8 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags,
 	if (!err) {
 		down_write(&sb->s_umount);
 		err = -EPERM;
-		if (ns_capable(sb->s_user_ns, CAP_SYS_ADMIN)) {
+		if (ns_capable(sb->s_user_ns, CAP_SYS_ADMIN) &&
+		    can_change_locked_flags(mnt, mnt_flags)) {
 			err = reconfigure_super(fc);
 			if (!err) {
 				lock_mount_hash();
@@ -4543,7 +4548,10 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
 	 MOUNT_ATTR_NOEXEC | MOUNT_ATTR__ATIME | MOUNT_ATTR_NODIRATIME |       \
 	 MOUNT_ATTR_NOSYMFOLLOW)
 
-#define MOUNT_SETATTR_VALID_FLAGS (FSMOUNT_VALID_FLAGS | MOUNT_ATTR_IDMAP)
+#define MOUNT_SETATTR_LOCK_FLAGS MOUNT_ATTR_VE_LOCK
+
+#define MOUNT_SETATTR_VALID_FLAGS \
+	(FSMOUNT_VALID_FLAGS | MOUNT_ATTR_IDMAP | MOUNT_SETATTR_LOCK_FLAGS)
 
 #define MOUNT_SETATTR_PROPAGATION_FLAGS \
 	(MS_UNBINDABLE | MS_PRIVATE | MS_SLAVE | MS_SHARED)
@@ -4564,6 +4572,14 @@ static unsigned int attr_flags_to_mnt_flags(u64 attr_flags)
 		mnt_flags |= MNT_NODIRATIME;
 	if (attr_flags & MOUNT_ATTR_NOSYMFOLLOW)
 		mnt_flags |= MNT_NOSYMFOLLOW;
+	if (attr_flags & MOUNT_ATTR_VE_LOCK_RDONLY)
+		mnt_flags |= MNT_LOCK_READONLY;
+	if (attr_flags & MOUNT_ATTR_VE_LOCK_NOSUID)
+		mnt_flags |= MNT_LOCK_NOSUID;
+	if (attr_flags & MOUNT_ATTR_VE_LOCK_NODEV)
+		mnt_flags |= MNT_LOCK_NODEV;
+	if (attr_flags & MOUNT_ATTR_VE_LOCK_NOEXEC)
+		mnt_flags |= MNT_LOCK_NOEXEC;
 
 	return mnt_flags;
 }
@@ -4915,6 +4931,15 @@ static unsigned int recalc_flags(struct mount_kattr *kattr, struct mount *mnt)
 	flags &= ~kattr->attr_clr;
 	/* flags to raise */
 	flags |= kattr->attr_set;
+	/* a protection lock only stands where the protection is set */
+	if (!(flags & MNT_READONLY))
+		flags &= ~MNT_LOCK_READONLY;
+	if (!(flags & MNT_NOSUID))
+		flags &= ~MNT_LOCK_NOSUID;
+	if (!(flags & MNT_NODEV))
+		flags &= ~MNT_LOCK_NODEV;
+	if (!(flags & MNT_NOEXEC))
+		flags &= ~MNT_LOCK_NOEXEC;
 
 	return flags;
 }
@@ -5083,6 +5108,10 @@ static int do_mount_setattr(struct path *path, struct mount_kattr *kattr)
 		kattr->mnt_idmap = mnt_idmap;
 	}
 
+	/* do_remount() tests the locks and changes the flags under s_umount */
+	if (kattr->lock_flags)
+		down_read(&mnt->mnt.mnt_sb->s_umount);
+
 	if (kattr->propagation) {
 		/*
 		 * Only take namespace_lock() if we're actually changing
@@ -5093,7 +5122,7 @@ static int do_mount_setattr(struct path *path, struct mount_kattr *kattr)
 			err = invent_group_ids(mnt, kattr->recurse);
 			if (err) {
 				namespace_unlock();
-				return err;
+				goto out_lock;
 			}
 		}
 	}
@@ -5137,6 +5166,10 @@ static int do_mount_setattr(struct path *path, struct mount_kattr *kattr)
 		namespace_unlock();
 	}
 
+out_lock:
+	if (kattr->lock_flags)
+		up_read(&mnt->mnt.mnt_sb->s_umount);
+
 	return err;
 }
 
@@ -5230,6 +5263,19 @@ static int build_mount_kattr(const struct mount_attr *attr, size_t usize,
 	if ((attr->attr_set | attr->attr_clr) & ~MOUNT_SETATTR_VALID_FLAGS)
 		return -EINVAL;
 
+	/*
+	 * Only the host may lock, one mount per call. Like the ones
+	 * lock_mnt_tree() raises, a protection lock is never dropped.
+	 */
+	kattr->lock_flags = (attr->attr_set | attr->attr_clr) &
+			    MOUNT_SETATTR_LOCK_FLAGS;
+	if (kattr->lock_flags && !capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	if (attr->attr_clr & MOUNT_ATTR_VE_LOCK)
+		return -EINVAL;
+	if (kattr->lock_flags && kattr->recurse)
+		return -EINVAL;
+
 	kattr->attr_set = attr_flags_to_mnt_flags(attr->attr_set);
 	kattr->attr_clr = attr_flags_to_mnt_flags(attr->attr_clr);
 
diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h
index 225bc366ffcb..8c6a5e643b9c 100644
--- a/include/uapi/linux/mount.h
+++ b/include/uapi/linux/mount.h
@@ -125,6 +125,21 @@ enum fsconfig_command {
 #define MOUNT_ATTR_IDMAP	0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */
 #define MOUNT_ATTR_NOSYMFOLLOW	0x00200000 /* Do not follow symlinks */
 
+/*
+ * Virtuozzo attributes take bits from 63 down, clear of the upstream ones.
+ *
+ * Lock a protection so that whoever gets the mount cannot clear it. Only the
+ * host locks, one mount per mount_setattr() call. A lock holds only where its
+ * protection is set and is never dropped. A bind copies the locks.
+ */
+#define MOUNT_ATTR_VE_LOCK_RDONLY	0x8000000000000000ULL
+#define MOUNT_ATTR_VE_LOCK_NOSUID	0x4000000000000000ULL
+#define MOUNT_ATTR_VE_LOCK_NODEV	0x2000000000000000ULL
+#define MOUNT_ATTR_VE_LOCK_NOEXEC	0x1000000000000000ULL
+#define MOUNT_ATTR_VE_LOCK \
+	(MOUNT_ATTR_VE_LOCK_RDONLY | MOUNT_ATTR_VE_LOCK_NOSUID | \
+	 MOUNT_ATTR_VE_LOCK_NODEV | MOUNT_ATTR_VE_LOCK_NOEXEC)
+
 /*
  * mount_setattr()
  */
-- 
2.43.0

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

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

* [Devel] [PATCH vz10 v2 2/3] fs: report the locks of a mount in statmount()
  2026-11-16  6:12 [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount Mirian Shilakadze
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace Mirian Shilakadze
@ 2026-11-16  6:12 ` Mirian Shilakadze
  2026-11-16  6:17   ` no-reply
  2026-11-16 17:13   ` Konstantin Khorenko
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 3/3] selftests/ve: test locking a mount from the host Mirian Shilakadze
  2026-11-16 17:13 ` [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount Konstantin Khorenko
  3 siblings, 2 replies; 11+ messages in thread
From: Mirian Shilakadze @ 2026-11-16  6:12 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

The locks a mount carries cannot be read back, so criu cannot dump them
and a restored container gets its mounts back unlocked.

Report them in the mnt_attr of statmount(), as the MOUNT_ATTR_VE_LOCK_*
attributes that raise them, whether the host raised them or the kernel
did, as lock_mnt_tree() does on a mount copied across user namespaces.
MNT_LOCK_ATIME has no such attribute and is not reported.

Feature: ve: ve generic structures
https://virtuozzo.atlassian.net/browse/VSTOR-155305
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 fs/namespace.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/namespace.c b/fs/namespace.c
index fa3c1851b7da..b73caff6a671 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5431,6 +5431,15 @@ static u64 mnt_to_attr_flags(struct vfsmount *mnt)
 	if (is_idmapped_mnt(mnt))
 		attr_flags |= MOUNT_ATTR_IDMAP;
 
+	if (mnt_flags & MNT_LOCK_READONLY)
+		attr_flags |= MOUNT_ATTR_VE_LOCK_RDONLY;
+	if (mnt_flags & MNT_LOCK_NOSUID)
+		attr_flags |= MOUNT_ATTR_VE_LOCK_NOSUID;
+	if (mnt_flags & MNT_LOCK_NODEV)
+		attr_flags |= MOUNT_ATTR_VE_LOCK_NODEV;
+	if (mnt_flags & MNT_LOCK_NOEXEC)
+		attr_flags |= MOUNT_ATTR_VE_LOCK_NOEXEC;
+
 	return attr_flags;
 }
 
-- 
2.43.0

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

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

* [Devel] [PATCH vz10 v2 3/3] selftests/ve: test locking a mount from the host
  2026-11-16  6:12 [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount Mirian Shilakadze
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace Mirian Shilakadze
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 2/3] fs: report the locks of a mount in statmount() Mirian Shilakadze
@ 2026-11-16  6:12 ` Mirian Shilakadze
  2026-11-16  6:38   ` no-reply
  2026-11-16 17:13   ` Konstantin Khorenko
  2026-11-16 17:13 ` [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount Konstantin Khorenko
  3 siblings, 2 replies; 11+ messages in thread
From: Mirian Shilakadze @ 2026-11-16  6:12 UTC (permalink / raw)
  To: khorenko, ptikhomirov; +Cc: devel

Cover the MOUNT_ATTR_VE_LOCK_* protection locks. A forked task that owns
its user and mount namespace moves in a clone the host locked, the way
vzctl hands a container its bind mounts, and must not be able to clear
a locked protection or its lock, or lock a mount of its own. A bind it
makes keeps the locks. On the host, check that each lock bit locks its
own protection and no other, that a lock stands only where its
protection is set, that a protection lock cannot be dropped, that locks
are refused with AT_RECURSIVE, and that statmount() reports the locks.

Feature: ve: ve generic structures
https://virtuozzo.atlassian.net/browse/VSTOR-155305
Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
---
 tools/testing/selftests/ve/.gitignore         |   1 +
 tools/testing/selftests/ve/Makefile           |   1 +
 .../testing/selftests/ve/ve_mount_lock_test.c | 274 ++++++++++++++++++
 3 files changed, 276 insertions(+)
 create mode 100644 tools/testing/selftests/ve/ve_mount_lock_test.c

diff --git a/tools/testing/selftests/ve/.gitignore b/tools/testing/selftests/ve/.gitignore
index 3d1179bd2c5f..9b26fb05e342 100644
--- a/tools/testing/selftests/ve/.gitignore
+++ b/tools/testing/selftests/ve/.gitignore
@@ -4,3 +4,4 @@ ve_mount_accounting_test
 ve_cpuid_override_test
 ve_vtty_stress
 ve_numa_migrate_test
+ve_mount_lock_test
diff --git a/tools/testing/selftests/ve/Makefile b/tools/testing/selftests/ve/Makefile
index e96320a18384..57d688381f93 100644
--- a/tools/testing/selftests/ve/Makefile
+++ b/tools/testing/selftests/ve/Makefile
@@ -7,6 +7,7 @@ TEST_GEN_PROGS += ve_perms_test
 TEST_GEN_PROGS += ve_mount_accounting_test
 TEST_GEN_PROGS += ve_vtty_stress
 TEST_GEN_PROGS += ve_numa_migrate_test
+TEST_GEN_PROGS += ve_mount_lock_test
 
 # CPUID faulting is x86-64 only. ARCH says "x86" for 32-bit too and lib.mk
 # picks the clang target by its emptiness, so decide by the compiler.
diff --git a/tools/testing/selftests/ve/ve_mount_lock_test.c b/tools/testing/selftests/ve/ve_mount_lock_test.c
new file mode 100644
index 000000000000..b113aebe617d
--- /dev/null
+++ b/tools/testing/selftests/ve/ve_mount_lock_test.c
@@ -0,0 +1,274 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ve_mount_lock selftests
+ *
+ * The host locks a mount with the MOUNT_ATTR_VE_LOCK_* attributes before it
+ * hands the mount over. A task that owns its user and mount namespace, as a
+ * container does, moves the mount in and must not be able to undo the locks.
+ */
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/wait.h>
+#include <linux/mount.h>
+
+#include "../kselftest_harness.h"
+#include "ve_selftest.h"
+
+#ifndef MOUNT_ATTR_VE_LOCK_RDONLY
+#define MOUNT_ATTR_VE_LOCK_RDONLY	0x8000000000000000ULL
+#define MOUNT_ATTR_VE_LOCK_NOSUID	0x4000000000000000ULL
+#define MOUNT_ATTR_VE_LOCK_NODEV	0x2000000000000000ULL
+#define MOUNT_ATTR_VE_LOCK_NOEXEC	0x1000000000000000ULL
+#define MOUNT_ATTR_VE_LOCK \
+	(MOUNT_ATTR_VE_LOCK_RDONLY | MOUNT_ATTR_VE_LOCK_NOSUID | \
+	 MOUNT_ATTR_VE_LOCK_NODEV | MOUNT_ATTR_VE_LOCK_NOEXEC)
+#endif
+
+#define SRC	"/tmp/src"
+#define DST	"/tmp/dst"
+#define DST2	"/tmp/dst2"
+
+#define PROTECTIONS (MOUNT_ATTR_RDONLY | MOUNT_ATTR_NOSUID | \
+		     MOUNT_ATTR_NODEV | MOUNT_ATTR_NOEXEC)
+
+static int setattr(int dfd, const char *path, unsigned int flags,
+		   __u64 set, __u64 clr)
+{
+	struct mount_attr attr = { .attr_set = set, .attr_clr = clr };
+
+	return syscall(__NR_mount_setattr, dfd, path, flags, &attr,
+		       sizeof(attr));
+}
+
+static int setattr_path(const char *path, __u64 set, __u64 clr)
+{
+	return setattr(AT_FDCWD, path, 0, set, clr);
+}
+
+static int move(int fd, const char *dst)
+{
+	return syscall(__NR_move_mount, fd, "", AT_FDCWD, dst,
+		       MOVE_MOUNT_F_EMPTY_PATH);
+}
+
+/* A detached clone of @path carrying @set, as the host hands a mount over. */
+static int handover(const char *path, __u64 set)
+{
+	int fd = syscall(__NR_open_tree, AT_FDCWD, path, OPEN_TREE_CLONE);
+
+	if (fd >= 0 && setattr(fd, "", AT_EMPTY_PATH, set, 0)) {
+		close(fd);
+		return -1;
+	}
+	return fd;
+}
+
+static int mnt_attr(const char *path, __u64 *attr)
+{
+	struct mnt_id_req req = {
+		.size = MNT_ID_REQ_SIZE_VER0,
+		.param = STATMOUNT_MNT_BASIC,
+	};
+	struct statmount sm;
+	struct statx sx;
+
+	if (statx(AT_FDCWD, path, 0, STATX_MNT_ID_UNIQUE, &sx))
+		return -1;
+	req.mnt_id = sx.stx_mnt_id;
+	if (syscall(__NR_statmount, &req, &sm, sizeof(sm), 0))
+		return -1;
+	*attr = sm.mnt_attr;
+	return 0;
+}
+
+/* Run @fn as container root once handover(SRC, @set) is moved onto DST. */
+static void in_ct(struct __test_metadata *_metadata,
+		  void (*fn)(struct __test_metadata *), __u64 set)
+{
+	int status;
+	pid_t pid;
+
+	pid = fork();
+	ASSERT_LE(0, pid);
+	if (pid == 0) {
+		int fd = handover(SRC, set);
+
+		if (fd < 0 || unshare(CLONE_NEWUSER | CLONE_NEWNS) ||
+		    write_file_at(AT_FDCWD, "/proc/self/setgroups", "deny") ||
+		    write_file_at(AT_FDCWD, "/proc/self/uid_map", "0 0 1") ||
+		    write_file_at(AT_FDCWD, "/proc/self/gid_map", "0 0 1") ||
+		    move(fd, DST)) {
+			perror("container setup");
+			_exit(1);
+		}
+		fn(_metadata);
+		_exit(_metadata->exit_code);
+	}
+	ASSERT_EQ(pid, waitpid(pid, &status, 0));
+	ASSERT_EQ(0, status);
+}
+
+FIXTURE(lock) {};
+
+FIXTURE_SETUP(lock)
+{
+	ASSERT_EQ(0, unshare(CLONE_NEWNS));
+	ASSERT_EQ(0, mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL));
+	ASSERT_EQ(0, mount("tmpfs", "/tmp", "tmpfs", 0, NULL));
+	ASSERT_EQ(0, mkdir(SRC, 0755));
+	ASSERT_EQ(0, mkdir(DST, 0755));
+	ASSERT_EQ(0, mkdir(DST2, 0755));
+}
+
+FIXTURE_TEARDOWN(lock)
+{
+}
+
+static void relax_unlocked(struct __test_metadata *_metadata)
+{
+	__u64 attr;
+
+	ASSERT_EQ(0, mount(NULL, DST, NULL, MS_REMOUNT | MS_BIND, NULL));
+	ASSERT_EQ(0, mnt_attr(DST, &attr));
+	EXPECT_EQ(0ULL, attr & MOUNT_ATTR_RDONLY);
+}
+
+/* Without a lock the container takes a read-only mount writable. */
+TEST_F(lock, unlocked_mount_is_relaxed)
+{
+	in_ct(_metadata, relax_unlocked, MOUNT_ATTR_RDONLY);
+}
+
+static void relax_locked(struct __test_metadata *_metadata)
+{
+	static const struct { unsigned long ms; __u64 attr; } prot[] = {
+		{ MS_RDONLY, MOUNT_ATTR_RDONLY },
+		{ MS_NOSUID, MOUNT_ATTR_NOSUID },
+		{ MS_NODEV, MOUNT_ATTR_NODEV },
+		{ MS_NOEXEC, MOUNT_ATTR_NOEXEC },
+	};
+	unsigned long all = MS_RDONLY | MS_NOSUID | MS_NODEV | MS_NOEXEC;
+	unsigned int i;
+	__u64 attr;
+
+	for (i = 0; i < ARRAY_SIZE(prot); i++) {
+		ASSERT_EQ(-1, mount(NULL, DST, NULL, MS_REMOUNT | MS_BIND |
+				    (all & ~prot[i].ms), NULL));
+		ASSERT_EQ(EPERM, errno);
+		ASSERT_EQ(-1, setattr_path(DST, 0, prot[i].attr));
+		ASSERT_EQ(EPERM, errno);
+	}
+	ASSERT_EQ(-1, setattr_path(DST, 0, MOUNT_ATTR_VE_LOCK_RDONLY));
+	ASSERT_EQ(EPERM, errno);
+	ASSERT_EQ(0, mnt_attr(DST, &attr));
+	EXPECT_EQ(PROTECTIONS, attr & PROTECTIONS);
+	EXPECT_EQ(MOUNT_ATTR_VE_LOCK, attr & MOUNT_ATTR_VE_LOCK);
+	EXPECT_EQ(0, setattr_path(DST, MOUNT_ATTR_NOSYMFOLLOW, 0));
+}
+
+/* No locked protection or lock can be cleared, other attributes can be set. */
+TEST_F(lock, locked_protections_hold)
+{
+	in_ct(_metadata, relax_locked, PROTECTIONS | MOUNT_ATTR_VE_LOCK);
+}
+
+static void lock_own(struct __test_metadata *_metadata)
+{
+	ASSERT_EQ(0, mount("tmpfs", DST2, "tmpfs", MS_RDONLY, NULL));
+	ASSERT_EQ(-1, setattr_path(DST2, MOUNT_ATTR_VE_LOCK, 0));
+	ASSERT_EQ(EPERM, errno);
+}
+
+/* The container cannot lock its own mounts. */
+TEST_F(lock, container_cannot_lock)
+{
+	in_ct(_metadata, lock_own, MOUNT_ATTR_RDONLY | MOUNT_ATTR_VE_LOCK);
+}
+
+static void bind_locked(struct __test_metadata *_metadata)
+{
+	ASSERT_EQ(0, mount(DST, DST2, NULL, MS_BIND, NULL));
+	ASSERT_EQ(-1, mount(NULL, DST2, NULL, MS_REMOUNT | MS_BIND, NULL));
+	ASSERT_EQ(EPERM, errno);
+}
+
+/* A bind keeps the protection locks. */
+TEST_F(lock, bind_keeps_protection_locks)
+{
+	in_ct(_metadata, bind_locked, MOUNT_ATTR_RDONLY | MOUNT_ATTR_VE_LOCK);
+}
+
+/* A protection lock stands only where its protection is set. */
+TEST_F(lock, lock_follows_protection)
+{
+	int fd = handover(SRC, MOUNT_ATTR_RDONLY);
+	__u64 attr;
+
+	ASSERT_GE(fd, 0);
+	ASSERT_EQ(0, move(fd, DST));
+	ASSERT_EQ(0, setattr_path(DST, MOUNT_ATTR_VE_LOCK, 0));
+	ASSERT_EQ(0, mnt_attr(DST, &attr));
+	EXPECT_EQ(MOUNT_ATTR_VE_LOCK_RDONLY, attr & MOUNT_ATTR_VE_LOCK);
+
+	ASSERT_EQ(0, setattr_path(DST, MOUNT_ATTR_NOSUID, 0));
+	EXPECT_EQ(0, setattr_path(DST, 0, MOUNT_ATTR_NOSUID));
+}
+
+/* Each lock bit locks its own protection and no other. */
+TEST_F(lock, one_lock_per_protection)
+{
+	static const struct { __u64 prot; __u64 lock; } pair[] = {
+		{ MOUNT_ATTR_RDONLY, MOUNT_ATTR_VE_LOCK_RDONLY },
+		{ MOUNT_ATTR_NOSUID, MOUNT_ATTR_VE_LOCK_NOSUID },
+		{ MOUNT_ATTR_NODEV, MOUNT_ATTR_VE_LOCK_NODEV },
+		{ MOUNT_ATTR_NOEXEC, MOUNT_ATTR_VE_LOCK_NOEXEC },
+	};
+	unsigned int i;
+	__u64 attr;
+
+	for (i = 0; i < ARRAY_SIZE(pair); i++) {
+		__u64 other = pair[(i + 1) % ARRAY_SIZE(pair)].prot;
+		int fd = handover(SRC, PROTECTIONS | pair[i].lock);
+
+		ASSERT_GE(fd, 0);
+		ASSERT_EQ(0, move(fd, DST));
+		close(fd);
+		ASSERT_EQ(0, mnt_attr(DST, &attr));
+		EXPECT_EQ(pair[i].lock, attr & MOUNT_ATTR_VE_LOCK);
+		ASSERT_EQ(-1, setattr_path(DST, 0, pair[i].prot));
+		ASSERT_EQ(EPERM, errno);
+		EXPECT_EQ(0, setattr_path(DST, 0, other));
+		ASSERT_EQ(0, umount2(DST, 0));
+	}
+}
+
+/* Not even the host drops a protection lock or clears what it protects. */
+TEST_F(lock, host_cannot_unlock_protection)
+{
+	int fd = handover(SRC, MOUNT_ATTR_RDONLY | MOUNT_ATTR_VE_LOCK);
+
+	ASSERT_GE(fd, 0);
+	ASSERT_EQ(0, move(fd, DST));
+	ASSERT_EQ(-1, setattr_path(DST, 0, MOUNT_ATTR_VE_LOCK_RDONLY));
+	ASSERT_EQ(EINVAL, errno);
+	ASSERT_EQ(-1, setattr_path(DST, 0, MOUNT_ATTR_RDONLY));
+	ASSERT_EQ(EPERM, errno);
+}
+
+/* Locks change on the one mount named, never recursively. */
+TEST_F(lock, not_recursive)
+{
+	ASSERT_EQ(0, mount(SRC, DST, NULL, MS_BIND, NULL));
+	ASSERT_EQ(-1, setattr(AT_FDCWD, DST, AT_RECURSIVE,
+			      MOUNT_ATTR_VE_LOCK, 0));
+	EXPECT_EQ(EINVAL, errno);
+}
+
+TEST_HARNESS_MAIN
-- 
2.43.0

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

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

* Re: [Devel] [PATCH vz10 v2 2/3] fs: report the locks of a mount in statmount()
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 2/3] fs: report the locks of a mount in statmount() Mirian Shilakadze
@ 2026-11-16  6:17   ` no-reply
  2026-11-16 17:13   ` Konstantin Khorenko
  1 sibling, 0 replies; 11+ messages in thread
From: no-reply @ 2026-11-16  6:17 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, ptikhomirov; +Cc: devel

> The locks a mount carries cannot be read back, so criu cannot dump them
> and a restored container gets its mounts back unlocked.
> 
> Report them in the mnt_attr of statmount(), as the MOUNT_ATTR_VE_LOCK_*
> attributes that raise them, whether the host raised them or the kernel
> did, as lock_mnt_tree() does on a mount copied across user namespaces.
> MNT_LOCK_ATIME has no such attribute and is not reported.
> 
> Feature: ve: ve generic structures
> https://virtuozzo.atlassian.net/browse/VSTOR-155305
> Signed-off-by: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261116061256.54472-1-mirian.shilakadze@virtuozzo.com?part=2


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

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

* Re: [Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace Mirian Shilakadze
@ 2026-11-16  6:24   ` no-reply
  2026-11-16 17:13   ` Konstantin Khorenko
  1 sibling, 0 replies; 11+ messages in thread
From: no-reply @ 2026-11-16  6:24 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, ptikhomirov; +Cc: devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] fs: mount_setattr() silently drops a VE lock request on an unset
  protection
--

commit 4fe4ec6ec778b3296f2d3e5ddbb682f247213bc4
Author: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

fs: let the protection flags of a mount be locked from userspace

This adds mount_setattr() attributes MOUNT_ATTR_VE_LOCK_RDONLY, _NOSUID, _NODEV and _NOEXEC. They let a CAP_SYS_ADMIN caller in the initial user namespace raise the matching MNT_LOCK_* bits on one mount at a time.

> @@ -4915,6 +4931,15 @@ static unsigned int recalc_flags(struct mount_kattr *kattr, struct mount *mnt)
>  	flags &= ~kattr->attr_clr;
>  	/* flags to raise */
>  	flags |= kattr->attr_set;
> +	/* a protection lock only stands where the protection is set */
> +	if (!(flags & MNT_READONLY))
> +		flags &= ~MNT_LOCK_READONLY;
> +	if (!(flags & MNT_NOSUID))
> +		flags &= ~MNT_LOCK_NOSUID;
> +	if (!(flags & MNT_NODEV))
> +		flags &= ~MNT_LOCK_NODEV;
> +	if (!(flags & MNT_NOEXEC))
> +		flags &= ~MNT_LOCK_NOEXEC;
>
>  	return flags;
>  }

[ ... ]

> +	kattr->lock_flags = (attr->attr_set | attr->attr_clr) &
> +			    MOUNT_SETATTR_LOCK_FLAGS;
> +	if (kattr->lock_flags && !capable(CAP_SYS_ADMIN))
> +		return -EPERM;

[Severity: Low]
Can mount_setattr() report success without locking anything here? If a caller passes, say, MOUNT_ATTR_VE_LOCK_RDONLY on a read-write mount without also setting MOUNT_ATTR_RDONLY, build_mount_kattr() accepts the request. recalc_flags() then strips MNT_LOCK_READONLY because MNT_READONLY is not set. The stripped value is committed and the call returns 0.

The host administrator gets no sign that the mount is still unprotected. This is a hardening interface, so would returning -EINVAL for a lock bit without its matching protection be safer? Setting the protection implicitly would also work.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261116061256.54472-1-mirian.shilakadze@virtuozzo.com?part=1

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

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

* Re: [Devel] [PATCH vz10 v2 3/3] selftests/ve: test locking a mount from the host
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 3/3] selftests/ve: test locking a mount from the host Mirian Shilakadze
@ 2026-11-16  6:38   ` no-reply
  2026-11-16 17:13   ` Konstantin Khorenko
  1 sibling, 0 replies; 11+ messages in thread
From: no-reply @ 2026-11-16  6:38 UTC (permalink / raw)
  To: Mirian Shilakadze, khorenko, ptikhomirov; +Cc: devel

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] selftests/ve: ve_mount_lock_test fails instead of skipping
  without prerequisites
- [Low] selftests/ve: handover() fd not closed in two ve_mount_lock
  tests
--

commit 03aae3cc92f5f083d66ff15d6314eb38765979c3
Author: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>

selftests/ve: test locking a mount from the host

The patch adds ve_mount_lock_test, which covers the MOUNT_ATTR_VE_LOCK_* protection locks. A forked task that owns its user and mount namespace moves in a clone the host locked. The test checks that this task cannot clear a locked protection or lock, and that the host-side lock semantics and the statmount() reporting hold.

> diff --git a/tools/testing/selftests/ve/ve_mount_lock_test.c b/tools/testing/selftests/ve/ve_mount_lock_test.c
> new file mode 100644
> index 000000000000..b113aebe617d
> --- /dev/null
> +++ b/tools/testing/selftests/ve/ve_mount_lock_test.c
> @@ -0,0 +1,274 @@

[ ... ]

> +/* Run @fn as container root once handover(SRC, @set) is moved onto DST. */
> +static void in_ct(struct __test_metadata *_metadata,
> +		  void (*fn)(struct __test_metadata *), __u64 set)
> +{
> +	int status;
> +	pid_t pid;
> +
> +	pid = fork();
> +	ASSERT_LE(0, pid);
> +	if (pid == 0) {
> +		int fd = handover(SRC, set);
> +
> +		if (fd < 0 || unshare(CLONE_NEWUSER | CLONE_NEWNS) ||
> +		    write_file_at(AT_FDCWD, "/proc/self/setgroups", "deny") ||
> +		    write_file_at(AT_FDCWD, "/proc/self/uid_map", "0 0 1") ||
> +		    write_file_at(AT_FDCWD, "/proc/self/gid_map", "0 0 1") ||
> +		    move(fd, DST)) {
> +			perror("container setup");
> +			_exit(1);
> +		}
> +		fn(_metadata);
> +		_exit(_metadata->exit_code);
> +	}
> +	ASSERT_EQ(pid, waitpid(pid, &status, 0));
> +	ASSERT_EQ(0, status);
> +}
> +
> +FIXTURE(lock) {};
> +
> +FIXTURE_SETUP(lock)
> +{
> +	ASSERT_EQ(0, unshare(CLONE_NEWNS));
> +	ASSERT_EQ(0, mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL));
> +	ASSERT_EQ(0, mount("tmpfs", "/tmp", "tmpfs", 0, NULL));
> +	ASSERT_EQ(0, mkdir(SRC, 0755));
> +	ASSERT_EQ(0, mkdir(DST, 0755));
> +	ASSERT_EQ(0, mkdir(DST2, 0755));
> +}

[Severity: Low]
Should a missing prerequisite be a skip rather than a failure here?

FIXTURE_SETUP(lock) only ASSERTs, so an unprivileged run fails in unshare(CLONE_NEWNS) instead of skipping. The sibling tests ve_cpuid_override_test and ve_numa_migrate_test call SKIP(return, "needs root") when geteuid() is non-zero.

In in_ct(), the same applies when user namespaces are unavailable, or when the kernel rejects the MOUNT_ATTR_VE_LOCK_* bits. The child calls perror() and _exit(1), and the parent's ASSERT_EQ(0, status) turns that into a failure. The local #ifndef fallback for the lock bits means a kernel without the feature ends up here as well. Probing with mount_setattr() on a throw-away clone, and skipping with a reason string on failure, would separate "feature absent" from "feature broken".

[ ... ]

> +/* A protection lock stands only where its protection is set. */
> +TEST_F(lock, lock_follows_protection)
> +{
> +	int fd = handover(SRC, MOUNT_ATTR_RDONLY);
> +	__u64 attr;
> +
> +	ASSERT_GE(fd, 0);
> +	ASSERT_EQ(0, move(fd, DST));
> +	ASSERT_EQ(0, setattr_path(DST, MOUNT_ATTR_VE_LOCK, 0));

[Severity: Low]
This isn't a bug, but the fd from handover() is never closed after move() here. host_cannot_unlock_protection() has the same omission. one_lock_per_protection() does close(fd), so the tests are inconsistent. The harness runs each test in its own process, so nothing leaks beyond the test, but closing the fd would match the other test.

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261116061256.54472-1-mirian.shilakadze@virtuozzo.com?part=3

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

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

* Re: [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount
  2026-11-16  6:12 [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount Mirian Shilakadze
                   ` (2 preceding siblings ...)
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 3/3] selftests/ve: test locking a mount from the host Mirian Shilakadze
@ 2026-11-16 17:13 ` Konstantin Khorenko
  3 siblings, 0 replies; 11+ messages in thread
From: Konstantin Khorenko @ 2026-11-16 17:13 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

I won't apply this version, please send v3 with the changes below.

On Mon, 16 Nov 2026 10:12:51 +0400, Mirian Shilakadze <mirian.shilakadze@virtuozzo.com> wrote:
> Changes since v1, after Pavel's review and Sashiko's:

The kernel side looks right to me: the remount test under s_umount
closes the v1 race, and the s_umount -> namespace_sem order is the one
mount_too_revealing() already uses. What to change for v3:

1. Patch 3: not_recursive passes on a kernel without the feature, the
   unknown bits already fail with EINVAL. Lock the same mount without
   AT_RECURSIVE first and expect success.

2. Patch 3: skip instead of failing when the test is not run as root,
   when user namespaces are off, or when the kernel lacks the lock
   bits (Sashiko's point). Probe the bits once on a scratch clone.
   Close the handover() fd where the other tests do not.

3. Patch 3: add a check that statmount() reports the locks the kernel
   raised, on a mount copied into a new user and mount namespace.
   Patch 2 says it does, nothing tests it.

4. Patch 2 message: say that this changes what statmount() returns in
   every unprivileged container, not only on locked binds.

5. Patch 1 message: say why the ve0 test went away and why
   AT_RECURSIVE is refused.

6. Cover letter: link v1. b4 did not connect the two revisions, it has
   a new ticket and a new title.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

* Re: [Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace Mirian Shilakadze
  2026-11-16  6:24   ` no-reply
@ 2026-11-16 17:13   ` Konstantin Khorenko
  1 sibling, 0 replies; 11+ messages in thread
From: Konstantin Khorenko @ 2026-11-16 17:13 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

I won't apply this version, please send v3 with the changes below.

On Mon, 16 Nov 2026 10:12:52 +0400, Mirian Shilakadze <mirian.shilakadze@virtuozzo.com> wrote:
> +	kattr->lock_flags = (attr->attr_set | attr->attr_clr) &
> +			    MOUNT_SETATTR_LOCK_FLAGS;
> +	if (kattr->lock_flags && !capable(CAP_SYS_ADMIN))
> +		return -EPERM;
> +	if (attr->attr_clr & MOUNT_ATTR_VE_LOCK)
> +		return -EINVAL;
> +	if (kattr->lock_flags && kattr->recurse)
> +		return -EINVAL;

Item 5 of the cover letter reply: give the reasons for the two choices
here in the message.

- The ve0 test: in the v1 review I asked to keep it. Dropping it is
  fine now that a lock cannot be dropped: host root that joined a
  container's ve can only add restrictions. One sentence says so.
- AT_RECURSIVE: only the s_umount of this mount's superblock is held,
  submounts on other superblocks would reopen the remount race.

Sashiko's point that a lock bit on an unset protection returns 0 and
locks nothing needs no change: the message and the UAPI comment say a
lock stands only where its protection is set, and MOUNT_ATTR_VE_LOCK
relies on that to lock whatever is set.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

* Re: [Devel] [PATCH vz10 v2 2/3] fs: report the locks of a mount in statmount()
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 2/3] fs: report the locks of a mount in statmount() Mirian Shilakadze
  2026-11-16  6:17   ` no-reply
@ 2026-11-16 17:13   ` Konstantin Khorenko
  1 sibling, 0 replies; 11+ messages in thread
From: Konstantin Khorenko @ 2026-11-16 17:13 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

I won't apply this version, please send v3 with the changes below.

On Mon, 16 Nov 2026 10:12:53 +0400, Mirian Shilakadze <mirian.shilakadze@virtuozzo.com> wrote:
> Report them in the mnt_attr of statmount(), as the MOUNT_ATTR_VE_LOCK_*
> attributes that raise them, whether the host raised them or the kernel
> did, as lock_mnt_tree() does on a mount copied across user namespaces.

Item 4 of the cover letter reply: say that this is a visible change in
every unprivileged container.

lock_mnt_tree() locks every protection set on a mount copied into a
new user namespace, so mnt_attr gains bits 63..60 on most mounts of
every container, ours or LXC. A tool there that feeds mnt_attr back
into mount_setattr() attr_set got 0 before and gets EPERM now. I am
fine with that, but the message has to say it.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

* Re: [Devel] [PATCH vz10 v2 3/3] selftests/ve: test locking a mount from the host
  2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 3/3] selftests/ve: test locking a mount from the host Mirian Shilakadze
  2026-11-16  6:38   ` no-reply
@ 2026-11-16 17:13   ` Konstantin Khorenko
  1 sibling, 0 replies; 11+ messages in thread
From: Konstantin Khorenko @ 2026-11-16 17:13 UTC (permalink / raw)
  To: Mirian Shilakadze; +Cc: devel

I won't apply this version, please send v3 with the changes below.

On Mon, 16 Nov 2026 10:12:54 +0400, Mirian Shilakadze <mirian.shilakadze@virtuozzo.com> wrote:
> +TEST_F(lock, not_recursive)
> +{
> +	ASSERT_EQ(0, mount(SRC, DST, NULL, MS_BIND, NULL));
> +	ASSERT_EQ(-1, setattr(AT_FDCWD, DST, AT_RECURSIVE,
> +			      MOUNT_ATTR_VE_LOCK, 0));
> +	EXPECT_EQ(EINVAL, errno);
> +}

Items 1-3 of the cover letter reply:

- Lock DST without AT_RECURSIVE first and expect 0.
- Skip when not root, without user namespaces, or when the kernel
  lacks the lock bits.
- Check that statmount() reports the locks lock_mnt_tree() raised.

A kernel without the feature fails this test with EINVAL too, the
unknown bits are refused before AT_RECURSIVE is looked at. That is one
of the two tests the cover letter counts as passing on the stock
kernel.

FIXTURE_SETUP(lock) only asserts, so a run without root fails in
unshare(CLONE_NEWNS), and in_ct() turns a missing user namespace or
missing feature into a failure. The sibling ve tests SKIP when
geteuid() is not 0.

Patch 2 says statmount() reports kernel-raised locks as well; a mount
copied into a new user and mount namespace shows them, and no test
looks at it.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

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

end of thread, other threads:[~2026-11-16 17:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16  6:12 [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount Mirian Shilakadze
2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace Mirian Shilakadze
2026-11-16  6:24   ` no-reply
2026-11-16 17:13   ` Konstantin Khorenko
2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 2/3] fs: report the locks of a mount in statmount() Mirian Shilakadze
2026-11-16  6:17   ` no-reply
2026-11-16 17:13   ` Konstantin Khorenko
2026-11-16  6:12 ` [Devel] [PATCH vz10 v2 3/3] selftests/ve: test locking a mount from the host Mirian Shilakadze
2026-11-16  6:38   ` no-reply
2026-11-16 17:13   ` Konstantin Khorenko
2026-11-16 17:13 ` [Devel] [PATCH vz10 v2 0/3] fs: let the host lock the protection flags of a mount Konstantin Khorenko

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