[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ef5a5364-94c1-452c-9c97-81f66246088a@kylinos.cn>
Date: Wed, 1 Oct 2025 18:42:10 +0800
From: pengyu <pengyu@...inos.cn>
To: Dmitry Torokhov <dmitry.torokhov@...il.com>
Cc: gregkh@...uxfoundation.org, jirislaby@...nel.org, legion@...nel.org,
mingo@...nel.org, myrrhperiwinkle@...labs.xyz, tglx@...utronix.de,
changlianzhi@...ontech.com, linux-kernel@...r.kernel.org,
linux-serial@...r.kernel.org,
syzbot+79c403850e6816dc39cf@...kaller.appspotmail.com,
jiangshanlai@...il.com, tj@...nel.org
Subject: Re: [PATCH] tty/vt: Fix possible deadlock in input_inject_event
在 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
Powered by blists - more mailing lists