OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: no-reply@sashiko.virtuozzo.com
To: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>,
	vasileios.almpanis@virtuozzo.com, ptikhomirov@virtuozzo.com,
	Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v6 5/5] ve/overlayfs: Override VE together with creds
Date: Mon, 16 Nov 2026 16:19:43 +0000	[thread overview]
Message-ID: <010701a1e5284447-b31d6973-b049-4d23-a230-4a76e40a14be-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261116-ovl-use-orig-ve-v6-5-7cfb41c8c973@virtuozzo.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ovl: ovl_copyfile() leaks real_in/real_out refs when override
  fails
- [Medium] ve/overlayfs: backing-file I/O switches creds without the
  matching VE override
- [Low] ovl: ovl_lower_positive() returns false when
  ovl_override_creds() fails
- [Low] ovl: ovl_nlink_end() silently skips index cleanup on override
  failure
--

commit 9665af403c75ade64577a4c77c18a22fb272209d
Author: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>

ve/overlayfs: Override VE together with creds

ovl_override_creds() now returns an error and fills a struct ovl_creds_desc holding both the old cred and the old VE. ovl_revert_creds() restores both. Every caller is converted, so overlayfs switches the VE together with the creator creds. Access to an overlayfs created in a different CT is rejected with -EPERM.

> diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
> index 2531433f47bf..464699e51695 100644
> --- a/fs/overlayfs/file.c
> +++ b/fs/overlayfs/file.c

[ ... ]

> @@ -520,14 +527,19 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
>  	 * verify read access with the source mounter creds.
>  	 */
>  	if (unlikely(inode_in->i_sb != inode_out->i_sb)) {
> -		old_cred = ovl_override_creds(inode_in->i_sb);
> +		ret = ovl_override_creds(inode_in->i_sb, &old_cred);
> +		if (ret)
> +			goto out_unlock;
>  		ret = rw_verify_area(READ, fd_file(real_in), &pos_in, len);
> -		revert_creds(old_cred);
> +		ovl_revert_creds(&old_cred);
>  		if (unlikely(ret))
>  			goto out_unlock;
>  	}

[Severity: Medium]
Does this new error exit leak the real_in and real_out file references?

Both were taken by ovl_real_fdget() earlier in ovl_copyfile(), but out_unlock only calls inode_unlock(inode_out), so fdput() is never reached. Before this patch the override could not fail, so the leak is a regression. A task in one CT doing copy_file_range() between its own overlayfs and one created by another CT gets -EPERM from override_VE() and leaks both files on every attempt. The second ovl_override_creds() failure below already uses skip_switch, which reaches the fdput() calls.

[ ... ]

> diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
> index efa2a072aa69..edc11a7b27ee 100644
> --- a/fs/overlayfs/namei.c
> +++ b/fs/overlayfs/namei.c

[ ... ]

> @@ -1426,7 +1436,10 @@ bool ovl_lower_positive(struct dentry *dentry)
>  	if (!ovl_dentry_upper(dentry))
>  		return true;
>  
> -	old_cred = ovl_override_creds(dentry->d_sb);
> +	/* Ugh, hard - we can't pass an error from here. */
> +	if (ovl_override_creds(dentry->d_sb, &old_cred))
> +		return false;
> +

[Severity: Low]
Is false the safe answer when the override fails?

Returning false means "no lower entry exists", so ovl_do_remove() would choose ovl_remove_upper() instead of ovl_remove_and_whiteout(), and ovl_rename() would skip RENAME_WHITEOUT. A lower file could then reappear after unlink. In practice the later override calls in the same operation fail the same way, but correctness then depends on call ordering.

The lookup-error branch of this function already assumes "something is there" and sets positive = true. Would returning true here be consistent with that?

[ ... ]

> diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
> index 817563215001..273b2e2e17eb 100644
> --- a/fs/overlayfs/util.c
> +++ b/fs/overlayfs/util.c
> @@ -63,11 +63,38 @@ struct dentry *ovl_workdir(struct dentry *dentry)
>  	return ofs->workdir;
>  }
>  
> -const struct cred *ovl_override_creds(struct super_block *sb)
> +/* On error no revert is needed. */
> +int ovl_override_creds(struct super_block *sb, struct ovl_creds_desc *desc)
>  {
>  	struct ovl_fs *ofs = OVL_FS(sb);
>  
> -	return override_creds(ofs->creator_cred);
> +	/* Cleanup after previous users */
> +	*desc = (struct ovl_creds_desc) {};
> +
> +	if (ve_is_super(ofs->creator_ve) && !ve_is_super(get_exec_env())) {
> +		/* Host overlayfs used from a CT: host creds work there. */
> +		desc->ve = NULL;
> +		desc->ve_overridden = false;
> +	} else {
> +		desc->ve = override_ve(ofs->creator_ve);
> +		if (IS_ERR(desc->ve))
> +			return PTR_ERR(desc->ve);
> +		desc->ve_overridden = true;
> +	}
> +
> +	desc->cred = override_creds(ofs->creator_cred);
> +	return 0;
> +}

[Severity: Medium]
As reported by Pavel Tikhomirov on v2 [1], the conversion is incomplete. Are the users of ovl_creds() still left with the cred/VE mismatch this patch describes?

ovl_read_iter(), ovl_write_iter(), ovl_splice_read(), ovl_splice_write() and ovl_mmap() set backing_file_ctx.cred = ovl_creds(sb). The helpers in fs/backing-file.c then call only override_creds(ctx->cred), with no override_ve(). ve_capable() uses current->overrided_ve ?: get_exec_env(), so on these paths the creator creds are still checked against the caller's VE. A host task reading a file on a CT overlayfs is one such case. Cross-CT access is also not rejected there with -EPERM, unlike the paths converted here. The commit message suggests all users of the old cred are covered, which is not the case.

> +
> +/* Accepts desc from a failed ovl_override_creds and does nothing. */
> +void ovl_revert_creds(struct ovl_creds_desc *old_creds)
> +{
> +	if (IS_ERR(old_creds->ve))
> +		return;
> +
> +	revert_creds(old_creds->cred);
> +	if (old_creds->ve_overridden)
> +		revert_ve(old_creds->ve);
>  }

[ ... ]

> @@ -1228,11 +1258,15 @@ void ovl_nlink_end(struct dentry *dentry)
>  	ovl_drop_write(dentry);
>  
>  	if (ovl_test_flag(OVL_INDEX, inode) && inode->i_nlink == 0) {
> -		const struct cred *old_cred;
> +		struct ovl_creds_desc old_cred;
> +		int err;
>  
> -		old_cred = ovl_override_creds(dentry->d_sb);
> -		ovl_cleanup_index(dentry);
> -		revert_creds(old_cred);
> +		err = ovl_override_creds(dentry->d_sb, &old_cred);
> +		if (err)
> +			pr_err("%s: skipping ovl_cleanup_index.\n", __func__);
> +		else
> +			ovl_cleanup_index(dentry);
> +		ovl_revert_creds(&old_cred);
>  	}

[Severity: Low]
Is it acceptable to silently skip ovl_cleanup_index() here?

ovl_nlink_end() is void and runs after the upper unlink or rename has already succeeded. If the override fails, an orphan index entry is left behind with i_nlink at 0, and only a pr_err() records it. The old code could not fail at this point. ovl_nlink_start() would normally have failed first for the same task, sb and VE, so this looks mostly unreachable. But it is an error path that now leaves stale state.

[1] https://lore.kernel.org/r/179318868950.3559520.6473416824609223980.b4-review@b4

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261116-ovl-use-orig-ve-v6-0-7cfb41c8c973@virtuozzo.com?part=5

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

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

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:06 [Devel] [PATCH hci-8.1 v6 0/5] Fix kernel crash in overlayfs Vladimir Riabchun
2026-11-16 16:06 ` [Devel] [PATCH hci-8.1 v6 1/5] ve: Remove STOPPED state Vladimir Riabchun
2026-11-16 16:10   ` no-reply
2026-11-16 16:25     ` Vladimir Riabchun
2026-11-16 16:06 ` [Devel] [PATCH hci-8.1 v6 2/5] ve: Introduce override_ve/revert_ve helpers Vladimir Riabchun
2026-11-16 16:12   ` no-reply
2026-11-16 16:06 ` [Devel] [PATCH hci-8.1 v6 3/5] ve: Defer ve creds drop until ve is completely destroyed Vladimir Riabchun
2026-11-16 16:14   ` no-reply
2026-11-16 16:06 ` [Devel] [PATCH hci-8.1 v6 4/5] ovl: Keep creator VE in overlayfs superblock Vladimir Riabchun
2026-11-16 16:13   ` no-reply
2026-11-16 16:06 ` [Devel] [PATCH hci-8.1 v6 5/5] ve/overlayfs: Override VE together with creds Vladimir Riabchun
2026-11-16 16:19   ` no-reply [this message]
2026-11-16 16:52     ` Vladimir Riabchun

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=010701a1e5284447-b31d6973-b049-4d23-a230-4a76e40a14be-000000@eu-central-1.amazonses.com \
    --to=no-reply@sashiko.virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=ptikhomirov@virtuozzo.com \
    --cc=vasileios.almpanis@virtuozzo.com \
    --cc=vladimir.riabchun@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox