All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>,
	khorenko@virtuozzo.com, ptikhomirov@virtuozzo.com
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH vz10 v2 3/3] selftests/ve: test locking a mount from the host
Date: Mon, 16 Nov 2026 06:38:49 +0000	[thread overview]
Message-ID: <010701a1e3146ccc-d22110a0-066c-4e3e-8dcd-f9b80cd9b74a-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261116061256.54472-4-mirian.shilakadze@virtuozzo.com>

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

  reply	other threads:[~2026-11-16  6:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=010701a1e3146ccc-d22110a0-066c-4e3e-8dcd-f9b80cd9b74a-000000@eu-central-1.amazonses.com \
    --to=no-reply@sashiko.virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=mirian.shilakadze@virtuozzo.com \
    --cc=ptikhomirov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.