From: sashiko-bot@kernel.org
To: "Jeffin Philip" <jeffinphilip14@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2] Input: atkbd - fix UAF in atkbd_set_repeat_rate() on disconnect
Date: Fri, 28 Aug 2026 10:15:27 +0000 [thread overview]
Message-ID: <20260828101528.6C8001F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828100547.120553-1-jeffinphilip14@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] A Time-of-Check to Time-of-Use (TOCTOU) race condition in `atkbd_event()` allows delayed work to be queued after `cancel_delayed_work_sync()`, leading to a Use-After-Free of the `atkbd` structure.
--
commit 0f8148a1f313524a8dd641967f56cd788e4c8ac4
Author: Jeffin Philip <jeffinphilip14@gmail.com>
Input: atkbd - fix UAF in atkbd_set_repeat_rate() on disconnect
This commit attempts to fix a use-after-free issue by closing the serio
port before canceling delayed work and adding an enabled check to
atkbd_event(). It aims to prevent work from being scheduled after
disconnection.
Link: https://lore.kernel.org/all/20260828080839.116065-1-jeffinphilip14@gmail.com/T/#u
> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
> --- a/drivers/input/keyboard/atkbd.c
> +++ b/drivers/input/keyboard/atkbd.c
> @@ -672,6 +672,9 @@ static int atkbd_event(struct input_dev *dev,
> if (!atkbd->write)
> return -1;
>
> + if (!atkbd->enabled)
> + return -1;
> +
[Severity: High]
Can this lockless check introduce a Time-of-Check to Time-of-Use (TOCTOU) race
condition?
If userspace calls evdev_write(), which invokes atkbd_event(), a thread could
read atkbd->enabled as true here, but then stall or be preempted before
actually scheduling the work.
[ ... ]
> @@ -963,17 +966,18 @@ static void atkbd_disconnect(struct serio *serio)
>
> atkbd_disable(atkbd);
>
> - input_unregister_device(atkbd->dev);
> -
> /*
> - * Make sure we don't have a command in flight.
> - * Note that since atkbd->enabled is false event work will keep
> - * rescheduling itself until it gets canceled and will not try
> - * accessing freed input device or serio port.
> + * close serio first so device will not get any data, which prevents
> + * atkbd_event_work from being rescheduled after cancel_delayed_work_sync
> + * returns. This ensures no work can dereference atkbd->dev after it has
> + * been freed.
> */
> - cancel_delayed_work_sync(&atkbd->event_work);
>
> serio_close(serio);
> + cancel_delayed_work_sync(&atkbd->event_work);
> +
> + input_unregister_device(atkbd->dev);
> +
[Severity: High]
If the thread running atkbd_event() is delayed after checking atkbd->enabled,
could it resume here and queue work after cancel_delayed_work_sync() has
already returned?
Since serio_close() only stops hardware interrupts and does not block userspace
from invoking atkbd_event(), atkbd_disconnect() could proceed to unregister
the device and free the atkbd structure.
When the delayed thread finally resumes and queues the work, won't that queued
work execute later and dereference the freed atkbd structure?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260828100547.120553-1-jeffinphilip14@gmail.com?part=1
next prev parent reply other threads:[~2026-08-28 10:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 10:05 [PATCH v2] Input: atkbd - fix UAF in atkbd_set_repeat_rate() on disconnect Jeffin Philip
2026-08-28 10:15 ` sashiko-bot [this message]
2026-08-28 14:32 ` Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260828101528.6C8001F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jeffinphilip14@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.