Re: [PATCH] tty/vt: Fix possible deadlock in input_inject_event

From: pengyu
Date: Wed Oct 01 2025 - 06:42:37 EST


在 2025/9/29 12:54, Dmitry Torokhov 写道:
Hi,

On Sun, Sep 28, 2025 at 09:08:19PM +0800, pengyu wrote:
syzkaller testing revealed a potential deadlock involving keyboard
handling:

CPU0 CPU1 CPU2
---- ---- ----
read_lock(tasklist_lock); evdev_write
input_inject_event write_lock(tasklist_lock);
lock(&dev->event_lock);
read_lock(tasklist_lock);
<Interrupt>
kbd_bh() / kd_sound_helper()
input_inject_event
lock(&dev->event_lock); // Deadlock risk

The deadlock occurs because:
1. Both kbd_bh and kd_sound_helper run in interrupt context
2. tasklist_lock is interrupt-unsafe
3. When evdev_write holds both dev->event_lock and tasklist_lock,
interrupt context attempts to acquire dev->event_lock create deadlock
risks

Convert both kbd_bh and kd_sound_helper to use workqueues. This moves
input_inject_event execution to process context, where it's safe to
acquire locks that may be held by code using interrupt-unsafe locks.

So if we ignore the input code and instead look at the send_sigio()
(which input core ends up calling) and do_wait() we see that
send_sigio() disables interrupts and takes the owner's spinlock
before taking the tasklist_lock, while do_wait() takes the tasklist_lock
first, without disabling interrupts. This is root of the issue as far as
I can tell and no amount of changes to the keyboard handler (which is
just happens to be in the middle) will not solve for all potential cases
and code paths.

I believe either do_exit() or send_sigio() have to be changed to fix
this properly.

Thanks.


Hi,

I noticed that besides do_wait, there are many places in the kernel where read_lock(tasklist_lock) is used without disabling interrupts. Addressing this solely through tasklist_lock may not fully resolve the issue.

This involves tasklist_lock, evdev_write, and various input device drivers. The only approach I can think of is to move functions like input_[inject]_event in the input drivers out of the interrupt context. This could affect many code paths, so I plan to start by modifying the keyboard code first.

--
Thanks,
Yu Peng