syzbot


possible deadlock in userfaultfd_release

Status: fixed on 2019/12/01 09:13
Reported-by: syzbot+0b8608e3d25d48fc4f4c@syzkaller.appspotmail.com
Fix commit: 052b31810085 fs/userfaultfd.c: disable irqs for fault_pending and event locks
First crash: 1984d, last: 1979d
Fix bisection: fixed by (bisect log) :
commit 052b318100856aa86f4e0c03cfe43a1bb6bfb487
Author: Eric Biggers <ebiggers@google.com>
Date: Thu Jul 4 22:14:39 2019 +0000

  fs/userfaultfd.c: disable irqs for fault_pending and event locks

  
Similar bugs (1)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream possible deadlock in userfaultfd_release C done 137 1973d 2217d 12/28 fixed on 2019/07/29 13:39

Sample crash report:
kauditd_printk_skb: 5 callbacks suppressed
audit: type=1400 audit(1561146492.680:36): avc:  denied  { map } for  pid=7815 comm="syz-executor672" path="/root/syz-executor672817080" dev="sda1" ino=16483 scontext=unconfined_u:system_r:insmod_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=1
========================================================
WARNING: possible irq lock inversion dependency detected
4.19.53+ #25 Not tainted
--------------------------------------------------------
syz-executor672/7816 just changed the state of lock:
0000000087978b0b (&ctx->fault_pending_wqh){+.+.}, at: spin_lock include/linux/spinlock.h:329 [inline]
0000000087978b0b (&ctx->fault_pending_wqh){+.+.}, at: userfaultfd_release+0x4d6/0x720 fs/userfaultfd.c:922
but this lock was taken by another, SOFTIRQ-safe lock in the past:
 (&(&ctx->ctx_lock)->rlock){..-.}


and interrupts could create inverse lock ordering between them.


other info that might help us debug this:
Chain exists of:
  &(&ctx->ctx_lock)->rlock --> &ctx->fd_wqh --> &ctx->fault_pending_wqh

 Possible interrupt unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&ctx->fault_pending_wqh);
                               local_irq_disable();
                               lock(&(&ctx->ctx_lock)->rlock);
                               lock(&ctx->fd_wqh);
  <Interrupt>
    lock(&(&ctx->ctx_lock)->rlock);

 *** DEADLOCK ***

no locks held by syz-executor672/7816.

the shortest dependencies between 2nd lock and 1st lock:
  -> (&(&ctx->ctx_lock)->rlock){..-.} ops: 2 {
     IN-SOFTIRQ-W at:
                        lock_acquire+0x16f/0x3f0 kernel/locking/lockdep.c:3900
                        __raw_spin_lock_irq include/linux/spinlock_api_smp.h:128 [inline]
                        _raw_spin_lock_irq+0x60/0x80 kernel/locking/spinlock.c:160
                        spin_lock_irq include/linux/spinlock.h:354 [inline]
                        free_ioctx_users+0x2d/0x490 fs/aio.c:614
                        percpu_ref_put_many include/linux/percpu-refcount.h:284 [inline]
                        percpu_ref_put include/linux/percpu-refcount.h:300 [inline]
                        percpu_ref_call_confirm_rcu lib/percpu-refcount.c:123 [inline]
                        percpu_ref_switch_to_atomic_rcu+0x407/0x540 lib/percpu-refcount.c:158
                        __rcu_reclaim kernel/rcu/rcu.h:236 [inline]
                        rcu_do_batch kernel/rcu/tree.c:2584 [inline]
                        invoke_rcu_callbacks kernel/rcu/tree.c:2897 [inline]
                        __rcu_process_callbacks kernel/rcu/tree.c:2864 [inline]
                        rcu_process_callbacks+0xba0/0x1a30 kernel/rcu/tree.c:2881
                        __do_softirq+0x25c/0x921 kernel/softirq.c:292
                        invoke_softirq kernel/softirq.c:372 [inline]
                        irq_exit+0x180/0x1d0 kernel/softirq.c:412
                        exiting_irq arch/x86/include/asm/apic.h:536 [inline]
                        smp_apic_timer_interrupt+0x13b/0x550 arch/x86/kernel/apic/apic.c:1056
                        apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:869
                        native_safe_halt+0xe/0x10 arch/x86/include/asm/irqflags.h:60
                        arch_cpu_idle+0xa/0x10 arch/x86/kernel/process.c:556
                        default_idle_call+0x36/0x90 kernel/sched/idle.c:93
                        cpuidle_idle_call kernel/sched/idle.c:153 [inline]
                        do_idle+0x377/0x560 kernel/sched/idle.c:262
                        cpu_startup_entry+0xc8/0xe0 kernel/sched/idle.c:368
                        start_secondary+0x3e8/0x5b0 arch/x86/kernel/smpboot.c:271
                        secondary_startup_64+0xa4/0xb0 arch/x86/kernel/head_64.S:243
     INITIAL USE at:
                       lock_acquire+0x16f/0x3f0 kernel/locking/lockdep.c:3900
                       __raw_spin_lock_irq include/linux/spinlock_api_smp.h:128 [inline]
                       _raw_spin_lock_irq+0x60/0x80 kernel/locking/spinlock.c:160
                       spin_lock_irq include/linux/spinlock.h:354 [inline]
                       aio_poll fs/aio.c:1739 [inline]
                       __io_submit_one fs/aio.c:1849 [inline]
                       io_submit_one+0xead/0x2eb0 fs/aio.c:1885
                       __do_sys_io_submit fs/aio.c:1929 [inline]
                       __se_sys_io_submit fs/aio.c:1900 [inline]
                       __x64_sys_io_submit+0x1aa/0x520 fs/aio.c:1900
                       do_syscall_64+0xfd/0x620 arch/x86/entry/common.c:293
                       entry_SYSCALL_64_after_hwframe+0x49/0xbe
   }
   ... key      at: [<ffffffff8a3813a0>] __key.50193+0x0/0x40
   ... acquired at:
   __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
   _raw_spin_lock+0x2f/0x40 kernel/locking/spinlock.c:144
   spin_lock include/linux/spinlock.h:329 [inline]
   aio_poll fs/aio.c:1741 [inline]
   __io_submit_one fs/aio.c:1849 [inline]
   io_submit_one+0xef2/0x2eb0 fs/aio.c:1885
   __do_sys_io_submit fs/aio.c:1929 [inline]
   __se_sys_io_submit fs/aio.c:1900 [inline]
   __x64_sys_io_submit+0x1aa/0x520 fs/aio.c:1900
   do_syscall_64+0xfd/0x620 arch/x86/entry/common.c:293
   entry_SYSCALL_64_after_hwframe+0x49/0xbe

 -> (&ctx->fd_wqh){....} ops: 4 {
    INITIAL USE at:
                     lock_acquire+0x16f/0x3f0 kernel/locking/lockdep.c:3900
                     __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
                     _raw_spin_lock_irqsave+0x95/0xcd kernel/locking/spinlock.c:152
                     add_wait_queue+0x4c/0x170 kernel/sched/wait.c:22
                     aio_poll_queue_proc+0x9e/0x110 fs/aio.c:1704
                     poll_wait include/linux/poll.h:47 [inline]
                     userfaultfd_poll+0x91/0x210 fs/userfaultfd.c:971
                     vfs_poll include/linux/poll.h:86 [inline]
                     aio_poll fs/aio.c:1738 [inline]
                     __io_submit_one fs/aio.c:1849 [inline]
                     io_submit_one+0xe4b/0x2eb0 fs/aio.c:1885
                     __do_sys_io_submit fs/aio.c:1929 [inline]
                     __se_sys_io_submit fs/aio.c:1900 [inline]
                     __x64_sys_io_submit+0x1aa/0x520 fs/aio.c:1900
                     do_syscall_64+0xfd/0x620 arch/x86/entry/common.c:293
                     entry_SYSCALL_64_after_hwframe+0x49/0xbe
  }
  ... key      at: [<ffffffff8a381120>] __key.43730+0x0/0x40
  ... acquired at:
   __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
   _raw_spin_lock+0x2f/0x40 kernel/locking/spinlock.c:144
   spin_lock include/linux/spinlock.h:329 [inline]
   userfaultfd_ctx_read fs/userfaultfd.c:1046 [inline]
   userfaultfd_read+0x394/0x18c0 fs/userfaultfd.c:1204
   __vfs_read+0x114/0x800 fs/read_write.c:416
   vfs_read+0x194/0x3d0 fs/read_write.c:452
   ksys_read+0x14f/0x2d0 fs/read_write.c:579
   __do_sys_read fs/read_write.c:589 [inline]
   __se_sys_read fs/read_write.c:587 [inline]
   __x64_sys_read+0x73/0xb0 fs/read_write.c:587
   do_syscall_64+0xfd/0x620 arch/x86/entry/common.c:293
   entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> (&ctx->fault_pending_wqh){+.+.} ops: 3 {
   HARDIRQ-ON-W at:
                    lock_acquire+0x16f/0x3f0 kernel/locking/lockdep.c:3900
                    __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
                    _raw_spin_lock+0x2f/0x40 kernel/locking/spinlock.c:144
                    spin_lock include/linux/spinlock.h:329 [inline]
                    userfaultfd_release+0x4d6/0x720 fs/userfaultfd.c:922
                    __fput+0x2dd/0x8b0 fs/file_table.c:278
                    ____fput+0x16/0x20 fs/file_table.c:309
                    task_work_run+0x145/0x1c0 kernel/task_work.c:113
                    exit_task_work include/linux/task_work.h:22 [inline]
                    do_exit+0x933/0x2fa0 kernel/exit.c:876
                    do_group_exit+0x135/0x370 kernel/exit.c:979
                    get_signal+0x3ec/0x1fc0 kernel/signal.c:2574
                    do_signal+0x95/0x1960 arch/x86/kernel/signal.c:821
                    exit_to_usermode_loop+0x244/0x2c0 arch/x86/entry/common.c:163
                    prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
                    syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
                    do_syscall_64+0x53d/0x620 arch/x86/entry/common.c:296
                    entry_SYSCALL_64_after_hwframe+0x49/0xbe
   SOFTIRQ-ON-W at:
                    lock_acquire+0x16f/0x3f0 kernel/locking/lockdep.c:3900
                    __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
                    _raw_spin_lock+0x2f/0x40 kernel/locking/spinlock.c:144
                    spin_lock include/linux/spinlock.h:329 [inline]
                    userfaultfd_release+0x4d6/0x720 fs/userfaultfd.c:922
                    __fput+0x2dd/0x8b0 fs/file_table.c:278
                    ____fput+0x16/0x20 fs/file_table.c:309
                    task_work_run+0x145/0x1c0 kernel/task_work.c:113
                    exit_task_work include/linux/task_work.h:22 [inline]
                    do_exit+0x933/0x2fa0 kernel/exit.c:876
                    do_group_exit+0x135/0x370 kernel/exit.c:979
                    get_signal+0x3ec/0x1fc0 kernel/signal.c:2574
                    do_signal+0x95/0x1960 arch/x86/kernel/signal.c:821
                    exit_to_usermode_loop+0x244/0x2c0 arch/x86/entry/common.c:163
                    prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
                    syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
                    do_syscall_64+0x53d/0x620 arch/x86/entry/common.c:296
                    entry_SYSCALL_64_after_hwframe+0x49/0xbe
   INITIAL USE at:
                   lock_acquire+0x16f/0x3f0 kernel/locking/lockdep.c:3900
                   __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
                   _raw_spin_lock+0x2f/0x40 kernel/locking/spinlock.c:144
                   spin_lock include/linux/spinlock.h:329 [inline]
                   userfaultfd_ctx_read fs/userfaultfd.c:1046 [inline]
                   userfaultfd_read+0x394/0x18c0 fs/userfaultfd.c:1204
                   __vfs_read+0x114/0x800 fs/read_write.c:416
                   vfs_read+0x194/0x3d0 fs/read_write.c:452
                   ksys_read+0x14f/0x2d0 fs/read_write.c:579
                   __do_sys_read fs/read_write.c:589 [inline]
                   __se_sys_read fs/read_write.c:587 [inline]
                   __x64_sys_read+0x73/0xb0 fs/read_write.c:587
                   do_syscall_64+0xfd/0x620 arch/x86/entry/common.c:293
                   entry_SYSCALL_64_after_hwframe+0x49/0xbe
 }
 ... key      at: [<ffffffff8a3811e0>] __key.43727+0x0/0x40
 ... acquired at:
   mark_lock_irq kernel/locking/lockdep.c:2755 [inline]
   mark_lock+0x420/0x1370 kernel/locking/lockdep.c:3127
   mark_irqflags kernel/locking/lockdep.c:3023 [inline]
   __lock_acquire+0x6b5/0x48f0 kernel/locking/lockdep.c:3368
   lock_acquire+0x16f/0x3f0 kernel/locking/lockdep.c:3900
   __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
   _raw_spin_lock+0x2f/0x40 kernel/locking/spinlock.c:144
   spin_lock include/linux/spinlock.h:329 [inline]
   userfaultfd_release+0x4d6/0x720 fs/userfaultfd.c:922
   __fput+0x2dd/0x8b0 fs/file_table.c:278
   ____fput+0x16/0x20 fs/file_table.c:309
   task_work_run+0x145/0x1c0 kernel/task_work.c:113
   exit_task_work include/linux/task_work.h:22 [inline]
   do_exit+0x933/0x2fa0 kernel/exit.c:876
   do_group_exit+0x135/0x370 kernel/exit.c:979
   get_signal+0x3ec/0x1fc0 kernel/signal.c:2574
   do_signal+0x95/0x1960 arch/x86/kernel/signal.c:821
   exit_to_usermode_loop+0x244/0x2c0 arch/x86/entry/common.c:163
   prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
   syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
   do_syscall_64+0x53d/0x620 arch/x86/entry/common.c:296
   entry_SYSCALL_64_after_hwframe+0x49/0xbe


stack backtrace:
CPU: 0 PID: 7816 Comm: syz-executor672 Not tainted 4.19.53+ #25
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x172/0x1f0 lib/dump_stack.c:113
 print_irq_inversion_bug.part.0+0x2c0/0x2cd kernel/locking/lockdep.c:2621
 print_irq_inversion_bug kernel/locking/lockdep.c:2624 [inline]
 check_usage_backwards.cold+0x1d/0x26 kernel/locking/lockdep.c:2670
 mark_lock_irq kernel/locking/lockdep.c:2755 [inline]
 mark_lock+0x420/0x1370 kernel/locking/lockdep.c:3127
 mark_irqflags kernel/locking/lockdep.c:3023 [inline]
 __lock_acquire+0x6b5/0x48f0 kernel/locking/lockdep.c:3368
 lock_acquire+0x16f/0x3f0 kernel/locking/lockdep.c:3900
 __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
 _raw_spin_lock+0x2f/0x40 kernel/locking/spinlock.c:144
 spin_lock include/linux/spinlock.h:329 [inline]
 userfaultfd_release+0x4d6/0x720 fs/userfaultfd.c:922
 __fput+0x2dd/0x8b0 fs/file_table.c:278
 ____fput+0x16/0x20 fs/file_table.c:309
 task_work_run+0x145/0x1c0 kernel/task_work.c:113
 exit_task_work include/linux/task_work.h:22 [inline]
 do_exit+0x933/0x2fa0 kernel/exit.c:876
 do_group_exit+0x135/0x370 kernel/exit.c:979
 get_signal+0x3ec/0x1fc0 kernel/signal.c:2574
 do_signal+0x95/0x1960 arch/x86/kernel/signal.c:821
 exit_to_usermode_loop+0x244/0x2c0 arch/x86/entry/common.c:163
 prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
 do_syscall_64+0x53d/0x620 arch/x86/entry/common.c:296
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x441299
Code: e8 fc ab 02 00 48 83 c4 18 c3 0f 1f 80 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 9b 09 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffd9b9f89c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: fffffffffffffe00 RBX: 0000000000000000 RCX: 0000000000441299
RDX: 0000000000000080 RSI: 00000000200000c0 RDI: 0000000000000005
RBP: 00000000006cb018 R08: 00000000004002c8 R09: 00000000004002c8
R10: 00000000004002c8 R11: 0000000000000246 R12: 00000000004020c0
R13: 0000000000402150 R14: 0000000000000000 R15: 0000000000000000

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2019/06/21 19:53 linux-4.19.y 9f31eb60d7a2 34bf9440 .config console log report syz C ci2-linux-4-19
2019/06/21 17:08 linux-4.19.y 9f31eb60d7a2 34bf9440 .config console log report syz C ci2-linux-4-19
2019/06/17 06:07 linux-4.19.y 7aa823a959e1 442206d7 .config console log report syz C ci2-linux-4-19
2019/06/16 20:10 linux-4.19.y 7aa823a959e1 442206d7 .config console log report syz C ci2-linux-4-19
* Struck through repros no longer work on HEAD.