All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jeffin Philip" <jeffinphilip14@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v4] Input: atkbd - fix uaf in atkbd_set_repeat_rate
Date: Sat, 29 Aug 2026 14:09:28 +0000	[thread overview]
Message-ID: <20260829140929.302901F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260829135959.14882-1-jeffinphilip14@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The patch fails to resolve the Use-After-Free (UAF) race condition it intends to fix because `disable_delayed_work_sync()` is incorrectly placed after `input_unregister_device()`.
--

commit 364595b57a843b20a975005b27712754f014825e
Author: Jeffin Philip <jeffinphilip14@gmail.com>

Input: atkbd - fix uaf in atkbd_set_repeat_rate
    
atkbd_disable() marks atkbd as disabled to prevent any work
event to be executed, however this can race with atkbd_event_work().
If a pending work passes the atkbd->enabled check and atkbd_disable()
runs after in disconnect, it could dereference dev which is freed in
disconnect following atkbd being marked disabled. Fix this by adding
disable_delayed_work_sync() which drops all work events preventing
any rescheduling after atkbd is marked disabled.
    
Reported-by: syzbot+1e2ef9bcb29af666b2e6@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1e2ef9bcb29af666b2e6
Fixes: 0ef7a26af127 ("Input: atkbd - fix canceling event_work in disconnect")
Signed-off-by: Jeffin Philip <jeffinphilip14@gmail.com>

> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
> index 3509b58e64920..0d75a7ba48d3c 100644
> --- a/drivers/input/keyboard/atkbd.c
> +++ b/drivers/input/keyboard/atkbd.c
> @@ -966,12 +966,9 @@ static void atkbd_disconnect(struct serio *serio)
>  	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.
> +	 * Prevent work from being rescheduled after atkbd is marked disabled
>  	 */
> -	cancel_delayed_work_sync(&atkbd->event_work);
> +	disable_delayed_work_sync(&atkbd->event_work);

[Severity: High]
This isn't a bug introduced by this patch, but does calling
disable_delayed_work_sync() after input_unregister_device() leave a
Use-After-Free race window open for the background work?

If atkbd_event_work() executes concurrently with atkbd_disconnect() and
passes the atkbd->enabled check, it can access atkbd->dev after it has
been freed.

For example, if atkbd_disconnect() calls input_unregister_device(atkbd->dev)
which drops the last reference and frees the device, the background work
could then access the freed dev in atkbd_set_leds():

drivers/input/keyboard/atkbd.c:atkbd_set_leds() {
    ...
	param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0)
    ...
}

Should disable_delayed_work_sync() be moved above input_unregister_device()
to fully close this race window and ensure the work item cannot execute
after the device is freed?

>  
>  	serio_close(serio);
>  	serio_set_drvdata(serio, NULL);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260829135959.14882-1-jeffinphilip14@gmail.com?part=1

  reply	other threads:[~2026-08-29 14:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29 13:59 [PATCH v4] Input: atkbd - fix uaf in atkbd_set_repeat_rate Jeffin Philip
2026-08-29 14:09 ` sashiko-bot [this message]
2026-08-29 16:34 ` Dmitry Torokhov
2026-08-30  8:14   ` Jeffin Philip
2026-08-30  8:27     ` Jeffin Philip

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=20260829140929.302901F000E9@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.