All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aibing Chen" <chenaibing@cmss.chinamobile.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH] Input: adi - use scnprintf() for the device name
Date: Thu, 26 Nov 2026 05:36:30 +0000	[thread overview]
Message-ID: <sashiko-outbox-234797@kernel.org> (raw)
In-Reply-To: <20261126053234.455-1-chenaibing@cmss.chinamobile.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] Input: adi - out-of-bounds access from unvalidated counts
  in adi_id_decode() [1]
--

commit cf403ee49ba4ff0238dcadf0ca631e797a95d76f
Author: Aibing Chen <chenaibing@cmss.chinamobile.com>

Input: adi - use scnprintf() for the device name

This commit switches from snprintf() to scnprintf() when formatting
adi->name in adi_init_input() to avoid -Wformat-truncation warnings.

> diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
> index e07b71978509b..0b60c8067faf8 100644
> --- a/drivers/input/joystick/adi.c
> +++ b/drivers/input/joystick/adi.c
> @@ -392,7 +392,7 @@ static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
>  	t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX;
>  
>  	snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id);
> -	snprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s [%s]", buf, adi->cname);
> +	scnprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s [%s]", buf, adi->cname);
>  	snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half);
>  
>  	adi->abs = adi_abs[t];

[Severity: Critical]
This problem wasn't introduced by this patch, but can the capability loops
further down in adi_init_input() read out of bounds on adi->abs and
adi->key [1]?

drivers/input/joystick/adi.c:adi_init_input() {
	...
	adi->abs = adi_abs[t];
	adi->key = adi_key[t];
	...
	for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++)
		set_bit(adi->abs[i], input_dev->absbit);

	for (i = 0; i < adi->buttons; i++)
		set_bit(adi->key[i], input_dev->keybit);
}

adi_id_decode() only checks the axis, hat, and button counts parsed from
the raw gameport ID packet against the packet bit length (< 256), which
allows up to 49 total axes and 126 buttons (or 252..255 buttons on
unsigned char underflow when subtracting 4 for ADI_ID_TPD or ADI_ID_WGP).
Because the per-device tables in adi_abs[] and adi_key[] hold at most 9
axes and 11 keys, indexing them with unvalidated counts in
adi_init_input(), adi_init_center(), and adi_decode() reads past the end
of the arrays and passes out-of-bounds bit indices to set_bit() and the
input reporting helpers, corrupting memory or crashing the kernel.

[1] https://sashiko.dev/#/bug/linux-92046c21-e0a8-4274-a502-20ca723131b1

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126053234.455-1-chenaibing@cmss.chinamobile.com?part=1

  reply	other threads:[~2026-11-26  5:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  5:32 [PATCH] Input: adi - use scnprintf() for the device name Aibing Chen
2026-11-26  5:36 ` sashiko-bot [this message]
2026-11-26  5:42 ` 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=sashiko-outbox-234797@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chenaibing@cmss.chinamobile.com \
    --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.