[BUG] WARNING: bad unlock balance in ntfs_readdir (fs/ntfs3/dir.c:625, v7.4-rc3)
From: Zheng Zheng
Date: Tue Nov 17 2026 - 01:51:52 EST
Hi Konstantin,
We found a reproducible lockdep bad-unlock-balance in ntfs3 on v7.4-rc3
with syzkaller.
Warning:
WARNING: bad unlock balance detected!
7.4.0-rc3-kernsight-kasan #1
-------------------------------------
syz-executor/10086 is trying to release lock (&ni->ni_lock) at:
[<ffffffff833e9657>] ni_unlock fs/ntfs3/ntfs_fs.h:1267 [inline]
[<ffffffff833e9657>] ntfs_readdir+0x7e7/0x1170 fs/ntfs3/dir.c:625
but there are no more locks to release!
Call trace:
__dump_stack
dump_stack_lvl
print_unlock_imbalance_bug
__lock_release
lock_release
__mutex_unlock_slowpath
ni_unlock fs/ntfs3/ntfs_fs.h:1267
ntfs_readdir fs/ntfs3/dir.c:625
iterate_dir
__do_sys_getdents64
__x64_sys_getdents64
do_syscall_64
The reproducer mounts a crafted NTFS3 image. The log also shows a sector
size mismatch:
ntfs3(loop4): Different NTFS sector size (4096) and media sector size (512).
That mismatch is an observed reproduction detail; we have not established it
as the cause of the double unlock.
Analysis: in ntfs_readdir(), the code drops ni->ni_lock before
ntfs_read_hdr()/dir_emit() and reacquires it afterwards. If
ntfs_read_hdr() returns a non-zero value, the `goto out` path skips the
re-lock, and `out` calls ni_unlock() again. This includes negative errors
and the `+1` "directory buffer is full" return value:
ni_unlock(ni);
err = ntfs_read_hdr(...);
if (err)
goto out; /* ni_lock is not held here */
ni_lock(ni);
out:
ni_unlock(ni); /* double unlock on this error path */
A reasonable fix is to distinguish the two cleanup paths instead of
unconditionally re-locking: after the explicit ni_unlock(), a non-zero
return from ntfs_read_hdr() should jump to a cleanup label that does not
call ni_unlock(); the normal out path should still unlock. A bool lock_held
flag or a separate out_unlocked label can express this clearly.
How to reproduce stably:
1. Build vanilla v7.4-rc3 with:
CONFIG_KASAN=y
CONFIG_PROVE_LOCKING=y
CONFIG_NTFS3_FS=y
CONFIG_DEBUG_INFO=y
The bzImage used here has sha256
0c16409f8aec508ac44a63e631c2bd352536401f3fd0856df1d839fb953a1882.
2. Boot a Debian trixie x86_64 guest (6 GiB RAM, 4 vCPU, KVM) with at least:
root=/dev/sda console=ttyS0 oops=panic panic_on_warn=1
The full QEMU command line is in environment.txt.
3. Copy syz-execprog and syz-executor built from syzkaller commit
853b104bb454141a5b0fc0e4218ec78e9f34ffb1, plus
reproducer/repro.kernsight.prog, into the guest.
4. In the guest, as root, run:
syz-execprog -procs=8 -threaded -repeat=1 \
-executor ./syz-executor repro.kernsight.prog
Expected result: "bad unlock balance detected" with
ntfs_readdir+0x7e7/0x1170 after roughly 120-145 seconds. This is a lockdep
report, not a panic; panic_on_warn=1 did not escalate this particular
lockdep path in our runs, so serial/dmesg is the success signal. We observed
the hit 4/4 on fresh VMs (runs 1-2 with -repeat=0; runs 3-4 with a single
ordered -repeat=1 pass):
Run 1: 138.18 s
Run 2: 144.69 s
Run 3: 119.98 s
Run 4: 141.08 s
Source/line-number check: the unlock is at fs/ntfs3/dir.c:625 in the
v7.4-rc3 tree used here. The file is identical to the torvalds v7.4-rc3 tag
(sha256 86fa0e100b32c38980b72767cfb905acacebe8b7c7eb26c39bf13b6bde5cd768);
addr2line maps ntfs_readdir+0x7e7 to line 627 (adjacent/inlined unlock),
consistent with the reported line 625.
The reproducer is a 177-entry state-reconstruction recipe (168 replay
entries + 8 priming programs + the triggering testcase) and is
self-contained. The old 1131-program external program set is not needed.
Repository contents (all v7.4-rc3):
https://github.com/Zheng-zheng-codes/ntfs-readdir-bad-unlock-balance
- README.md: phenomenon, root-cause analysis, stable reproduction steps
and verification results.
- MINIMIZATION.md: notes on reducing the old 1131-program set to the
current 177-entry rc3 recipe.
- environment.txt: rc3 kernel/guest image hashes, QEMU command line and
syzkaller revision.
- kernel.config: v7.4-rc3 kernel configuration.
- reproducer/repro.kernsight.prog: 177-entry self-contained state recipe.
- reproducer/repro.priming.prog: state-priming portion.
- reproducer/repro.prog: triggering testcase.
- reproducer/repro.report, repro.stats, repro.outcomes.jsonl,
repro.context.json: pipeline verification evidence.
- logs/log-0.txt, logs/report-0.txt: original rc3 syzkaller log and crash
report.
- logs/machineInfo-0.txt, logs/title-stat.json: guest environment and title
statistics.
- logs/external-verification/: full serial consoles and run records for
all four fresh-VM reproductions listed above.
- logs/external-verification/verification-summary.txt: concise reproduction
summary and hashes.
- SHA256SUMS: checksums for the inputs and logs.
Is this error path the intended one to fix, or am I missing another place
that should hold ni_lock before reaching out?
Best regards,
Zheng Zheng