All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH 4/4] Input: psmouse - use guard() for resource management
Date: Mon, 27 Jul 2026 05:35:21 +0000	[thread overview]
Message-ID: <20260727053521.A5CA01F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727050803.1269941-4-dmitry.torokhov@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Unbounded array write (buffer overflow) in `psmouse_receive_byte` due to unhandled `protocol_handler = NULL`.
--

--- Patch [4]: [PATCH 4/4] Input: psmouse - use guard() for resource management ---
commit 7e27c0c560cf8dcd06bedf52a084dc88e9bf3ed9
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Input: psmouse - use guard() for resource management

Replace manual serialization with guard(mutex) and guard(serio_pause_rx)
where appropriate. This eliminates the need for explicit goto-based error
paths.

> diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
> index a9a110f2c860a..58b9b5dd7f085 100644
> --- a/drivers/input/mouse/psmouse-base.c
> +++ b/drivers/input/mouse/psmouse-base.c

[ ... ]

> @@ -1461,7 +1456,7 @@ static void psmouse_disconnect(struct serio *serio)
>  
>  	disable_work_sync(&psmouse->resync_work);
>  
> -	mutex_lock(&psmouse_mutex);
> +	guard(mutex)(&psmouse_mutex);
>  
>  	psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
>  

[Severity: Critical]
With the changes in the first patch of this series, psmouse_disconnect() sets
psmouse->state = PSMOUSE_CMD_MODE and sets psmouse->protocol_handler = NULL
before calling the vendor disconnect handler.

If a noisy or malicious PS/2 device (e.g., emulated by a BMC or USB adapter)
spams bytes during this driver unbind window, psmouse_receive_byte() will
place them into psmouse->packet[psmouse->pktcnt++] and call
psmouse_handle_byte().

Because protocol_handler is NULL, psmouse_handle_byte() immediately returns 0:

drivers/input/mouse/psmouse-base.c:psmouse_handle_byte() {
    ...
	/* protocol_handler is NULL when device is being disconnected */
	if (unlikely(!psmouse->protocol_handler))
		return 0;
    ...
}

Since pktcnt is never reset here, could this regression allow pktcnt to
continuously increment and overflow the 8-byte psmouse->packet[] array on
subsequent bytes, corrupting struct psmouse fields and adjacent memory?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260727050803.1269941-1-dmitry.torokhov@gmail.com?part=4

  reply	other threads:[~2026-07-27  5:35 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 [this message]
2026-07-27  5:38 ` [PATCH 1/4] Input: psmouse - fix use-after-free during protocol disconnect sashiko-bot
2026-07-27  5:53   ` 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=20260727053521.A5CA01F000E9@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.