1. 14 Jul, 2023 1 commit
    • Sungjong Seo's avatar
      exfat: release s_lock before calling dir_emit() · ff84772f
      Sungjong Seo authored
      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: ca061973 ("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: default avatarSungjong Seo <sj1557.seo@samsung.com>
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      ff84772f
  2. 13 Jul, 2023 1 commit
    • Namjae Jeon's avatar
      exfat: check if filename entries exceeds max filename length · d4233457
      Namjae Jeon authored
      exfat_extract_uni_name copies characters from a given file name entry into
      the 'uniname' variable. This variable is actually defined on the stack of
      the exfat_readdir() function. According to the definition of
      the 'exfat_uni_name' type, the file name should be limited 255 characters
      (+ null teminator space), but the exfat_get_uniname_from_ext_entry()
      function can write more characters because there is no check if filename
      entries exceeds max filename length. This patch add the check not to copy
      filename characters when exceeding max filename length.
      
      Cc: stable@vger.kernel.org
      Cc: Yuezhang Mo <Yuezhang.Mo@sony.com>
      Reported-by: default avatarMaxim Suhanov <dfirblog@gmail.com>
      Reviewed-by: default avatarSungjong Seo <sj1557.seo@samsung.com>
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      d4233457
  3. 11 Jul, 2023 1 commit
    • gaoming's avatar
      exfat: use kvmalloc_array/kvfree instead of kmalloc_array/kfree · daf60d6c
      gaoming authored
      The call stack shown below is a scenario in the Linux 4.19 kernel.
      Allocating memory failed where exfat fs use kmalloc_array due to
      system memory fragmentation, while the u-disk was inserted without
      recognition.
      Devices such as u-disk using the exfat file system are pluggable and
      may be insert into the system at any time.
      However, long-term running systems cannot guarantee the continuity of
      physical memory. Therefore, it's necessary to address this issue.
      
      Binder:2632_6: page allocation failure: order:4,
       mode:0x6040c0(GFP_KERNEL|__GFP_COMP), nodemask=(null)
      Call trace:
      [242178.097582]  dump_backtrace+0x0/0x4
      [242178.097589]  dump_stack+0xf4/0x134
      [242178.097598]  warn_alloc+0xd8/0x144
      [242178.097603]  __alloc_pages_nodemask+0x1364/0x1384
      [242178.097608]  kmalloc_order+0x2c/0x510
      [242178.097612]  kmalloc_order_trace+0x40/0x16c
      [242178.097618]  __kmalloc+0x360/0x408
      [242178.097624]  load_alloc_bitmap+0x160/0x284
      [242178.097628]  exfat_fill_super+0xa3c/0xe7c
      [242178.097635]  mount_bdev+0x2e8/0x3a0
      [242178.097638]  exfat_fs_mount+0x40/0x50
      [242178.097643]  mount_fs+0x138/0x2e8
      [242178.097649]  vfs_kern_mount+0x90/0x270
      [242178.097655]  do_mount+0x798/0x173c
      [242178.097659]  ksys_mount+0x114/0x1ac
      [242178.097665]  __arm64_sys_mount+0x24/0x34
      [242178.097671]  el0_svc_common+0xb8/0x1b8
      [242178.097676]  el0_svc_handler+0x74/0x90
      [242178.097681]  el0_svc+0x8/0x340
      
      By analyzing the exfat code,we found that continuous physical memory
      is not required here,so kvmalloc_array is used can solve this problem.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatargaoming <gaoming20@hihonor.com>
      Signed-off-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
      daf60d6c
  4. 09 Jul, 2023 10 commits
  5. 08 Jul, 2023 27 commits