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 <[email protected]>

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/[email protected]?part=3

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to