• Joel Fernandes (Google)'s avatar
    mm: shmem.c: Correctly annotate new inodes for lockdep · 946f8052
    Joel Fernandes (Google) authored
    commit b45d71fb upstream.
    
    Directories and inodes don't necessarily need to be in the same lockdep
    class.  For ex, hugetlbfs splits them out too to prevent false positives
    in lockdep.  Annotate correctly after new inode creation.  If its a
    directory inode, it will be put into a different class.
    
    This should fix a lockdep splat reported by syzbot:
    
    > ======================================================
    > WARNING: possible circular locking dependency detected
    > 4.18.0-rc8-next-20180810+ #36 Not tainted
    > ------------------------------------------------------
    > syz-executor900/4483 is trying to acquire lock:
    > 00000000d2bfc8fe (&sb->s_type->i_mutex_key#9){++++}, at: inode_lock
    > include/linux/fs.h:765 [inline]
    > 00000000d2bfc8fe (&sb->s_type->i_mutex_key#9){++++}, at:
    > shmem_fallocate+0x18b/0x12e0 mm/shmem.c:2602
    >
    > but task is already holding lock:
    > 0000000025208078 (ashmem_mutex){+.+.}, at: ashmem_shrink_scan+0xb4/0x630
    > drivers/staging/android/ashmem.c:448
    >
    > which lock already depends on the new lock.
    >
    > -> #2 (ashmem_mutex){+.+.}:
    >        __mutex_lock_common kernel/locking/mutex.c:925 [inline]
    >        __mutex_lock+0x171/0x1700 kernel/locking/mutex.c:1073
    >        mutex_lock_nested+0x16/0x20 kernel/locking/mutex.c:1088
    >        ashmem_mmap+0x55/0x520 drivers/staging/android/ashmem.c:361
    >        call_mmap include/linux/fs.h:1844 [inline]
    >        mmap_region+0xf27/0x1c50 mm/mmap.c:1762
    >        do_mmap+0xa10/0x1220 mm/mmap.c:1535
    >        do_mmap_pgoff include/linux/mm.h:2298 [inline]
    >        vm_mmap_pgoff+0x213/0x2c0 mm/util.c:357
    >        ksys_mmap_pgoff+0x4da/0x660 mm/mmap.c:1585
    >        __do_sys_mmap arch/x86/kernel/sys_x86_64.c:100 [inline]
    >        __se_sys_mmap arch/x86/kernel/sys_x86_64.c:91 [inline]
    >        __x64_sys_mmap+0xe9/0x1b0 arch/x86/kernel/sys_x86_64.c:91
    >        do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
    >        entry_SYSCALL_64_after_hwframe+0x49/0xbe
    >
    > -> #1 (&mm->mmap_sem){++++}:
    >        __might_fault+0x155/0x1e0 mm/memory.c:4568
    >        _copy_to_user+0x30/0x110 lib/usercopy.c:25
    >        copy_to_user include/linux/uaccess.h:155 [inline]
    >        filldir+0x1ea/0x3a0 fs/readdir.c:196
    >        dir_emit_dot include/linux/fs.h:3464 [inline]
    >        dir_emit_dots include/linux/fs.h:3475 [inline]
    >        dcache_readdir+0x13a/0x620 fs/libfs.c:193
    >        iterate_dir+0x48b/0x5d0 fs/readdir.c:51
    >        __do_sys_getdents fs/readdir.c:231 [inline]
    >        __se_sys_getdents fs/readdir.c:212 [inline]
    >        __x64_sys_getdents+0x29f/0x510 fs/readdir.c:212
    >        do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
    >        entry_SYSCALL_64_after_hwframe+0x49/0xbe
    >
    > -> #0 (&sb->s_type->i_mutex_key#9){++++}:
    >        lock_acquire+0x1e4/0x540 kernel/locking/lockdep.c:3924
    >        down_write+0x8f/0x130 kernel/locking/rwsem.c:70
    >        inode_lock include/linux/fs.h:765 [inline]
    >        shmem_fallocate+0x18b/0x12e0 mm/shmem.c:2602
    >        ashmem_shrink_scan+0x236/0x630 drivers/staging/android/ashmem.c:455
    >        ashmem_ioctl+0x3ae/0x13a0 drivers/staging/android/ashmem.c:797
    >        vfs_ioctl fs/ioctl.c:46 [inline]
    >        file_ioctl fs/ioctl.c:501 [inline]
    >        do_vfs_ioctl+0x1de/0x1720 fs/ioctl.c:685
    >        ksys_ioctl+0xa9/0xd0 fs/ioctl.c:702
    >        __do_sys_ioctl fs/ioctl.c:709 [inline]
    >        __se_sys_ioctl fs/ioctl.c:707 [inline]
    >        __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:707
    >        do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
    >        entry_SYSCALL_64_after_hwframe+0x49/0xbe
    >
    > other info that might help us debug this:
    >
    > Chain exists of:
    >   &sb->s_type->i_mutex_key#9 --> &mm->mmap_sem --> ashmem_mutex
    >
    >  Possible unsafe locking scenario:
    >
    >        CPU0                    CPU1
    >        ----                    ----
    >   lock(ashmem_mutex);
    >                                lock(&mm->mmap_sem);
    >                                lock(ashmem_mutex);
    >   lock(&sb->s_type->i_mutex_key#9);
    >
    >  *** DEADLOCK ***
    >
    > 1 lock held by syz-executor900/4483:
    >  #0: 0000000025208078 (ashmem_mutex){+.+.}, at:
    > ashmem_shrink_scan+0xb4/0x630 drivers/staging/android/ashmem.c:448
    
    Link: http://lkml.kernel.org/r/20180821231835.166639-1-joel@joelfernandes.orgSigned-off-by: 's avatarJoel Fernandes (Google) <joel@joelfernandes.org>
    Reported-by: 's avatarsyzbot <syzkaller@googlegroups.com>
    Reviewed-by: 's avatarNeilBrown <neilb@suse.com>
    Suggested-by: 's avatarNeilBrown <neilb@suse.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: 's avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    946f8052
Name
Last commit
Last update
..
kasan Loading commit data...
Kconfig Loading commit data...
Kconfig.debug Loading commit data...
Makefile Loading commit data...
backing-dev.c Loading commit data...
balloon_compaction.c Loading commit data...
bootmem.c Loading commit data...
cleancache.c Loading commit data...
cma.c Loading commit data...
cma.h Loading commit data...
cma_debug.c Loading commit data...
compaction.c Loading commit data...
debug.c Loading commit data...
debug_page_ref.c Loading commit data...
dmapool.c Loading commit data...
early_ioremap.c Loading commit data...
fadvise.c Loading commit data...
failslab.c Loading commit data...
filemap.c Loading commit data...
frame_vector.c Loading commit data...
frontswap.c Loading commit data...
gup.c Loading commit data...
gup_benchmark.c Loading commit data...
highmem.c Loading commit data...
hmm.c Loading commit data...
huge_memory.c Loading commit data...
hugetlb.c Loading commit data...
hugetlb_cgroup.c Loading commit data...
hwpoison-inject.c Loading commit data...
init-mm.c Loading commit data...
internal.h Loading commit data...
interval_tree.c Loading commit data...
khugepaged.c Loading commit data...
kmemleak-test.c Loading commit data...
kmemleak.c Loading commit data...
ksm.c Loading commit data...
list_lru.c Loading commit data...
maccess.c Loading commit data...
madvise.c Loading commit data...
memblock.c Loading commit data...
memcontrol.c Loading commit data...
memfd.c Loading commit data...
memory-failure.c Loading commit data...
memory.c Loading commit data...
memory_hotplug.c Loading commit data...
mempolicy.c Loading commit data...
mempool.c Loading commit data...
memtest.c Loading commit data...
migrate.c Loading commit data...
mincore.c Loading commit data...
mlock.c Loading commit data...
mm_init.c Loading commit data...
mmap.c Loading commit data...
mmu_context.c Loading commit data...
mmu_notifier.c Loading commit data...
mmzone.c Loading commit data...
mprotect.c Loading commit data...
mremap.c Loading commit data...
msync.c Loading commit data...
nobootmem.c Loading commit data...
nommu.c Loading commit data...
oom_kill.c Loading commit data...
page-writeback.c Loading commit data...
page_alloc.c Loading commit data...
page_counter.c Loading commit data...
page_ext.c Loading commit data...
page_idle.c Loading commit data...
page_io.c Loading commit data...
page_isolation.c Loading commit data...
page_owner.c Loading commit data...
page_poison.c Loading commit data...
page_vma_mapped.c Loading commit data...
pagewalk.c Loading commit data...
percpu-internal.h Loading commit data...
percpu-km.c Loading commit data...
percpu-stats.c Loading commit data...
percpu-vm.c Loading commit data...
percpu.c Loading commit data...
pgtable-generic.c Loading commit data...
process_vm_access.c Loading commit data...
quicklist.c Loading commit data...
readahead.c Loading commit data...
rmap.c Loading commit data...
rodata_test.c Loading commit data...
shmem.c Loading commit data...
slab.c Loading commit data...
slab.h Loading commit data...
slab_common.c Loading commit data...
slob.c Loading commit data...
slub.c Loading commit data...
sparse-vmemmap.c Loading commit data...
sparse.c Loading commit data...
swap.c Loading commit data...
swap_cgroup.c Loading commit data...
swap_slots.c Loading commit data...
swap_state.c Loading commit data...
swapfile.c Loading commit data...
truncate.c Loading commit data...
usercopy.c Loading commit data...
userfaultfd.c Loading commit data...
util.c Loading commit data...
vmacache.c Loading commit data...
vmalloc.c Loading commit data...
vmpressure.c Loading commit data...
vmscan.c Loading commit data...
vmstat.c Loading commit data...
workingset.c Loading commit data...
z3fold.c Loading commit data...
zbud.c Loading commit data...
zpool.c Loading commit data...
zsmalloc.c Loading commit data...
zswap.c Loading commit data...