linux-stable/fs/exfat
Sungjong Seo e705b16800 exfat: release s_lock before calling dir_emit()
commit ff84772fd4 upstream.

There is a potential deadlock reported by syzbot as below:

======================================================
WARNING: possible circular locking dependency detected
6.4.0-next-20230707-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor330/5073 is trying to acquire lock:
ffff8880218527a0 (&mm->mmap_lock){++++}-{3:3}, at: mmap_read_lock_killable include/linux/mmap_lock.h:151 [inline]
ffff8880218527a0 (&mm->mmap_lock){++++}-{3:3}, at: get_mmap_lock_carefully mm/memory.c:5293 [inline]
ffff8880218527a0 (&mm->mmap_lock){++++}-{3:3}, at: lock_mm_and_find_vma+0x369/0x510 mm/memory.c:5344
but task is already holding lock:
ffff888019f760e0 (&sbi->s_lock){+.+.}-{3:3}, at: exfat_iterate+0x117/0xb50 fs/exfat/dir.c:232

which lock already depends on the new lock.

Chain exists of:
  &mm->mmap_lock --> mapping.invalidate_lock#3 --> &sbi->s_lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&sbi->s_lock);
                               lock(mapping.invalidate_lock#3);
                               lock(&sbi->s_lock);
  rlock(&mm->mmap_lock);

Let's try to avoid above potential deadlock condition by moving dir_emit*()
out of sbi->s_lock coverage.

Fixes: ca06197382 ("exfat: add directory operations")
Cc: stable@vger.kernel.org #v5.7+
Reported-by: syzbot+1741a5d9b79989c10bdc@syzkaller.appspotmail.com
Link: https://lore.kernel.org/lkml/00000000000078ee7e060066270b@google.com/T/#u
Tested-by: syzbot+1741a5d9b79989c10bdc@syzkaller.appspotmail.com
Signed-off-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-08-11 12:14:20 +02:00
..
Kconfig fs: build the legacy direct I/O code conditionally 2023-01-26 10:30:56 -07:00
Makefile exfat: add Kconfig and Makefile 2020-03-05 21:00:40 -05:00
balloc.c exfat: use kvmalloc_array/kvfree instead of kmalloc_array/kfree 2023-08-11 12:14:20 +02:00
cache.c exfat: fix use of uninitialized spinlock on error path 2020-10-07 14:27:13 +09:00
dir.c exfat: release s_lock before calling dir_emit() 2023-08-11 12:14:20 +02:00
exfat_fs.h Description for this pull request: 2023-03-01 08:42:27 -08:00
exfat_raw.h exfat: handle unreconized benign secondary entries 2023-02-27 21:14:46 +09:00
fatent.c exfat: fix the newly allocated clusters are not freed in error handling 2023-02-28 20:01:40 +09:00
file.c Description for this pull request: 2023-03-01 08:42:27 -08:00
inode.c exfat: fix inode->i_blocks for non-512 byte sector size device 2023-02-27 21:14:45 +09:00
misc.c exfat: Expand exfat_err() and co directly to pr_*() macro 2022-08-01 10:14:07 +09:00
namei.c Description for this pull request: 2023-03-01 08:42:27 -08:00
nls.c exfat: Drop superfluous new line for error messages 2022-08-01 10:14:07 +09:00
super.c exfat: fix inode->i_blocks for non-512 byte sector size device 2023-02-27 21:14:45 +09:00