[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <dltckle3ksus7qojkpiirvush5khk52o36yhqnlfpiymrjjwzt@ev46jjxjhi3p>
Date: Sun, 28 Sep 2025 21:54:31 -0700
From: Dmitry Torokhov <dmitry.torokhov@...il.com>
To: pengyu <pengyu@...inos.cn>
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
Subject: Re: [PATCH] tty/vt: Fix possible deadlock in input_inject_event
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.
--
Dmitry
Powered by blists - more mailing lists