Skip to content

ntfs3: fix deadlocks in ntfs_readdir caused by ni_lock held across dir_emit

Yun Zhou lkml ntfs3 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2ntfs3: remove ntfs_iget5 call in ntfs_dir_emit to fix recursive deadlockfs/ntfs3/dir.c+0 -160 replies
2/2ntfs3: release ni_lock before dir_emit in ntfs_readdir to fix deadlocksfs/ntfs3/dir.c+20 -21 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] ntfs3: fix deadlocks in ntfs_readdir caused by ni_lock held across dir_emit

Commit d62cf685d12e ("fs/ntfs3: hold ni_lock across readdir metadata walk") extended ni_lock to cover the entire directory walk in ntfs_readdir(), including dir_emit() calls that copy data to userspace. This introduced multiple deadlocks reported by syzkaller:

1. Recursive ni_lock: ntfs_dir_emit() -> ntfs_iget5() -> mi_read() tries to acquire ni_lock on a child inode with the same lock class while the parent's ni_lock is already held.

2. Lock-order inversions: dir_emit() may trigger page faults that need mmap_lock or mapping->invalidate_lock, conflicting with paths that acquire those locks before ni_lock (ntfs_fallocate, mmap).

This series fixes both issues:
- Patch 1 removes the ntfs_iget5() call that caused recursive locking.
- Patch 2 releases ni_lock before calling dir_emit(), using the XFS approach of reading data into stable buffers under the lock, then emitting to userspace after releasing it.

Yun Zhou (2):
ntfs3: remove ntfs_iget5 call in ntfs_dir_emit to fix recursive
deadlock
ntfs3: release ni_lock before dir_emit in ntfs_readdir to fix
deadlocks

 fs/ntfs3/dir.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)
Signature · 1 line
2.43.0