[Devel] [PATCH vz10 v2 1/3] fs: let the protection flags of a mount be locked from userspace

no-reply at sashiko.virtuozzo.com no-reply at sashiko.virtuozzo.com
Mon Nov 16 09:24:13 MSK 2026


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



More information about the Devel mailing list