Skip to contentSkip to conversation

autofs: set wait queue status before releasing waiters

PATCH New Zhenwen Liang 1 participant 1 message Nov 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 autofs: set wait queue status before releasing waiters

autofs_wait() waits without a lock for wq->name.name to become NULL and then reads wq->status:

	wait_event_killable(wq->queue, wq->name.name == NULL);
	status = wq->status;

autofs_wait_release() clears wq->name.name before it stores the status:

	wq->name.name = NULL;	/* Do not wait on this queue */
	wq->status = status;
	wake_up(&wq->queue);

wait_event_killable() tests the condition before it sleeps. A waiter that gets there after wq->name.name was cleared but before wq->status was stored does not sleep, and returns the initial status -EINTR even though the daemon reported success. The lookup then fails with EINTR. On weakly ordered CPUs nothing orders the two stores for the lockless reader either.

Store the status first, publish wq->name.name = NULL with smp_store_release(), and read it with smp_load_acquire() in autofs_wait(). autofs_catatonic_mode_locked() already stores the status first; use smp_store_release() there too.

Reproduced on v7.4-rc4 in QEMU with a debug-only patch, not part of this change, that delays the waiter before its first check and delays autofs_wait_release() between the two stores. A stat() that triggers a mount failed with EINTR in 5 of 5 runs, although the daemon answered AUTOFS_IOC_READY with status 0. With this patch stat() succeeded in 5 of 5 runs. Without the delays (one control run) we did not see the failure.

The problem was found with a Lean-based formal model of the code and AI-assisted analysis. The patch and this description were written with AI assistance; a human checked them against the source.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

---
autofs_wait_release() clears wq->name.name before it stores wq->status (fs/autofs/waitq.c:518-519 in v7.4-rc4), while autofs_wait() tests wq->name.name without a lock and then reads wq->status (453-454). A waiter that checks in between does not sleep and returns the initial -EINTR (line 413), although the daemon reported success. The same order is in next-20261123 and the stable branches we checked (5.10.y, 5.15.y, 6.1.y, 6.6.y, 6.12.y, 6.18.y, 7.3.y); it dates back to fs/autofs4.

Effect: a path walk that triggers a mount fails with EINTR. Any process can hit it by timing; no privilege boundary is involved.

Reproduced on v7.4-rc4 in QEMU (x86_64 TCG, 4 vCPUs) with a debug-only patch that adds mdelay() before the waiter's first check and between the two stores. A test program acts as the daemon (mounts a tmpfs, answers AUTOFS_IOC_READY with status 0) while a child stat()s the trigger path:

  v7.4-rc4 + delays:          stat() -> EINTR in 5 of 5 runs
  + this patch:               stat() OK in 5 of 5 runs
  no delays (1 control run):  stat() OK

Without the delays we did not see it, and we did not test a weakly ordered architecture. The debug patch, test program and logs are available on request.

syzbot's open "KCSAN: data-race in autofs_wait / autofs_wait" (extid c6d286fd51860df64d9a) concerns the global token counter, not these fields, as far as we can tell.

Found by a formal code verification tool under development (Lean-based), with AI-assisted analysis; verified by the reproduction above and human review. The patch and this text were written with AI assistance and reviewed by a human. Point of contact: Zhenwen Liang <[email protected]>.

A search of public list archives, git history and syzbot found no earlier report. Related, different race: the pending patch "autofs:
serialize allocation of global wait queue tokens" (Zhu Jun, 2026-11-11).

 fs/autofs/waitq.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fs/autofs/waitq.c +6 -3
index 92c0bbbf452b..2496786a463e 100644
@@ -29,7 +29,8 @@ static void autofs_catatonic_mode_locked(struct autofs_sb_info *sbi)
 		nwq = wq->next;
 		wq->status = -ENOENT; /* Magic is gone - report failure */
 		kfree(wq->name.name - wq->offset);
-		wq->name.name = NULL;
+		/* Pairs with smp_load_acquire() in autofs_wait() */
+		smp_store_release(&wq->name.name, NULL);
 		wake_up(&wq->queue);
 		if (!--wq->wait_ctr)
 			kfree(wq);
@@ -450,7 +451,8 @@ int autofs_wait(struct autofs_sb_info *sbi,
 	 * wq->name.name is NULL iff the lock is already released
 	 * or the mount has been made catatonic.
 	 */
-	wait_event_killable(wq->queue, wq->name.name == NULL);
+	/* Pairs with smp_store_release() in autofs_wait_release() */
+	wait_event_killable(wq->queue, !smp_load_acquire(&wq->name.name));
 	status = wq->status;
 
 	/*
@@ -515,8 +517,9 @@ int autofs_wait_release(struct autofs_sb_info *sbi,
 
 	*wql = wq->next;	/* Unlink from chain */
 	kfree(wq->name.name - wq->offset);
-	wq->name.name = NULL;	/* Do not wait on this queue */
 	wq->status = status;
+	/* Do not wait on this queue; pairs with autofs_wait() */
+	smp_store_release(&wq->name.name, NULL);
 	wake_up(&wq->queue);
 	if (!--wq->wait_ctr)
 		kfree(wq);
Signature · 1 line
2.56.1.809.ga0b61035b5-goog