mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] fs/ntfs3: fix double ni_unlock() in ntfs_readdir()
@ 2026-12-03 15:45 Shuai Liu
  2026-12-04 21:31 ` Ernest Borowski
  2026-12-05 11:18 ` Christian Aurich Zanettini Martins
  0 siblings, 2 replies; 3+ messages in thread
From: Shuai Liu @ 2026-12-03 15:45 UTC (permalink / raw)
  To: almaz.alexandrovich, ntfs3
  Cc: christian.aurichzm, yun.zhou, syzbot+5c0ed4f2974a8b100ed4, linux-kernel

From: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>

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@gmail.com>
Fixes: 7a5aa6c45072 ("ntfs3: release ni_lock before dir_emit in ntfs_readdir to fix deadlocks")
Reported-by: syzbot+5c0ed4f2974a8b100ed4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5c0ed4f2974a8b100ed4
Link: https://lore.kernel.org/all/20261023223533.686085-1-christian.aurichzm@gmail.com/ # v1
Link: https://lore.kernel.org/all/20261029052102.1585462-1-christian.aurichzm@gmail.com/ # v2
Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
Signed-off-by: Shuai Liu <847807867@qq.com>
---
 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] fs/ntfs3: fix double ni_unlock() in ntfs_readdir()
  2026-12-03 15:45 [PATCH v3] fs/ntfs3: fix double ni_unlock() in ntfs_readdir() Shuai Liu
@ 2026-12-04 21:31 ` Ernest Borowski
  2026-12-05 11:18 ` Christian Aurich Zanettini Martins
  1 sibling, 0 replies; 3+ messages in thread
From: Ernest Borowski @ 2026-12-04 21:31 UTC (permalink / raw)
  To: Shuai Liu
  Cc: almaz.alexandrovich, ntfs3, christian.aurichzm, yun.zhou,
	syzbot+5c0ed4f2974a8b100ed4, linux-kernel

Tested-by: Ernest Borowski <ernest.borowski.git@proton.me>

Our test [1] lists a directory of 3000 files three times, so every
listing fills the getdents64() buffer several times.  On the ntfs3 tree
at 6ad211033e3e it triggers the lockdep "bad unlock balance" warning on
Ubuntu and Arch.  With this patch each listing returns all 3000 names
and dmesg stays clean on both.

[1] https://github.com/xerrni/linux-ntfs/blob/master/tests/ntfs3_readdir_large.sh


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] fs/ntfs3: fix double ni_unlock() in ntfs_readdir()
  2026-12-03 15:45 [PATCH v3] fs/ntfs3: fix double ni_unlock() in ntfs_readdir() Shuai Liu
  2026-12-04 21:31 ` Ernest Borowski
@ 2026-12-05 11:18 ` Christian Aurich Zanettini Martins
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Aurich Zanettini Martins @ 2026-12-05 11:18 UTC (permalink / raw)
  To: brauner, almaz.alexandrovich
  Cc: 847807867, ernest.borowski.git, yun.zhou, ntfs3, linux-fsdevel,
	linux-kernel, syzbot+5c0ed4f2974a8b100ed4,
	Christian Aurich Zanettini Martins

Shuai Liu wrote:
> 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.

Thanks Shuai for resending, and Ernest for testing.

Christian, there's been no word from Konstantin on any version since
October, and this is a 7.4 regression that syzbot keeps hitting. Could
you take it through vfs.fixes?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-05 11:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 15:45 [PATCH v3] fs/ntfs3: fix double ni_unlock() in ntfs_readdir() Shuai Liu
2026-12-04 21:31 ` Ernest Borowski
2026-12-05 11:18 ` Christian Aurich Zanettini Martins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®