[PATCH v3] fs/ntfs3: fix double ni_unlock() in ntfs_readdir()
From: Shuai Liu
Date: Thu Dec 03 2026 - 10:45:20 EST
From: Christian Aurich Zanettini Martins <christian.aurichzm@xxxxxxxxx>
ntfs_readdir() drops ni_lock before each ntfs_read_hdr() call and jumps
to out if the call returns non-zero. As posted, the patch that became
commit 7a5aa6c45072 ("ntfs3: release ni_lock before dir_emit in
ntfs_readdir to fix deadlocks") used out as the label after ni_unlock().
It was applied on top of commit fb058ccff579 ("fs/ntfs3: take ni_lock()
once in ntfs_readdir()"), which renamed out_unlock to out, so these
jumps now unlock a lock that is no longer held.
This also happens when getdents64() fills the supplied buffer,
triggering a lockdep "bad unlock balance" warning.
Jump to out_free instead to avoid unlocking an already released lock.
v1 [1] and v2 [2] of this patch received no maintainer response while
the bug kept crashing; re-sending unchanged as v3 on behalf of the
original author, with the syzbot report tags added.
From: Christian Aurich Zanettini Martins <christian.aurichzm@xxxxxxxxx>
Fixes: 7a5aa6c45072 ("ntfs3: release ni_lock before dir_emit in ntfs_readdir to fix deadlocks")
Reported-by: syzbot+5c0ed4f2974a8b100ed4@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=5c0ed4f2974a8b100ed4
Link: https://lore.kernel.org/all/20261023223533.686085-1-christian.aurichzm@xxxxxxxxx/ # v1
Link: https://lore.kernel.org/all/20261029052102.1585462-1-christian.aurichzm@xxxxxxxxx/ # v2
Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@xxxxxxxxx>
Signed-off-by: Shuai Liu <847807867@xxxxxx>
---
fs/ntfs3/dir.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c
index 7ee1a5d4189e4..a7f910a0923b4 100644
--- a/fs/ntfs3/dir.c
+++ b/fs/ntfs3/dir.c
@@ -572,7 +572,7 @@ static int ntfs_readdir(struct file *file, struct dir_context *ctx)
*/
err = ntfs_read_hdr(sbi, ni, &root->ihdr, 0, pos, name, ctx);
if (err)
- goto out;
+ goto out_free;
ni_lock(ni);
bit = 0;
@@ -616,7 +616,7 @@ static int ntfs_readdir(struct file *file, struct dir_context *ctx)
((u64)bit << index_bits) + sbi->record_size,
pos, name, ctx);
if (err)
- goto out;
+ goto out_free;
ni_lock(ni);
}
@@ -624,6 +624,7 @@ static int ntfs_readdir(struct file *file, struct dir_context *ctx)
out:
ni_unlock(ni);
+out_free:
kfree(name);
put_indx_node(node);
--
2.43.0