syzbot


possible deadlock in tty_port_close_start

Status: fixed on 2021/06/15 21:27
Reported-by: syzbot+5420bc7f334912e0c8b2@syzkaller.appspotmail.com
Fix commit: 1f51881e2dcc ttyprintk: Add TTY hangup callback.
First crash: 1540d, last: 1075d
Fix bisection: fixed by (bisect log) :
commit 1f51881e2dccac944682e08b23ec441678809443
Author: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Date: Thu Apr 15 00:22:22 2021 +0000

  ttyprintk: Add TTY hangup callback.

  
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-4.14 possible deadlock in tty_port_close_start C error 49 597d 1531d 0/1 upstream: reported C repro on 2020/02/15 19:33
upstream possible deadlock in tty_port_close_start serial C done error 43 938d 1533d 0/26 auto-obsoleted due to no activity on 2022/10/02 01:37

Sample crash report:
wlan0: Created IBSS using preconfigured BSSID 50:50:50:50:50:50
IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
wlan0: Creating new IBSS network, BSSID 50:50:50:50:50:50
ttyprintk ttyprintk: tty_port_close_start: tty->count = 1 port count = 39
======================================================
WARNING: possible circular locking dependency detected
4.19.157-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor686/9659 is trying to acquire lock:
00000000f946559c (console_owner){....}, at: console_trylock_spinning kernel/printk/printk.c:1697 [inline]
00000000f946559c (console_owner){....}, at: vprintk_emit+0x3fe/0x740 kernel/printk/printk.c:1964

but task is already holding lock:
0000000070bdabad (&(&port->lock)->rlock){-.-.}, at: tty_port_close_start.part.0+0x28/0x540 drivers/tty/tty_port.c:574

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (&(&port->lock)->rlock){-.-.}:
       tty_port_tty_get+0x1d/0x80 drivers/tty/tty_port.c:289
       tty_port_default_wakeup+0x11/0x40 drivers/tty/tty_port.c:47
       serial8250_tx_chars+0x490/0xaf0 drivers/tty/serial/8250/8250_port.c:1806
       serial8250_handle_irq.part.0+0x31f/0x3d0 drivers/tty/serial/8250/8250_port.c:1893
       serial8250_handle_irq drivers/tty/serial/8250/8250_port.c:1866 [inline]
       serial8250_default_handle_irq+0xae/0x220 drivers/tty/serial/8250/8250_port.c:1909
       serial8250_interrupt+0x101/0x240 drivers/tty/serial/8250/8250_core.c:125
       __handle_irq_event_percpu+0x27e/0x8e0 kernel/irq/handle.c:149
       handle_irq_event_percpu kernel/irq/handle.c:189 [inline]
       handle_irq_event+0x102/0x285 kernel/irq/handle.c:206
       handle_edge_irq+0x260/0xcf0 kernel/irq/chip.c:797
       generic_handle_irq_desc include/linux/irqdesc.h:155 [inline]
       handle_irq+0x35/0x50 arch/x86/kernel/irq_64.c:87
       do_IRQ+0x93/0x1c0 arch/x86/kernel/irq.c:246
       ret_from_intr+0x0/0x1e
       native_safe_halt+0xe/0x10 arch/x86/include/asm/irqflags.h:60
       arch_safe_halt arch/x86/include/asm/paravirt.h:94 [inline]
       default_idle+0x49/0x310 arch/x86/kernel/process.c:557
       cpuidle_idle_call kernel/sched/idle.c:153 [inline]
       do_idle+0x2ec/0x4b0 kernel/sched/idle.c:263
       cpu_startup_entry+0xc5/0xe0 kernel/sched/idle.c:369
       start_kernel+0x8d6/0x911 init/main.c:736
       secondary_startup_64+0xa4/0xb0 arch/x86/kernel/head_64.S:243

-> #1 (&port_lock_key){-.-.}:
       serial8250_console_write+0x89b/0xad0 drivers/tty/serial/8250/8250_port.c:3270
       call_console_drivers kernel/printk/printk.c:1764 [inline]
       console_unlock+0xbb6/0x1110 kernel/printk/printk.c:2460
       vprintk_emit+0x2d1/0x740 kernel/printk/printk.c:1965
       vprintk_func+0x79/0x17e kernel/printk/printk_safe.c:397
       printk+0xba/0xed kernel/printk/printk.c:2040
       register_console+0x87f/0xc90 kernel/printk/printk.c:2776
       univ8250_console_init+0x3a/0x46 drivers/tty/serial/8250/8250_core.c:684
       console_init+0x4cb/0x718 kernel/printk/printk.c:2862
       start_kernel+0x686/0x911 init/main.c:659
       secondary_startup_64+0xa4/0xb0 arch/x86/kernel/head_64.S:243

-> #0 (console_owner){....}:
       console_trylock_spinning kernel/printk/printk.c:1718 [inline]
       vprintk_emit+0x43b/0x740 kernel/printk/printk.c:1964
       vprintk_func+0x79/0x17e kernel/printk/printk_safe.c:397
       printk+0xba/0xed kernel/printk/printk.c:2040
       tty_port_close_start.part.0+0x4f3/0x540 drivers/tty/tty_port.c:576
       tty_port_close_start drivers/tty/tty_port.c:648 [inline]
       tty_port_close+0x46/0x160 drivers/tty/tty_port.c:641
       tty_release+0x45e/0x1210 drivers/tty/tty_io.c:1678
       __fput+0x2ce/0x890 fs/file_table.c:278
       task_work_run+0x148/0x1c0 kernel/task_work.c:113
       tracehook_notify_resume include/linux/tracehook.h:193 [inline]
       exit_to_usermode_loop+0x251/0x2a0 arch/x86/entry/common.c:167
       prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
       syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
       do_syscall_64+0x538/0x620 arch/x86/entry/common.c:296
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

other info that might help us debug this:

Chain exists of:
  console_owner --> &port_lock_key --> &(&port->lock)->rlock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&(&port->lock)->rlock);
                               lock(&port_lock_key);
                               lock(&(&port->lock)->rlock);
  lock(console_owner);

 *** DEADLOCK ***

2 locks held by syz-executor686/9659:
 #0: 000000008e2197ec (&tty->legacy_mutex){+.+.}, at: tty_lock+0x6a/0xa0 drivers/tty/tty_mutex.c:19
 #1: 0000000070bdabad (&(&port->lock)->rlock){-.-.}, at: tty_port_close_start.part.0+0x28/0x540 drivers/tty/tty_port.c:574

stack backtrace:
CPU: 0 PID: 9659 Comm: syz-executor686 Not tainted 4.19.157-syzkaller #0
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+0x1fc/0x2fe lib/dump_stack.c:118
 print_circular_bug.constprop.0.cold+0x2d7/0x41e kernel/locking/lockdep.c:1221
 check_prev_add kernel/locking/lockdep.c:1865 [inline]
 check_prevs_add kernel/locking/lockdep.c:1978 [inline]
 validate_chain kernel/locking/lockdep.c:2419 [inline]
 __lock_acquire+0x30c9/0x3ff0 kernel/locking/lockdep.c:3415
 lock_acquire+0x170/0x3c0 kernel/locking/lockdep.c:3907
 console_trylock_spinning kernel/printk/printk.c:1718 [inline]
 vprintk_emit+0x43b/0x740 kernel/printk/printk.c:1964
 vprintk_func+0x79/0x17e kernel/printk/printk_safe.c:397
 printk+0xba/0xed kernel/printk/printk.c:2040
 tty_port_close_start.part.0+0x4f3/0x540 drivers/tty/tty_port.c:576
 tty_port_close_start drivers/tty/tty_port.c:648 [inline]
 tty_port_close+0x46/0x160 drivers/tty/tty_port.c:641
 tty_release+0x45e/0x1210 drivers/tty/tty_io.c:1678
 __fput+0x2ce/0x890 fs/file_table.c:278
 task_work_run+0x148/0x1c0 kernel/task_work.c:113
 tracehook_notify_resume include/linux/tracehook.h:193 [inline]
 exit_to_usermode_loop+0x251/0x2a0 arch/x86/entry/common.c:167
 prepare_exit_to_usermode arch/x86/entry/common.c:198 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:271 [inline]
 do_syscall_64+0x538/0x620 arch/x86/entry/common.c:296
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x409961
Code: 75 14 b8 03 00 00 00 0f 05 48 3d 01 f0 ff ff 0f 83 24 1a 00 00 c3 48 83 ec 08 e8 0a fc ff ff 48 89 04 24 b8 03 00 00 00 0f 05 <48> 8b 3c 24 48 89 c2 e8 53 fc ff ff 48 89 d0 48 83 c4 08 48 3d 01
RSP: 002b:00007ffc2f25fff0 EFLAGS: 00000293 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000004 RCX: 0000000000409961
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003
RBP: 00000000006e1c30 R08: 00000000004b3912 R09: 00000000004b3912
R10: 00007ffc2f260010 R11: 0000000000000293 R12: 00000000006e1c3c
R13: 0000000000000001 R14: 000000000000002d R15: 20c49ba5e353f7cf
IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
IPv6: ADDRCONF(NETDEV_UP): wlan1: link is not ready
wlan0: Created IBSS using preconfigured BSSID 50:50:50:50:50:50
ieee80211 phy13: Selected rate control algorithm 'minstrel_ht'
wlan0: Creating new IBSS network, BSSID 50:50:50:50:50:50
IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
wlan1: Created IBSS using preconfigured BSSID 50:50:50:50:50:50
IPv6: ADDRCONF(NETDEV_UP): wlan1: link is not ready
wlan1: Creating new IBSS network, BSSID 50:50:50:50:50:50
IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready
wlan1: Created IBSS using preconfigured BSSID 50:50:50:50:50:50
wlan1: Creating new IBSS network, BSSID 50:50:50:50:50:50
IPv6: ADDRCONF(NETDEV_CHANGE): wlan1: link becomes ready

Crashes (47):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2020/11/15 02:22 linux-4.19.y 31acccdc8774 1bf9a662 .config console log report syz C ci2-linux-4-19
2021/05/16 11:19 linux-4.19.y 3c8c23092588 f54a5c09 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/05/04 08:40 linux-4.19.y 97a8651cadce 09efdd63 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/04/28 20:55 linux-4.19.y 97a8651cadce 77e2b668 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/04/11 08:07 linux-4.19.y 830a059cbba6 6a81331a .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/03/25 13:12 linux-4.19.y 78fec1611cbf 6a383ecf .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/03/23 00:52 linux-4.19.y 125222814e7b 8092f30d .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/03/21 22:35 linux-4.19.y 125222814e7b 4c9a64da .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/03/20 16:04 linux-4.19.y 125222814e7b e45f5621 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/03/10 20:33 linux-4.19.y 2cae3e25b706 764067f3 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/03/07 22:43 linux-4.19.y 2cae3e25b706 09fbf400 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/02/27 15:01 linux-4.19.y 2d19be4653f5 4c37c133 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/02/24 12:19 linux-4.19.y 2d19be4653f5 fcc6d71b .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/02/23 10:53 linux-4.19.y 255b58a2b3af fcc6d71b .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/02/13 14:55 linux-4.19.y 811218eceeaa 98682e5e .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/02/09 13:57 linux-4.19.y 811218eceeaa 2bd9619f .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/02/07 19:36 linux-4.19.y 811218eceeaa 2ce644fc .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/02/04 17:55 linux-4.19.y 811218eceeaa 42b90a7c .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/01/26 13:33 linux-4.19.y 2263955bf7e7 52e37319 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/01/26 12:57 linux-4.19.y 2263955bf7e7 52e37319 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/01/26 00:24 linux-4.19.y 2263955bf7e7 52e37319 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/01/22 18:46 linux-4.19.y 43d555d83c3f d4f4eca5 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2021/01/21 06:54 linux-4.19.y 43d555d83c3f d4f4eca5 .config console log report info ci2-linux-4-19 possible deadlock in tty_port_close_start
2020/12/25 06:24 linux-4.19.y 13d2ce42de8c c2c1d1dd .config console log report info ci2-linux-4-19
2020/12/14 21:01 linux-4.19.y 13d2ce42de8c 97183ed7 .config console log report info ci2-linux-4-19
2020/12/07 15:37 linux-4.19.y daefdc9eb24b f80ce148 .config console log report info ci2-linux-4-19
2020/11/26 04:04 linux-4.19.y 0c88e405c97e 3f581b43 .config console log report info ci2-linux-4-19
2020/11/19 21:50 linux-4.19.y 2c746135a12e 0767f13f .config console log report info ci2-linux-4-19
2020/11/15 17:51 linux-4.19.y 31acccdc8774 1bf9a662 .config console log report info ci2-linux-4-19
2020/11/13 20:03 linux-4.19.y 31acccdc8774 4a7fa9b4 .config console log report info ci2-linux-4-19
2020/11/03 22:19 linux-4.19.y f5d8eef067ac cba33199 .config console log report info ci2-linux-4-19
2020/10/09 19:57 linux-4.19.y a1b977b49b66 fa79ed2a .config console log report info ci2-linux-4-19
2020/09/04 19:35 linux-4.19.y c37da90efff5 abf9ba4f .config console log report ci2-linux-4-19
2020/08/25 06:43 linux-4.19.y d18b78abc0c6 344da168 .config console log report ci2-linux-4-19
2020/08/14 22:07 linux-4.19.y c14d30dc9987 5ce13532 .config console log report ci2-linux-4-19
2020/08/13 20:47 linux-4.19.y c14d30dc9987 ee7cb8b6 .config console log report ci2-linux-4-19
2020/08/04 08:59 linux-4.19.y 13af6c74b14a 96dd3623 .config console log report ci2-linux-4-19
2020/07/27 12:04 linux-4.19.y 20b3a3dfdf6c cb93dc6a .config console log report ci2-linux-4-19
2020/07/05 05:33 linux-4.19.y 399849e4654e 24d7f505 .config console log report ci2-linux-4-19
2020/06/26 13:27 linux-4.19.y a39e75458e1c b202c7a8 .config console log report ci2-linux-4-19
2020/04/15 22:19 linux-4.19.y 6dd0e32665e5 3f3c5574 .config console log report ci2-linux-4-19
2020/03/22 07:37 linux-4.19.y 14cfdbd39e31 78267cec .config console log report ci2-linux-4-19
2020/03/21 12:13 linux-4.19.y 14cfdbd39e31 aa6c6a55 .config console log report ci2-linux-4-19
2020/03/07 23:36 linux-4.19.y 7472c4028e23 2e9971bb .config console log report ci2-linux-4-19
2020/03/06 10:35 linux-4.19.y 7472c4028e23 7fb694ef .config console log report ci2-linux-4-19
2020/02/21 06:54 linux-4.19.y 4fccc2503536 bd2a74a3 .config console log report ci2-linux-4-19
2020/02/05 23:50 linux-4.19.y b499cf4b3a90 662cf49a .config console log report ci2-linux-4-19
* Struck through repros no longer work on HEAD.