syzbot


possible deadlock in __snd_pcm_lib_xfer

Status: fixed on 2023/02/24 13:50
Subsystems: sound
[Documentation on labels]
Reported-by: syzbot+6e5c88838328e99c7e1c@syzkaller.appspotmail.com
Fix commit: bc55cfd5718c ALSA: pcm: Fix potential AB/BA lock with buffer_mutex and mmap_lock
First crash: 760d, last: 759d
Cause bisection: introduced by (bisect log) [merge commit]:
commit 7f5985b0b3f6cf1e808773927423bbe5999f8953
Author: Stephen Rothwell <sfr@canb.auug.org.au>
Date: Sun Mar 27 23:17:45 2022 +0000

  Merge branch 'for-next' of git://git.kernel.dk/linux-block.git

Crash: possible deadlock in __snd_pcm_lib_xfer (log)
Repro: C syz .config
  
Discussions (8)
Title Replies (including bot) Last reply
[PATCH 4.14 00/14] 4.14.279-rc1 review 17 (17) 2022/05/14 16:07
[PATCH 4.19 00/15] 4.19.243-rc1 review 22 (22) 2022/05/14 15:06
[PATCH 5.4 00/52] 5.4.193-rc1 review 59 (59) 2022/05/11 09:59
[PATCH 5.10 000/599] 5.10.110-rc1 review 628 (629) 2022/05/08 12:31
[PATCH 5.16 0000/1017] 5.16.19-rc1 review 1034 (1035) 2022/04/07 08:34
[PATCH 5.15 000/913] 5.15.33-rc1 review 932 (933) 2022/04/06 15:36
[PATCH 5.17 0000/1126] 5.17.2-rc1 review 1143 (1144) 2022/04/06 14:06
[syzbot] possible deadlock in __snd_pcm_lib_xfer 1 (2) 2022/03/30 08:36
Last patch testing requests (1)
Created Duration User Patch Repo Result
2022/03/30 03:54 9m hdanton@sina.com patch https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/ 8515d05bf6bc OK

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
5.17.0-next-20220328-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor329/3588 is trying to acquire lock:
ffff8880243c1d28 (&mm->mmap_lock#2){++++}-{3:3}, at: __might_fault+0xa1/0x170 mm/memory.c:5300

but task is already holding lock:
ffff88801afef230 (&runtime->buffer_mutex){+.+.}-{3:3}, at: wait_for_avail sound/core/pcm_lib.c:1913 [inline]
ffff88801afef230 (&runtime->buffer_mutex){+.+.}-{3:3}, at: __snd_pcm_lib_xfer+0xbca/0x1e20 sound/core/pcm_lib.c:2263

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (&runtime->buffer_mutex){+.+.}-{3:3}:
       __mutex_lock_common kernel/locking/mutex.c:600 [inline]
       __mutex_lock+0x12f/0x12f0 kernel/locking/mutex.c:733
       snd_pcm_hw_params+0xc9/0x18a0 sound/core/pcm_native.c:705
       snd_pcm_kernel_ioctl+0x164/0x310 sound/core/pcm_native.c:3410
       snd_pcm_oss_change_params_locked+0x14e2/0x3a70 sound/core/oss/pcm_oss.c:976
       snd_pcm_oss_change_params sound/core/oss/pcm_oss.c:1116 [inline]
       snd_pcm_oss_mmap+0x442/0x550 sound/core/oss/pcm_oss.c:2929
       call_mmap include/linux/fs.h:2085 [inline]
       mmap_region+0xba5/0x14a0 mm/mmap.c:1791
       do_mmap+0x863/0xfa0 mm/mmap.c:1582
       vm_mmap_pgoff+0x1b7/0x290 mm/util.c:519
       ksys_mmap_pgoff+0x40d/0x5a0 mm/mmap.c:1628
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x35/0x80 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae

-> #0 (&mm->mmap_lock#2){++++}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3096 [inline]
       check_prevs_add kernel/locking/lockdep.c:3219 [inline]
       validate_chain kernel/locking/lockdep.c:3834 [inline]
       __lock_acquire+0x2ac6/0x56c0 kernel/locking/lockdep.c:5060
       lock_acquire kernel/locking/lockdep.c:5672 [inline]
       lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5637
       __might_fault mm/memory.c:5301 [inline]
       __might_fault+0x104/0x170 mm/memory.c:5294
       _copy_to_user+0x25/0x140 lib/usercopy.c:28
       copy_to_user include/linux/uaccess.h:160 [inline]
       default_read_copy+0x10f/0x180 sound/core/pcm_lib.c:2013
       __snd_pcm_lib_xfer+0x1517/0x1e20 sound/core/pcm_lib.c:2282
       snd_pcm_oss_read3+0x1c4/0x400 sound/core/oss/pcm_oss.c:1292
       snd_pcm_oss_read2+0x300/0x3f0 sound/core/oss/pcm_oss.c:1503
       snd_pcm_oss_read1 sound/core/oss/pcm_oss.c:1550 [inline]
       snd_pcm_oss_read+0x620/0x7a0 sound/core/oss/pcm_oss.c:2788
       vfs_read+0x1ef/0x5d0 fs/read_write.c:480
       ksys_read+0x127/0x250 fs/read_write.c:620
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x35/0x80 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x44/0xae

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&runtime->buffer_mutex);
                               lock(&mm->mmap_lock#2);
                               lock(&runtime->buffer_mutex);
  lock(&mm->mmap_lock#2);

 *** DEADLOCK ***

1 lock held by syz-executor329/3588:
 #0: ffff88801afef230 (&runtime->buffer_mutex){+.+.}-{3:3}, at: wait_for_avail sound/core/pcm_lib.c:1913 [inline]
 #0: ffff88801afef230 (&runtime->buffer_mutex){+.+.}-{3:3}, at: __snd_pcm_lib_xfer+0xbca/0x1e20 sound/core/pcm_lib.c:2263

stack backtrace:
CPU: 0 PID: 3588 Comm: syz-executor329 Not tainted 5.17.0-next-20220328-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2176
 check_prev_add kernel/locking/lockdep.c:3096 [inline]
 check_prevs_add kernel/locking/lockdep.c:3219 [inline]
 validate_chain kernel/locking/lockdep.c:3834 [inline]
 __lock_acquire+0x2ac6/0x56c0 kernel/locking/lockdep.c:5060
 lock_acquire kernel/locking/lockdep.c:5672 [inline]
 lock_acquire+0x1ab/0x510 kernel/locking/lockdep.c:5637
 __might_fault mm/memory.c:5301 [inline]
 __might_fault+0x104/0x170 mm/memory.c:5294
 _copy_to_user+0x25/0x140 lib/usercopy.c:28
 copy_to_user include/linux/uaccess.h:160 [inline]
 default_read_copy+0x10f/0x180 sound/core/pcm_lib.c:2013
 __snd_pcm_lib_xfer+0x1517/0x1e20 sound/core/pcm_lib.c:2282
 snd_pcm_oss_read3+0x1c4/0x400 sound/core/oss/pcm_oss.c:1292
 snd_pcm_oss_read2+0x300/0x3f0 sound/core/oss/pcm_oss.c:1503
 snd_pcm_oss_read1 sound/core/oss/pcm_oss.c:1550 [inline]
 snd_pcm_oss_read+0x620/0x7a0 sound/core/oss/pcm_oss.c:2788
 vfs_read+0x1ef/0x5d0 fs/read_write.c:480
 ksys_read+0x127/0x250 fs/read_write.c:620
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0x80 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f72068ad0f9
Code: 28 c3 e8 2a 14 00 00 66 2e 0f 1f 84 00 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 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fff51e1f1c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f72068ad0f9
RDX: 0000000000000ff2 RSI: 0000000020000780 RDI: 0000000000000004
RBP: 00007f72068710e0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f7206871170
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
 </TASK>

Crashes (3):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/03/28 18:51 linux-next 8515d05bf6bc ee339263 .config console log report syz C ci-upstream-linux-next-kasan-gce-root possible deadlock in __snd_pcm_lib_xfer
2022/03/28 10:39 linux-next 8515d05bf6bc ee339263 .config console log report info ci-upstream-linux-next-kasan-gce-root possible deadlock in __snd_pcm_lib_xfer
2022/03/28 08:15 linux-next 8515d05bf6bc 89bc8608 .config console log report info ci-upstream-linux-next-kasan-gce-root possible deadlock in __snd_pcm_lib_xfer
* Struck through repros no longer work on HEAD.