From 422429d63fe12e7c4fbbb3211c4e0af149c22148 Mon Sep 17 00:00:00 2001 From: William Allen Date: Wed, 14 Oct 2026 12:51:44 -0500 Subject: [PATCH] fix: read the replaced listing's watch descriptor before detach can free it (#685) install() replaces an existing cache entry by calling detach(old), which destroys the listing when no reader holds it, and then reads old->wd to decide whether to release the watch. When the old listing has no readers, that read happens after the free. Two threads that enumerate the same uncached directory at the same time reach this path: both build a listing, the first installs an entry with no readers, and the second replaces it. Save the watch descriptor before detaching, as drop() already does. --- tools/linuxfs/preload/dircache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/linuxfs/preload/dircache.c b/tools/linuxfs/preload/dircache.c index bdfec14dad..c20c7d0b46 100644 --- a/tools/linuxfs/preload/dircache.c +++ b/tools/linuxfs/preload/dircache.c @@ -256,9 +256,10 @@ static void install(struct listing *l) { int slot = find(l->dev, l->ino); if (slot >= 0) { struct listing *old = table[slot]; + int old_wd = old->wd; table[slot] = l; detach(old); - if (old->wd != l->wd) release(old->wd); + if (old_wd != l->wd) release(old_wd); return; } int victim = -1;