[PATCH] ovl: do not revalidate disconnected real dentries

From: Song Yan via B4 Relay

Date: Thu Dec 03 2026 - 22:19:29 EST


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
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
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.

Fixes: 5be1fa8abd7b ("Pass parent directory inode and expected name to ->d_revalidate()")
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;
+ }
/* In RCU walk the dentry name may go away at any time */
if (!take_dentry_name_snapshot(&n, d))
return -ECHILD;

---
base-commit: 007722b8211f7b34fdf21b1e6a9c32497633ea29
change-id: 20261204-b4-ovl-disconnected-revalidate-58343ebb61ce

Best regards,
--
Song Yan <imeoer@xxxxxxxxx>