From: sashiko-bot@kernel.org
To: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH 1/4] Input: psmouse - fix use-after-free during protocol disconnect
Date: Mon, 27 Jul 2026 05:38:08 +0000 [thread overview]
Message-ID: <20260727053809.030801F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727050803.1269941-1-dmitry.torokhov@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The patch introduces an unbounded increment of `psmouse->pktcnt` leading to a heap buffer overflow in the `psmouse->packet` array when stray bytes are received during protocol disconnect.
--
--- Patch [1]: [PATCH 1/4] Input: psmouse - fix use-after-free during protocol disconnect ---
commit 6906d0fc401466f9489746b3c6e47ede12a56c49
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Input: psmouse - fix use-after-free during protocol disconnect
This commit attempts to fix a use-after-free by explicitly setting
psmouse->protocol_handler to NULL inside a serio_pause_rx scoped_guard.
It also updates psmouse_handle_byte() to drop incoming bytes when the
handler is NULL.
> diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
> index 6ab5f1d96eaea..916a14b9b6a7d 100644
> --- a/drivers/input/mouse/psmouse-base.c
> +++ b/drivers/input/mouse/psmouse-base.c
> @@ -267,7 +267,13 @@ void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
> */
> static int psmouse_handle_byte(struct psmouse *psmouse)
> {
> - psmouse_ret_t rc = psmouse->protocol_handler(psmouse);
> + psmouse_ret_t rc;
> +
> + /* protocol_handler is NULL when device is being disconnected */
> + if (unlikely(!psmouse->protocol_handler))
> + return 0;
> +
[Severity: High]
Does this early return cause an out-of-bounds write in psmouse_receive_byte()?
By returning 0 here, we completely bypass the switch block below which is
responsible for resetting psmouse->pktcnt.
When stray bytes arrive during the disconnect window, psmouse_receive_byte()
will append them to the packet buffer and increment the counter:
psmouse_receive_byte() {
...
psmouse->packet[psmouse->pktcnt++] = data;
...
psmouse_handle_byte(psmouse);
}
If psmouse_handle_byte() keeps returning 0 without resetting pktcnt, won't
pktcnt grow monotonically and eventually overflow the 8-byte packet array?
> + rc = psmouse->protocol_handler(psmouse);
>
> switch (rc) {
> case PSMOUSE_BAD_DATA:
[ ... ]
> @@ -1466,6 +1472,9 @@ static void psmouse_disconnect(struct serio *serio)
> psmouse_deactivate(parent);
> }
>
> + scoped_guard(serio_pause_rx, serio)
> + psmouse->protocol_handler = NULL;
> +
> if (psmouse->disconnect)
> psmouse->disconnect(psmouse);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260727050803.1269941-1-dmitry.torokhov@gmail.com?part=1
next prev parent reply other threads:[~2026-07-27 5:38 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 5:07 [PATCH 1/4] Input: psmouse - fix use-after-free during protocol disconnect Dmitry Torokhov
2026-07-27 5:07 ` [PATCH 2/4] Input: psmouse - clean up locking around disable_work_sync() Dmitry Torokhov
2026-07-27 5:32 ` sashiko-bot
2026-07-27 5:52 ` Dmitry Torokhov
2026-07-27 5:08 ` [PATCH 3/4] Input: psmouse - modernize PNP ID parsing Dmitry Torokhov
2026-07-27 5:08 ` [PATCH 4/4] Input: psmouse - use guard() for resource management Dmitry Torokhov
2026-07-27 5:35 ` sashiko-bot
2026-07-27 5:38 ` sashiko-bot [this message]
2026-07-27 5:53 ` [PATCH 1/4] Input: psmouse - fix use-after-free during protocol disconnect 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=20260727053809.030801F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@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.