On 11/16/26 18:32, [email protected] wrote:
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 <[email protected]>

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?

Already replied.


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.


Already replied.

[ ... ]

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?

Well, if you tried to use descriptor without ovl_override_creds, it is
your fault.

The idea of allowing revert after ovl_override_creds failure is to avoid
big code rework when early return of ovl_override_creds would require
unlocking/cleanup.


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

You make me cry.


[ ... ]

@@ -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?

Yes, replied already.


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


--
Best regards, Riabchun Vladimir
Linux Kernel Developer, Virtuozzo

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to