All Virtuozzo development lists (kernel + QEMU)
 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 v7 6/6] ve/overlayfs: Override VE together with creds
Date: Mon, 16 Nov 2026 17:32:25 +0000	[thread overview]
Message-ID: <010701a1e56ad165-f5cf76ff-4ab0-42fd-af99-fbbe80bc922b-000000@eu-central-1.amazonses.com> (raw)
In-Reply-To: <20261116-ovl-use-orig-ve-v7-6-37daa56081ed@virtuozzo.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] ve/overlayfs: backing-file I/O paths switch creds without the
  VE
- [Low] ovl: ovl_lower_positive() returns false when
  ovl_override_creds() fails
- [Low] ovl: ovl_nlink_end() skips ovl_cleanup_index() with only pr_err
  on override failure
- [Low] ovl: ovl_revert_creds() relies on an IS_ERR(desc->ve) sentinel
  after failed override
--

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

ve/overlayfs: Override VE together with creds

This changes ovl_override_creds() to switch the VE together with the creator creds. It also adds ovl_revert_creds() and converts all callers. The aim is to stop ve_capable() checks inside overlayfs from running against a mismatched cred and VE when a host user accesses a CT-owned overlayfs.

> Modify ovl_override_creds so that it returns both old cred and old VE.
> This will also protect us from future rebase issues - all new users of
> old_cred and ovl_override_creds will fail with compilation error.

[Severity: Medium]
As reported by Pavel Tikhomirov on v2 [1], the backing-file I/O paths are not covered. ovl_read_iter(), ovl_write_iter(), ovl_splice_read(), ovl_splice_write() and ovl_mmap() set backing_file_ctx.cred = ovl_creds(sb). backing_file_read_iter() and its siblings then call only override_creds(ctx->cred), with no VE override.

A ve_capable() check in the underlying filesystem on those paths therefore still sees the creator cred with the caller's VE. Cross-CT access is also not rejected with -EPERM there.

The message says all users of the old cred are protected, but only callers of ovl_override_creds() were converted. Can the message state that these paths are left for a follow-up?

> 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;
> +
>  	/* Positive upper -> have to look up lower to see whether it exists */
>  	for (i = 0; !done && !positive && i < ovl_numlower(poe); i++) {
>  		struct dentry *this;

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

The loop below already treats a lookup error as "assume something is there" (positive = true). Returning false here makes ovl_do_remove() pick ovl_remove_upper() instead of ovl_remove_and_whiteout(), and ovl_rename() skip RENAME_WHITEOUT. A lower entry could then reappear after unlink.

This is masked today only because the later ovl_override_creds() calls in those functions fail the same way for the same task and sb. Correctness depends on that call ordering. Returning true would be consistent with the error handling in the loop.

[ ... ]

> 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;
> +}
> +
> +/* 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);
>  }

[Severity: Low]
This isn't a bug today, but ovl_revert_creds() is a no-op after a failed ovl_override_creds() only because the failure leaves an ERR_PTR in desc->ve. Some callers return early on failure, while others fall through to ovl_revert_creds(). That inconsistency is why several sites need awkward "if (!err)" guards.

Any new early error return added before override_ve(), or a revert on a descriptor that never went through ovl_override_creds(), would end up in revert_creds(NULL). ovl_rename() already pre-initializes old_cred = {} for this reason. Would an explicit flag in the descriptor, or callers returning early on error, be clearer?

The commit message also says ovl_override_creds "returns both old cred and old VE". It now returns an int and fills a descriptor.

[ ... ]

> @@ -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);
>  	}
>  
>  	ovl_inode_unlock(inode);

[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 with i_nlink 0 is left behind and the caller is not told.

The path should be mostly unreachable, since ovl_nlink_start() calls ovl_override_creds() earlier in the same operation and would normally fail first. A rate-limited message or a WARN_ON_ONCE would fit better than a plain pr_err() that can flood the log.

[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-v7-0-37daa56081ed@virtuozzo.com?part=6

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

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

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 17:18 [Devel] [PATCH hci-8.1 v7 0/6] Fix kernel crash in overlayfs Vladimir Riabchun
2026-11-16 17:18 ` [Devel] [PATCH hci-8.1 v7 1/6] ve: Remove STOPPED state Vladimir Riabchun
2026-11-16 17:23   ` no-reply
2026-11-16 17:35     ` Vladimir Riabchun
2026-11-16 17:18 ` [Devel] [PATCH hci-8.1 v7 2/6] ve: Introduce override_ve/revert_ve helpers Vladimir Riabchun
2026-11-16 17:25   ` no-reply
2026-11-16 17:18 ` [Devel] [PATCH hci-8.1 v7 3/6] ve: Defer ve creds drop until ve is completely destroyed Vladimir Riabchun
2026-11-16 17:26   ` no-reply
2026-11-16 17:18 ` [Devel] [PATCH hci-8.1 v7 4/6] ovl: Keep creator VE in overlayfs superblock Vladimir Riabchun
2026-11-16 17:27   ` no-reply
2026-11-16 17:18 ` [Devel] [PATCH hci-8.1 v7 5/6] ovl: Fix leaking fd references in ovl_copyfile Vladimir Riabchun
2026-11-16 17:27   ` no-reply
2026-11-16 17:18 ` [Devel] [PATCH hci-8.1 v7 6/6] ve/overlayfs: Override VE together with creds Vladimir Riabchun
2026-11-16 17:32   ` no-reply [this message]
2026-11-16 17:45     ` Vladimir Riabchun
2026-11-16 17:43 ` [Devel] [PATCH hci-8.1 v7 0/6] Fix kernel crash in overlayfs Konstantin Khorenko
2026-11-16 20:22   ` 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=010701a1e56ad165-f5cf76ff-4ab0-42fd-af99-fbbe80bc922b-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 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.