syzbot


possible deadlock in pipe_resize_ring

Status: moderation: reported on 2024/03/31 17:20
Subsystems: fs
[Documentation on labels]
Reported-by: syzbot+263b0bae62e1f80ce27d@syzkaller.appspotmail.com
First crash: 17d, last: 17d

Sample crash report:
========================================================
WARNING: possible irq lock inversion dependency detected
6.9.0-rc1-syzkaller-00009-g7033999ecd7b #0 Not tainted
--------------------------------------------------------
syz-executor.0/15964 just changed the state of lock:
ffff8880271e48a8 (&pipe->rd_wait){+.+.}-{2:2}, at: spin_lock_irq include/linux/spinlock.h:376 [inline]
ffff8880271e48a8 (&pipe->rd_wait){+.+.}-{2:2}, at: pipe_resize_ring+0x5d/0x4b0 fs/pipe.c:1275
but this lock was taken by another, SOFTIRQ-safe lock in the past:
 (&ctx->ctx_lock){..-.}-{2:2}


and interrupts could create inverse lock ordering between them.


other info that might help us debug this:
 Possible interrupt unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&pipe->rd_wait);
                               local_irq_disable();
                               lock(&ctx->ctx_lock);
                               lock(&pipe->rd_wait);
  <Interrupt>
    lock(&ctx->ctx_lock);

 *** DEADLOCK ***

3 locks held by syz-executor.0/15964:
 #0: ffff8880271e4868 (&pipe->mutex){+.+.}-{3:3}, at: pipe_fcntl+0x98/0x510 fs/pipe.c:1405
 #1: ffff8880271e48a8 (&pipe->rd_wait){+.+.}-{2:2}, at: spin_lock_irq include/linux/spinlock.h:376 [inline]
 #1: ffff8880271e48a8 (&pipe->rd_wait){+.+.}-{2:2}, at: pipe_resize_ring+0x5d/0x4b0 fs/pipe.c:1275
 #2: ffffffff8d7b4b60 (rcu_read_lock){....}-{1:2}, at: rcu_lock_acquire include/linux/rcupdate.h:329 [inline]
 #2: ffffffff8d7b4b60 (rcu_read_lock){....}-{1:2}, at: rcu_read_lock include/linux/rcupdate.h:781 [inline]
 #2: ffffffff8d7b4b60 (rcu_read_lock){....}-{1:2}, at: __bpf_trace_run kernel/trace/bpf_trace.c:2380 [inline]
 #2: ffffffff8d7b4b60 (rcu_read_lock){....}-{1:2}, at: bpf_trace_run2+0xe4/0x420 kernel/trace/bpf_trace.c:2420

the shortest dependencies between 2nd lock and 1st lock:
 -> (&ctx->ctx_lock){..-.}-{2:2} {
    IN-SOFTIRQ-W at:
                      lock_acquire kernel/locking/lockdep.c:5754 [inline]
                      lock_acquire+0x1b1/0x560 kernel/locking/lockdep.c:5719
                      __raw_spin_lock_irq include/linux/spinlock_api_smp.h:119 [inline]
                      _raw_spin_lock_irq+0x36/0x50 kernel/locking/spinlock.c:170
                      spin_lock_irq include/linux/spinlock.h:376 [inline]
                      free_ioctx_users+0x37/0x240 fs/aio.c:658
                      percpu_ref_put_many.constprop.0+0x269/0x2a0 include/linux/percpu-refcount.h:335
                      rcu_do_batch kernel/rcu/tree.c:2196 [inline]
                      rcu_core+0x828/0x16b0 kernel/rcu/tree.c:2471
                      __do_softirq+0x218/0x922 kernel/softirq.c:554
                      invoke_softirq kernel/softirq.c:428 [inline]
                      __irq_exit_rcu kernel/softirq.c:633 [inline]
                      irq_exit_rcu+0xb9/0x120 kernel/softirq.c:645
                      instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1043 [inline]
                      sysvec_apic_timer_interrupt+0x95/0xb0 arch/x86/kernel/apic/apic.c:1043
                      asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:702
                      get_current arch/x86/include/asm/current.h:49 [inline]
                      __sanitizer_cov_trace_pc+0xc/0x60 kernel/kcov.c:206
                      _compound_head include/linux/page-flags.h:247 [inline]
                      PageSlab include/linux/page-flags.h:507 [inline]
                      page_table_check_clear.part.0+0xc6/0x7f0 mm/page_table_check.c:74
                      page_table_check_clear mm/page_table_check.c:68 [inline]
                      __page_table_check_pte_clear+0x31c/0x570 mm/page_table_check.c:158
                      page_table_check_pte_clear include/linux/page_table_check.h:49 [inline]
                      ptep_get_and_clear_full arch/x86/include/asm/pgtable.h:1295 [inline]
                      get_and_clear_full_ptes include/linux/pgtable.h:634 [inline]
                      zap_present_folio_ptes mm/memory.c:1479 [inline]
                      zap_present_ptes mm/memory.c:1561 [inline]
                      zap_pte_range mm/memory.c:1603 [inline]
                      zap_pmd_range mm/memory.c:1720 [inline]
                      zap_pud_range mm/memory.c:1749 [inline]
                      zap_p4d_range mm/memory.c:1770 [inline]
                      unmap_page_range+0x1efc/0x3be0 mm/memory.c:1791
                      unmap_single_vma+0x194/0x2b0 mm/memory.c:1837
                      unmap_vmas+0x22f/0x490 mm/memory.c:1881
                      exit_mmap+0x1c1/0xb90 mm/mmap.c:3267
                      __mmput+0x12a/0x4d0 kernel/fork.c:1345
                      mmput+0x62/0x70 kernel/fork.c:1367
                      exit_mm kernel/exit.c:569 [inline]
                      do_exit+0x999/0x2c10 kernel/exit.c:865
                      do_group_exit+0xd3/0x2a0 kernel/exit.c:1027
                      __do_sys_exit_group kernel/exit.c:1038 [inline]
                      __se_sys_exit_group kernel/exit.c:1036 [inline]
                      __ia32_sys_exit_group+0x3e/0x50 kernel/exit.c:1036
                      do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline]
                      __do_fast_syscall_32+0x7a/0x120 arch/x86/entry/common.c:321
                      do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:346
                      entry_SYSENTER_compat_after_hwframe+0x7a/0x84
    INITIAL USE at:
                     lock_acquire kernel/locking/lockdep.c:5754 [inline]
                     lock_acquire+0x1b1/0x560 kernel/locking/lockdep.c:5719
                     __raw_spin_lock_irq include/linux/spinlock_api_smp.h:119 [inline]
                     _raw_spin_lock_irq+0x36/0x50 kernel/locking/spinlock.c:170
                     spin_lock_irq include/linux/spinlock.h:376 [inline]
                     aio_poll fs/aio.c:1933 [inline]
                     __io_submit_one fs/aio.c:2021 [inline]
                     io_submit_one+0xc6b/0x1df0 fs/aio.c:2058
                     __do_compat_sys_io_submit fs/aio.c:2159 [inline]
                     __se_compat_sys_io_submit fs/aio.c:2129 [inline]
                     __ia32_compat_sys_io_submit+0x1af/0x390 fs/aio.c:2129
                     do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline]
                     __do_fast_syscall_32+0x7a/0x120 arch/x86/entry/common.c:321
                     do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:346
                     entry_SYSENTER_compat_after_hwframe+0x7a/0x84
  }
  ... key      at: [<ffffffff946a0300>] __key.19+0x0/0x40
  ... acquired at:
   __raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline]
   _raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154
   spin_lock include/linux/spinlock.h:351 [inline]
   poll_iocb_lock_wq+0x8b/0x240 fs/aio.c:1714
   aio_poll fs/aio.c:1935 [inline]
   __io_submit_one fs/aio.c:2021 [inline]
   io_submit_one+0xc9d/0x1df0 fs/aio.c:2058
   __do_compat_sys_io_submit fs/aio.c:2159 [inline]
   __se_compat_sys_io_submit fs/aio.c:2129 [inline]
   __ia32_compat_sys_io_submit+0x1af/0x390 fs/aio.c:2129
   do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline]
   __do_fast_syscall_32+0x7a/0x120 arch/x86/entry/common.c:321
   do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:346
   entry_SYSENTER_compat_after_hwframe+0x7a/0x84

-> (&pipe->rd_wait){+.+.}-{2:2} {
   HARDIRQ-ON-W at:
                    __trace_hardirqs_on_caller kernel/locking/lockdep.c:4292 [inline]
                    lockdep_hardirqs_on_prepare+0x137/0x420 kernel/locking/lockdep.c:4359
                    trace_hardirqs_on+0x36/0x40 kernel/trace/trace_preemptirq.c:61
                    __local_bh_enable_ip+0xa4/0x120 kernel/softirq.c:387
                    spin_unlock_bh include/linux/spinlock.h:396 [inline]
                    sock_hash_delete_elem+0x2b8/0x360 net/core/sock_map.c:947
                    bpf_prog_57115342e4867123+0x47/0x4b
                    bpf_dispatcher_nop_func include/linux/bpf.h:1234 [inline]
                    __bpf_prog_run include/linux/filter.h:657 [inline]
                    bpf_prog_run include/linux/filter.h:664 [inline]
                    __bpf_trace_run kernel/trace/bpf_trace.c:2381 [inline]
                    bpf_trace_run2+0x151/0x420 kernel/trace/bpf_trace.c:2420
                    trace_kfree include/trace/events/kmem.h:94 [inline]
                    kfree+0x225/0x390 mm/slub.c:4377
                    pipe_resize_ring+0x1ed/0x4b0 fs/pipe.c:1310
                    pipe_set_size fs/pipe.c:1370 [inline]
                    pipe_fcntl+0x327/0x510 fs/pipe.c:1409
                    do_fcntl+0x22f/0x1330 fs/fcntl.c:426
                    do_compat_fcntl64+0x35d/0x6a0 fs/fcntl.c:676
                    do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline]
                    __do_fast_syscall_32+0x7a/0x120 arch/x86/entry/common.c:321
                    do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:346
                    entry_SYSENTER_compat_after_hwframe+0x7a/0x84
   SOFTIRQ-ON-W at:
                    __trace_hardirqs_on_caller kernel/locking/lockdep.c:4300 [inline]
                    lockdep_hardirqs_on_prepare+0x27a/0x420 kernel/locking/lockdep.c:4359
                    trace_hardirqs_on+0x36/0x40 kernel/trace/trace_preemptirq.c:61
                    __local_bh_enable_ip+0xa4/0x120 kernel/softirq.c:387
                    spin_unlock_bh include/linux/spinlock.h:396 [inline]
                    sock_hash_delete_elem+0x2b8/0x360 net/core/sock_map.c:947
                    bpf_prog_57115342e4867123+0x47/0x4b
                    bpf_dispatcher_nop_func include/linux/bpf.h:1234 [inline]
                    __bpf_prog_run include/linux/filter.h:657 [inline]
                    bpf_prog_run include/linux/filter.h:664 [inline]
                    __bpf_trace_run kernel/trace/bpf_trace.c:2381 [inline]
                    bpf_trace_run2+0x151/0x420 kernel/trace/bpf_trace.c:2420
                    trace_kfree include/trace/events/kmem.h:94 [inline]
                    kfree+0x225/0x390 mm/slub.c:4377
                    pipe_resize_ring+0x1ed/0x4b0 fs/pipe.c:1310
                    pipe_set_size fs/pipe.c:1370 [inline]
                    pipe_fcntl+0x327/0x510 fs/pipe.c:1409
                    do_fcntl+0x22f/0x1330 fs/fcntl.c:426
                    do_compat_fcntl64+0x35d/0x6a0 fs/fcntl.c:676
                    do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline]
                    __do_fast_syscall_32+0x7a/0x120 arch/x86/entry/common.c:321
                    do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:346
                    entry_SYSENTER_compat_after_hwframe+0x7a/0x84
   INITIAL USE at:
                   lock_acquire kernel/locking/lockdep.c:5754 [inline]
                   lock_acquire+0x1b1/0x560 kernel/locking/lockdep.c:5719
                   __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline]
                   _raw_spin_lock_irqsave+0x3a/0x60 kernel/locking/spinlock.c:162
                   prepare_to_wait_event+0x1f/0x690 kernel/sched/wait.c:275
                   pipe_read+0xa3f/0x1400 fs/pipe.c:390
                   call_read_iter include/linux/fs.h:2102 [inline]
                   new_sync_read fs/read_write.c:395 [inline]
                   vfs_read+0x9fd/0xb80 fs/read_write.c:476
                   ksys_read+0x1f8/0x260 fs/read_write.c:619
                   do_syscall_x64 arch/x86/entry/common.c:52 [inline]
                   do_syscall_64+0xd2/0x260 arch/x86/entry/common.c:83
                   entry_SYSCALL_64_after_hwframe+0x6d/0x75
 }
 ... key      at: [<ffffffff9469cb60>] __key.2+0x0/0x40
 ... acquired at:
   mark_held_locks+0x9f/0xe0 kernel/locking/lockdep.c:4274
   __trace_hardirqs_on_caller kernel/locking/lockdep.c:4300 [inline]
   lockdep_hardirqs_on_prepare+0x27a/0x420 kernel/locking/lockdep.c:4359
   trace_hardirqs_on+0x36/0x40 kernel/trace/trace_preemptirq.c:61
   __local_bh_enable_ip+0xa4/0x120 kernel/softirq.c:387
   spin_unlock_bh include/linux/spinlock.h:396 [inline]
   sock_hash_delete_elem+0x2b8/0x360 net/core/sock_map.c:947
   bpf_prog_57115342e4867123+0x47/0x4b
   bpf_dispatcher_nop_func include/linux/bpf.h:1234 [inline]
   __bpf_prog_run include/linux/filter.h:657 [inline]
   bpf_prog_run include/linux/filter.h:664 [inline]
   __bpf_trace_run kernel/trace/bpf_trace.c:2381 [inline]
   bpf_trace_run2+0x151/0x420 kernel/trace/bpf_trace.c:2420
   trace_kfree include/trace/events/kmem.h:94 [inline]
   kfree+0x225/0x390 mm/slub.c:4377
   pipe_resize_ring+0x1ed/0x4b0 fs/pipe.c:1310
   pipe_set_size fs/pipe.c:1370 [inline]
   pipe_fcntl+0x327/0x510 fs/pipe.c:1409
   do_fcntl+0x22f/0x1330 fs/fcntl.c:426
   do_compat_fcntl64+0x35d/0x6a0 fs/fcntl.c:676
   do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline]
   __do_fast_syscall_32+0x7a/0x120 arch/x86/entry/common.c:321
   do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:346
   entry_SYSENTER_compat_after_hwframe+0x7a/0x84


stack backtrace:
CPU: 1 PID: 15964 Comm: syz-executor.0 Not tainted 6.9.0-rc1-syzkaller-00009-g7033999ecd7b #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x116/0x1f0 lib/dump_stack.c:114
 print_irq_inversion_bug.part.0+0x3e9/0x5a0 kernel/locking/lockdep.c:4080
 print_irq_inversion_bug kernel/locking/lockdep.c:4033 [inline]
 check_usage_forwards kernel/locking/lockdep.c:4111 [inline]
 mark_lock_irq kernel/locking/lockdep.c:4243 [inline]
 mark_lock+0x574/0xc60 kernel/locking/lockdep.c:4678
 mark_held_locks+0x9f/0xe0 kernel/locking/lockdep.c:4274
 __trace_hardirqs_on_caller kernel/locking/lockdep.c:4300 [inline]
 lockdep_hardirqs_on_prepare+0x27a/0x420 kernel/locking/lockdep.c:4359
 trace_hardirqs_on+0x36/0x40 kernel/trace/trace_preemptirq.c:61
 __local_bh_enable_ip+0xa4/0x120 kernel/softirq.c:387
 spin_unlock_bh include/linux/spinlock.h:396 [inline]
 sock_hash_delete_elem+0x2b8/0x360 net/core/sock_map.c:947
 bpf_prog_57115342e4867123+0x47/0x4b
 bpf_dispatcher_nop_func include/linux/bpf.h:1234 [inline]
 __bpf_prog_run include/linux/filter.h:657 [inline]
 bpf_prog_run include/linux/filter.h:664 [inline]
 __bpf_trace_run kernel/trace/bpf_trace.c:2381 [inline]
 bpf_trace_run2+0x151/0x420 kernel/trace/bpf_trace.c:2420
 trace_kfree include/trace/events/kmem.h:94 [inline]
 kfree+0x225/0x390 mm/slub.c:4377
 pipe_resize_ring+0x1ed/0x4b0 fs/pipe.c:1310
 pipe_set_size fs/pipe.c:1370 [inline]
 pipe_fcntl+0x327/0x510 fs/pipe.c:1409
 do_fcntl+0x22f/0x1330 fs/fcntl.c:426
 do_compat_fcntl64+0x35d/0x6a0 fs/fcntl.c:676
 do_syscall_32_irqs_on arch/x86/entry/common.c:165 [inline]
 __do_fast_syscall_32+0x7a/0x120 arch/x86/entry/common.c:321
 do_fast_syscall_32+0x32/0x80 arch/x86/entry/common.c:346
 entry_SYSENTER_compat_after_hwframe+0x7a/0x84
RIP: 0023:0xf72e3579
Code: b8 01 10 06 03 74 b4 01 10 07 03 74 b0 01 10 08 03 74 d8 01 00 00 00 00 00 00 00 00 00 00 00 00 00 51 52 55 89 e5 0f 34 cd 80 <5d> 5a 59 c3 90 90 90 90 8d b4 26 00 00 00 00 8d b4 26 00 00 00 00
RSP: 002b:00000000f5edd5ac EFLAGS: 00000292 ORIG_RAX: 0000000000000037
RAX: ffffffffffffffda RBX: 0000000000000008 RCX: 0000000000000407
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000000
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
 </TASK>
----------------
Code disassembly (best guess), 2 bytes skipped:
   0:	10 06                	adc    %al,(%rsi)
   2:	03 74 b4 01          	add    0x1(%rsp,%rsi,4),%esi
   6:	10 07                	adc    %al,(%rdi)
   8:	03 74 b0 01          	add    0x1(%rax,%rsi,4),%esi
   c:	10 08                	adc    %cl,(%rax)
   e:	03 74 d8 01          	add    0x1(%rax,%rbx,8),%esi
  1e:	00 51 52             	add    %dl,0x52(%rcx)
  21:	55                   	push   %rbp
  22:	89 e5                	mov    %esp,%ebp
  24:	0f 34                	sysenter
  26:	cd 80                	int    $0x80
* 28:	5d                   	pop    %rbp <-- trapping instruction
  29:	5a                   	pop    %rdx
  2a:	59                   	pop    %rcx
  2b:	c3                   	ret
  2c:	90                   	nop
  2d:	90                   	nop
  2e:	90                   	nop
  2f:	90                   	nop
  30:	8d b4 26 00 00 00 00 	lea    0x0(%rsi,%riz,1),%esi
  37:	8d b4 26 00 00 00 00 	lea    0x0(%rsi,%riz,1),%esi

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/03/27 17:16 upstream 7033999ecd7b 454571b6 .config console log report info [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream-386 possible deadlock in pipe_resize_ring
* Struck through repros no longer work on HEAD.