All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: Mirian Shilakadze <mirian.shilakadze@virtuozzo.com>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH vz10] fs: let the protection flags of a mount be locked from userspace
Date: Thu, 12 Nov 2026 17:05:46 +0100	[thread overview]
Message-ID: <179449954661.4060562.4766019607878285221.b4-review@b4> (raw)
In-Reply-To: <20261012102058.46896-1-mirian.shilakadze@virtuozzo.com>

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

On Mon, 12 Oct 2026 14:20:34 +0400, Mirian Shilakadze <mirian.shilakadze@virtuozzo.com> wrote:
> Add MOUNT_ATTR_VE_LOCK to mount_setattr(). In attr_set it locks those
> of the four protections the call leaves set, in attr_clr it drops the
> locks. Only a host task with CAP_SYS_ADMIN in the initial user
> namespace may use it. MNT_LOCKED is not raised, so the container can
> still unmount the bind.

- Drop the tools/perf copy of the define.
- Make the lock readable, e.g. in statmount() mnt_attr or in
  mountinfo, so checkpoint/restore can keep it. If not in this patch,
  say in the message that C/R loses it.
- Say in the message that unlocking also drops the locks
  lock_mnt_tree() raised.
- Say in the message that a remount racing a lock can change the
  superblock and still fail with EPERM. Keep the code.
- ve_may_lock_mount(): one definition outside the #ifdef, keep the
  ve0 test, and name the setns() case in its comment.
- Fewer comment lines: move the rationale into the message.

The kernel logic itself looks right to me: the re-tests close the
remount race, the lock_mnt_tree() refactor is exact, and nothing
changes while nobody uses the flag.

> diff --git a/tools/perf/trace/beauty/include/uapi/linux/mount.h b/tools/perf/trace/beauty/include/uapi/linux/mount.h
[...]
> +#define MOUNT_ATTR_VE_LOCK	0x8000000000000000ULL

Sashiko is right here. fsmount.sh turns this define into entry 64 of
fsmount_attr_flags[], and on a 32-bit perf the flag printer then
shifts 1UL by more than 31. fsmount() can never pass this flag, so the
entry is dead anyway. Without the hunk check-headers.sh only warns.

> @@ -5230,8 +5278,33 @@ 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;
>
> +	kattr->ve_lock = !!(attr->attr_set & MOUNT_ATTR_VE_LOCK);

Sashiko and Pavel asked how the lock is read back, and it matters.
Nothing reports MNT_LOCK_*, so CRIU restores a locked bind as an
ordinary one. libvzctl relocks the configured binds after restore,
but not the binds the container made of them. Those were locked
before the dump, because clone_mnt() copies the bits. After restore
the container can remount them rw again.

> +	if (attr->attr_clr & MOUNT_ATTR_VE_LOCK)
> +		kattr->attr_clr |= MNT_LOCK_PROTECTION_MASK;

These are the same bits lock_mnt_tree() raises when a tree crosses a
user namespace. Until now nothing could clear them, now host root can,
on any mount it reaches. That is fine, but the message and the UAPI
comment have to say it.

> +				if (can_change_locked_flags(mnt, mnt_flags))
> +					set_mount_attributes(mnt, mnt_flags);
> +				else
> +					err = -EPERM;

This is Sashiko's first point, and it is real: mount_setattr() takes
neither s_umount nor the namespace lock, so a lock can land between
the first test and this one, after reconfigure_super() is done.
Testing earlier does not close the window. Only the owner of the
superblock gets here and the mount stays locked, so keep the code and
say it in the message.

> +static inline bool ve_may_lock_mount(void)
> +{
> +	return ve_is_super(get_exec_env()) && capable(CAP_SYS_ADMIN);
> +}
[...]
> +static inline bool ve_may_lock_mount(void) { return capable(CAP_SYS_ADMIN); }

ve_is_super() and get_exec_env() have CONFIG_VE=n stubs, so the
first definition works for both configs. The ve0 test is not excess,
as Pavel thought: host root can setns() into a container's ve
namespace and keep its init_user_ns credentials, and capable() is
then true. That is the case the comment should name.

> +/*
> + * Raise the MNT_LOCK_* twin of every protection @flags carries, so that whoever
> + * is given the mount cannot clear them again. Shared by lock_mnt_tree(), where
> + * the kernel locks a tree that crosses a user namespace, and by
> + * MOUNT_ATTR_VE_LOCK, where the host asks for it.
> + *
> + * Neither MNT_LOCKED nor MNT_LOCK_ATIME is raised here. lock_mnt_tree() adds
> + * both itself, while a mount locked through MOUNT_ATTR_VE_LOCK can still be
> + * unmounted and keeps its atime settable.
> + */

The patch adds far more comment lines than the code around it has.
The rationale here, in ve_may_lock_mount() and in the two blocks in
build_mount_kattr() belongs in the commit message. The second
paragraph is also inexact: lock_mnt_tree() adds MNT_LOCKED only to
mounts that are not on an expiry list.

Separate patches, not needed for this series. I created a task for it:

1. Pavel's idea to let the host raise MNT_LOCKED on the binds vzctl
   makes, so the container can neither unmount nor move them. A moved
   bind loses its --ext-mount-map key and CRIU fails the dump. Pavel
   has the task:
   https://virtuozzo.atlassian.net/browse/VSTOR-154914

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

      parent reply	other threads:[~2026-11-12 16:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 10:20 Mirian Shilakadze
2026-10-12 10:28 ` no-reply
2026-10-12 14:02 ` Pavel Tikhomirov
2026-11-12 16:05 ` Konstantin Khorenko [this message]

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=179449954661.4060562.4766019607878285221.b4-review@b4 \
    --to=khorenko@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=mirian.shilakadze@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.