• Miaohe Lin's avatar
    mm: mmap: Fix general protection fault in unlink_file_vma() · bc4fe4cd
    Miaohe Lin authored
    The syzbot reported the below general protection fault:
    
      general protection fault, probably for non-canonical address
      0xe00eeaee0000003b: 0000 [#1] PREEMPT SMP KASAN
      KASAN: maybe wild-memory-access in range [0x00777770000001d8-0x00777770000001df]
      CPU: 1 PID: 10488 Comm: syz-executor721 Not tainted 5.9.0-rc3-syzkaller #0
      RIP: 0010:unlink_file_vma+0x57/0xb0 mm/mmap.c:164
      Call Trace:
         free_pgtables+0x1b3/0x2f0 mm/memory.c:415
         exit_mmap+0x2c0/0x530 mm/mmap.c:3184
         __mmput+0x122/0x470 kernel/fork.c:1076
         mmput+0x53/0x60 kernel/fork.c:1097
         exit_mm kernel/exit.c:483 [inline]
         do_exit+0xa8b/0x29f0 kernel/exit.c:793
         do_group_exit+0x125/0x310 kernel/exit.c:903
         get_signal+0x428/0x1f00 kernel/signal.c:2757
         arch_do_signal+0x82/0x2520 arch/x86/kernel/signal.c:811
         exit_to_user_mode_loop kernel/entry/common.c:136 [inline]
         exit_to_user_mode_prepare+0x1ae/0x200 kernel/entry/common.c:167
         syscall_exit_to_user_mode+0x7e/0x2e0 kernel/entry/common.c:242
         entry_SYSCALL_64_after_hwframe+0x44/0xa9
    
    It's because the ->mmap() callback can change vma->vm_file and fput the
    original file.  But the commit d70cec89 ("mm: mmap: merge vma after
    call_mmap() if possible") failed to catch this case and always fput()
    the original file, hence add an extra fput().
    
    [ Thanks Hillf for pointing this extra fput() out. ]
    
    Fixes: d70cec89 ("mm: mmap: merge vma after call_mmap() if possible")
    Reported-by: syzbot+c5d5a51dcbb558ca0cb5@syzkaller.appspotmail.com
    Signed-off-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Cc: Christian König <ckoenig.leichtzumerken@gmail.com>
    Cc: Hongxiang Lou <louhongxiang@huawei.com>
    Cc: Chris Wilson <chris@chris-wilson.co.uk>
    Cc: Dave Airlie <airlied@redhat.com>
    Cc: Daniel Vetter <daniel@ffwll.ch>
    Cc: Sumit Semwal <sumit.semwal@linaro.org>
    Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
    Cc: John Hubbard <jhubbard@nvidia.com>
    Link: https://lkml.kernel.org/r/20200916090733.31427-1-linmiaohe@huawei.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    bc4fe4cd
mmap.c 102 KB