[Devel] [PATCH v3 VZ10 1/1] fs: namespace: transform mount flags to comma separated values
Vladimir Riabchun
vladimir.riabchun at virtuozzo.com
Wed Jun 3 17:17:59 MSK 2026
On 6/3/26 14:32, Vasileios Almpanis wrote:
> In legacy mount callpaths, userspace might pass mount options as
> flags. These flags escape our checks in ve_devmnt_process allowing
> devices to be mounted inside containers with options not specified in
> ...
> +/*
> + * For legacy mount(2), MS_* mount flags are folded into fc->sb_flags and are
> + * not present in the monolithic data string. Build a page with user data
> + * followed by those flags for ve_devmnt checks in vfs_parse_monolithic_sep.
> + *
> + * Returns @data when nothing needs to be added, a new page otherwise, or
> + * ERR_PTR() on failure. The caller must free_page() when the result != @data.
> + */
> +void *legacy_merge_mount_data(struct fs_context *fc, void *data)
> +{
> + struct ve_struct *ve = get_exec_env();
> + size_t off = 0;
> + char *page;
> + int err;
> +
> + if (ve_is_super(ve))
> + return data;
> +
> + if (!fc->fs_type || !(fc->fs_type->fs_flags & FS_REQUIRES_DEV))
> + return data;
> +
> + /*
> + * Filesystems with binary mount data (e.g. btrfs) bypass option
> + * string parsing entirely, so our checks cannot apply here.
> + */
> + if (fc->fs_type->fs_flags & FS_BINARY_MOUNTDATA)
> + return data;
> +
> + page = (char *)__get_free_page(GFP_KERNEL);
> + if (!page)
> + return ERR_PTR(-ENOMEM);
> +
> + if (data && *(char *)data) {
> + ssize_t ret = strscpy(page, data, PAGE_SIZE);
> +
> + if (ret < 0) {
> + err = -E2BIG;
> + goto err_free;
> + }
> + off = ret;
> + }
> +
> + err = vfs_format_sb_flags(fc, page, PAGE_SIZE, &off);
> + if (err)
> + goto err_free;
> +
> + if (!off) {
Let's drop this check. It happens only when data is empty and no flags provided.
And it doesn't add any value - we just free page a little bit earlier.
Everything else looks good.
> + free_page((unsigned long)page);
> + return data;
> + }
> +
> + return page;
> +
> +err_free:
> + free_page((unsigned long)page);
> + return ERR_PTR(err);
> +}
> ...
--
Best regards, Riabchun Vladimir
Linux Kernel Developer, Virtuozzo
More information about the Devel
mailing list