Skip to content

Commit

Permalink
fs/ntfs3: don't hold ni_lock when calling truncate_setsize()
Browse files Browse the repository at this point in the history
[ Upstream commit 0226635 ]

syzbot is reporting hung task at do_user_addr_fault() [1], for there is
a silent deadlock between PG_locked bit and ni_lock lock.

Since filemap_update_page() calls filemap_read_folio() after calling
folio_trylock() which will set PG_locked bit, ntfs_truncate() must not
call truncate_setsize() which will wait for PG_locked bit to be cleared
when holding ni_lock lock.

Link: https://lore.kernel.org/all/00000000000060d41f05f139aa44@google.com/
Link: https://syzkaller.appspot.com/bug?extid=bed15dbf10294aa4f2ae [1]
Reported-by: syzbot <syzbot+bed15dbf10294aa4f2ae@syzkaller.appspotmail.com>
Debugged-by: Linus Torvalds <torvalds@linux-foundation.org>
Co-developed-by: Hillf Danton <hdanton@sina.com>
Signed-off-by: Hillf Danton <hdanton@sina.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fixes: 4342306 ("fs/ntfs3: Add file operations and implementation")
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Tetsuo Handa authored and gregkh committed Jan 12, 2023
1 parent a23e837 commit 8414983
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/ntfs3/file.c
Expand Up @@ -488,10 +488,10 @@ static int ntfs_truncate(struct inode *inode, loff_t new_size)

new_valid = ntfs_up_block(sb, min_t(u64, ni->i_valid, new_size));

ni_lock(ni);

truncate_setsize(inode, new_size);

ni_lock(ni);

down_write(&ni->file.run_lock);
err = attr_set_size(ni, ATTR_DATA, NULL, 0, &ni->file.run, new_size,
&new_valid, ni->mi.sbi->options->prealloc, NULL);
Expand Down

0 comments on commit 8414983

Please sign in to comment.