lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CANikGpeautjFq49hKPhZQ7TQ3zwjToQrGUw+A6Oux90AcQqvcA@mail.gmail.com>
Date: Mon, 26 Aug 2024 13:52:41 -0700
From: Juefei Pu <juefei.pu@...il.ucr.edu>
To: gregkh@...uxfoundation.org, jirislaby@...nel.org, 
	linux-kernel@...r.kernel.org, linux-serial@...r.kernel.org
Subject: BUG: WARNING: possible circular locking dependency detected

Hello,
We found the following issue using syzkaller on Linux v6.10.
A possible deadlock issue was discovered in function
`tty_buffer_flush` when it attempted to acquire lock `buf->lock`.

Unfortunately, the syzkaller failed to generate a reproducer.
But at least we have the report:

======================================================
WARNING: possible circular locking dependency detected
6.10.0 #13 Not tainted
------------------------------------------------------
kworker/0:0/8 is trying to acquire lock:
ffff8880130990b8 (&buf->lock){+.+.}-{3:3}, at:
tty_buffer_flush+0x75/0x3f0 drivers/tty/tty_buffer.c:229

but task is already holding lock:
ffffffff8da0eb20 (console_lock){+.+.}-{0:0}, at: vc_SAK+0x25/0x210
drivers/tty/vt/vt_ioctl.c:983

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (console_lock){+.+.}-{0:0}:
       console_lock+0x15f/0x1a0 kernel/printk/printk.c:2665
       con_flush_chars+0x67/0x260 drivers/tty/vt/vt.c:3503
       n_tty_write+0xfb6/0x12d0 drivers/tty/n_tty.c:2405
       iterate_tty_write drivers/tty/tty_io.c:1021 [inline]
       file_tty_write+0x589/0xa00 drivers/tty/tty_io.c:1096
       new_sync_write fs/read_write.c:497 [inline]
       vfs_write+0x8a1/0xc70 fs/read_write.c:590
       ksys_write+0x19b/0x2c0 fs/read_write.c:643
       do_syscall_x64 arch/x86/entry/common.c:52 [inline]
       do_syscall_64+0x7e/0x150 arch/x86/entry/common.c:83
       entry_SYSCALL_64_after_hwframe+0x67/0x6f

-> #1 (&tty->termios_rwsem){++++}-{3:3}:
       down_write+0x36/0x50 kernel/locking/rwsem.c:1579
       n_tty_flush_buffer+0x2d/0x240 drivers/tty/n_tty.c:358
       tty_buffer_flush+0x324/0x3f0 drivers/tty/tty_buffer.c:241
       tty_ldisc_flush+0x66/0xc0 drivers/tty/tty_ldisc.c:388
       tty_port_close_start+0x2e7/0x540 drivers/tty/tty_port.c:663
       tty_port_close+0x24/0x140 drivers/tty/tty_port.c:718
       tty_release+0x284/0xd70 drivers/tty/tty_io.c:1760
       __fput+0x24a/0x8a0 fs/file_table.c:422
       task_work_run+0x239/0x2f0 kernel/task_work.c:180
       resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
       exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
       exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
       __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
       syscall_exit_to_user_mode+0x12d/0x280 kernel/entry/common.c:218
       do_syscall_64+0x8a/0x150 arch/x86/entry/common.c:89
       entry_SYSCALL_64_after_hwframe+0x67/0x6f

-> #0 (&buf->lock){+.+.}-{3:3}:
       check_prev_add kernel/locking/lockdep.c:3134 [inline]
       check_prevs_add kernel/locking/lockdep.c:3253 [inline]
       validate_chain kernel/locking/lockdep.c:3869 [inline]
       __lock_acquire+0x37ac/0x8050 kernel/locking/lockdep.c:5137
       lock_acquire+0x1a9/0x400 kernel/locking/lockdep.c:5754
       __mutex_lock_common kernel/locking/mutex.c:608 [inline]
       __mutex_lock+0x131/0xd50 kernel/locking/mutex.c:752
       tty_buffer_flush+0x75/0x3f0 drivers/tty/tty_buffer.c:229
       tty_ldisc_flush+0x66/0xc0 drivers/tty/tty_ldisc.c:388
       __do_SAK+0xc4/0x710 drivers/tty/tty_io.c:3038
       vc_SAK+0x73/0x210 drivers/tty/vt/vt_ioctl.c:993
       process_one_work kernel/workqueue.c:3248 [inline]
       process_scheduled_works+0x977/0x1410 kernel/workqueue.c:3329
       worker_thread+0xaa0/0x1020 kernel/workqueue.c:3409
       kthread+0x2eb/0x380 kernel/kthread.c:389
       ret_from_fork+0x49/0x80 arch/x86/kernel/process.c:147
       ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:244

other info that might help us debug this:

Chain exists of:
  &buf->lock --> &tty->termios_rwsem --> console_lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(console_lock);
                               lock(&tty->termios_rwsem);
                               lock(console_lock);
  lock(&buf->lock);

 *** DEADLOCK ***

4 locks held by kworker/0:0/8:
 #0: ffff88801307a948 ((wq_completion)events){+.+.}-{0:0}, at:
process_one_work kernel/workqueue.c:3223 [inline]
 #0: ffff88801307a948 ((wq_completion)events){+.+.}-{0:0}, at:
process_scheduled_works+0x8fb/0x1410 kernel/workqueue.c:3329
 #1: ffffc900000afd20
((work_completion)(&vc_cons[currcons].SAK_work)){+.+.}-{0:0}, at:
process_one_work kernel/workqueue.c:3224 [inline]
 #1: ffffc900000afd20
((work_completion)(&vc_cons[currcons].SAK_work)){+.+.}-{0:0}, at:
process_scheduled_works+0x922/0x1410 kernel/workqueue.c:3329
 #2: ffffffff8da0eb20 (console_lock){+.+.}-{0:0}, at:
vc_SAK+0x25/0x210 drivers/tty/vt/vt_ioctl.c:983
 #3: ffff88802f1670a0 (&tty->ldisc_sem){++++}-{0:0}, at: tty_ldisc_ref
drivers/tty/tty_ldisc.c:263 [inline]
 #3: ffff88802f1670a0 (&tty->ldisc_sem){++++}-{0:0}, at:
tty_ldisc_flush+0x1b/0xc0 drivers/tty/tty_ldisc.c:386

stack backtrace:
CPU: 0 PID: 8 Comm: kworker/0:0 Not tainted 6.10.0 #13
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
Workqueue: events vc_SAK
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x23d/0x360 lib/dump_stack.c:114
 check_noncircular+0x36c/0x4a0 kernel/locking/lockdep.c:2187
 check_prev_add kernel/locking/lockdep.c:3134 [inline]
 check_prevs_add kernel/locking/lockdep.c:3253 [inline]
 validate_chain kernel/locking/lockdep.c:3869 [inline]
 __lock_acquire+0x37ac/0x8050 kernel/locking/lockdep.c:5137
 lock_acquire+0x1a9/0x400 kernel/locking/lockdep.c:5754
 __mutex_lock_common kernel/locking/mutex.c:608 [inline]
 __mutex_lock+0x131/0xd50 kernel/locking/mutex.c:752
 tty_buffer_flush+0x75/0x3f0 drivers/tty/tty_buffer.c:229
 tty_ldisc_flush+0x66/0xc0 drivers/tty/tty_ldisc.c:388
 __do_SAK+0xc4/0x710 drivers/tty/tty_io.c:3038
 vc_SAK+0x73/0x210 drivers/tty/vt/vt_ioctl.c:993
 process_one_work kernel/workqueue.c:3248 [inline]
 process_scheduled_works+0x977/0x1410 kernel/workqueue.c:3329
 worker_thread+0xaa0/0x1020 kernel/workqueue.c:3409
 kthread+0x2eb/0x380 kernel/kthread.c:389
 ret_from_fork+0x49/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:244
 </TASK>
tty tty1: SAK: killed process 7942 (agetty): by session
tty tty1: SAK: killed process 7942 (agetty): by controlling tty

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ