[PATCH v2] ovl: do not revalidate disconnected real dentries

From: Song Yan via B4 Relay

Date: Fri Dec 04 2026 - 18:14:39 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 v7.1 (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 (index=on ensures origin decoding is
enabled for FUSE's null s_uuid even when redirect_dir/xino are off):

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

Check IS_ROOT(d) before fetching the parent in ovl_revalidate_real()
and return 1, matching VFS behavior. The upper dentry is still
revalidated as usual, and a root or disconnected lower origin dentry
has no parent-child name binding to revalidate.

Fixes: a9d019573e88 ("ovl: lookup non-dir copy-up-origin by file handle")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Song Yan <imeoer@xxxxxxxxx>
---
Changes in v2:
- Check IS_ROOT(d) before fetching the parent in ovl_revalidate_real()
as suggested by Amir Goldstein.
- Update Fixes tag to a9d019573e88 ("ovl: lookup non-dir copy-up-origin
by file handle").
- Update the FUSE epoch regression version from 6.16 to v7.1.
- Keep index=on in the reproducer (FUSE leaves sb->s_uuid null, so
ovl_lower_uuid_ok() disables origin decoding when
ovl_allow_offline_changes() is true).
- Link to v1: https://patch.msgid.link/20261204-b4-ovl-disconnected-revalidate-v1-1-f9bf277d1a43@xxxxxxxxx
---
fs/overlayfs/super.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index e61aab199..94e1d00ce 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -95,6 +95,10 @@ static int ovl_revalidate_real(struct dentry *d, unsigned int flags, bool weak)
struct inode *dir;
struct name_snapshot n;

+ /* Like the VFS, do not revalidate a root or disconnected dentry */
+ if (IS_ROOT(d))
+ return 1;
+
if (flags & LOOKUP_RCU) {
parent = READ_ONCE(d->d_parent);
dir = d_inode_rcu(parent);

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

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