Re: [PATCH] ovl: do not revalidate disconnected real dentries
From: Amir Goldstein
Date: Fri Dec 04 2026 - 06:53:36 EST
On Fri, Dec 4, 2026 at 4:19 AM Song Yan via B4 Relay
<devnull+imeoer.gmail.com@xxxxxxxxxx> wrote:
>
> From: Song Yan <imeoer@xxxxxxxxx>
>
> When looking up a copied-up non-directory file with a lower origin
> after dcache eviction (e.g. drop_caches=2), ovl_lookup() decodes
> trusted.overlay.origin via exportfs_decode_fh() -> d_obtain_alias() and
> stores the resulting disconnected dentry (d_parent == d, d_name == "/")
> in oe->lowerstack[0].dentry.
>
> On the next cached lookup, ovl_revalidate_real() invokes
> d->d_op->d_revalidate(dir, &n.name, d, flags) on that disconnected
> dentry, passing d's own non-directory inode as dir and "/" as name.
> VFS never calls ->d_revalidate() on IS_ROOT() dentries, and on a FUSE
> lowerdir this fails persistently with -ESTALE: since 6.16 (commits
> 2396356a945b and 5a6baf204610) the d_obtain_alias() dentry has epoch 0
So it is since v7.1 (when both commits exist)
> while fc->epoch starts at 1, so fuse_dentry_revalidate() returns 0
> immediately; on older kernels fuse_get_dentry() invalidates the entry
> timeout and fuse_dentry_revalidate() sends FUSE_LOOKUP(file_ino, "/"),
> which fails with -ENOTDIR. Because ovl_revalidate_real() turns 0 into
> -ESTALE without dropping the overlay dentry, subsequent accesses keep
> failing until the overlay dentry is evicted.
>
> Reproducer with a FUSE lowerdir:
>
> mount -t overlay ovl \
> -o lowerdir=lower,upperdir=upper,workdir=work,index=on merged
index=on is not needed for the repro AFAICT
decoding of origin happens regardless
(I don't think we have a way to opt-out of it)
> echo copied >> merged/f
> sync && echo 2 > /proc/sys/vm/drop_caches
> stat merged/f # ok
> cat merged/f # ESTALE
>
> Skip ->d_revalidate() in ovl_revalidate_real() when parent == d. The
> upper dentry is still revalidated as usual, and a disconnected lower
> origin (or mount root) has no parent-child name binding to revalidate.
>
Thanks for reporting this bug!
> Fixes: 5be1fa8abd7b ("Pass parent directory inode and expected name to ->d_revalidate()")
I think the bug predates this commit, probably:
Fixes: a9d019573e88 ("ovl: lookup non-dir copy-up-origin by file handle")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Song Yan <imeoer@xxxxxxxxx>
> ---
> fs/overlayfs/super.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
> index e61aab199..51150b4e8 100644
> --- a/fs/overlayfs/super.c
> +++ b/fs/overlayfs/super.c
> @@ -104,6 +104,15 @@ static int ovl_revalidate_real(struct dentry *d, unsigned int flags, bool weak)
> parent = dget_parent(d);
> dir = d_inode(parent);
> }
> + /*
> + * A disconnected lower origin dentry or mount root has no
> + * parent directory or real component name to revalidate.
> + */
> + if (parent == d) {
> + if (!(flags & LOOKUP_RCU))
> + dput(parent);
> + return 1;
> + }
simpler, before dget_parent()
/* Like the VFS, do not revalidate a root or disconnected dentry */
if (IS_ROOT(d))
return 1;
Thanks,
Amir,