* [PATCH] Input: adi - use scnprintf() for the device name
@ 2026-11-26 5:32 Aibing Chen
2026-11-26 5:36 ` sashiko-bot
2026-11-26 5:42 ` Dmitry Torokhov
0 siblings, 2 replies; 3+ messages in thread
From: Aibing Chen @ 2026-11-26 5:32 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input, linux-kernel
adi_init_input() composes the device name as "Logitech %s [%s]" from the
model string in buf[] and the controller name in adi->cname, into a 64
byte array. buf can hold up to 63 characters and cname up to 15, so the
composed name can reach 90 bytes and does not fit. The name is
informational and truncating it is acceptable, but the call site does not
say so.
Building with W=1, where -Wformat-truncation is enabled, the file does not
build today; COMPILE_TEST configurations additionally turn the warning
into an error through CONFIG_WERROR:
drivers/input/joystick/adi.c:395:60: error: '%s' directive output may be
truncated writing up to 63 bytes into a region of size 55
[-Werror=format-truncation=]
Use scnprintf(), the helper that expresses a bounded, truncation tolerant
write, so that the file builds warning free and the intent is visible at
the call site.
No functional change.
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
drivers/input/joystick/adi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index e07b71978..0b60c8067 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];
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] Input: adi - use scnprintf() for the device name
2026-11-26 5:32 [PATCH] Input: adi - use scnprintf() for the device name Aibing Chen
@ 2026-11-26 5:36 ` sashiko-bot
2026-11-26 5:42 ` Dmitry Torokhov
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-26 5:36 UTC (permalink / raw)
To: Aibing Chen; +Cc: linux-input, dmitry.torokhov
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Input: adi - use scnprintf() for the device name
2026-11-26 5:32 [PATCH] Input: adi - use scnprintf() for the device name Aibing Chen
2026-11-26 5:36 ` sashiko-bot
@ 2026-11-26 5:42 ` Dmitry Torokhov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2026-11-26 5:42 UTC (permalink / raw)
To: Aibing Chen; +Cc: linux-input, linux-kernel
On Thu, Nov 26, 2026 at 01:32:34PM +0800, Aibing Chen wrote:
> adi_init_input() composes the device name as "Logitech %s [%s]" from the
> model string in buf[] and the controller name in adi->cname, into a 64
> byte array. buf can hold up to 63 characters and cname up to 15, so the
> composed name can reach 90 bytes and does not fit. The name is
> informational and truncating it is acceptable, but the call site does not
> say so.
>
> Building with W=1, where -Wformat-truncation is enabled, the file does not
> build today; COMPILE_TEST configurations additionally turn the warning
> into an error through CONFIG_WERROR:
>
> drivers/input/joystick/adi.c:395:60: error: '%s' directive output may be
> truncated writing up to 63 bytes into a region of size 55
> [-Werror=format-truncation=]
>
> Use scnprintf(), the helper that expresses a bounded, truncation tolerant
> write, so that the file builds warning free and the intent is visible at
> the call site.
>
> No functional change.
>
> Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
Applied, thank you.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-26 5:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 5:32 [PATCH] Input: adi - use scnprintf() for the device name Aibing Chen
2026-11-26 5:36 ` sashiko-bot
2026-11-26 5:42 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox