[PATCH 1/8] Input: adi - fix out-of-bounds write in adi_read_packet()
From: Dmitry Torokhov
Date: Mon Nov 30 2026 - 00:42:57 EST
adi_read_packet() initializes the per-stream packet counter to -1 and
pre-increments it before storing each sample into the fixed-size data
buffer, while checking the upper bound against the full buffer length.
When the buffer already holds 256 samples, another strobe passes the
check and writes one byte past the end of the buffer into adjacent
fields of struct adi_port, and leaves the counter out of bounds for
subsequent packet reads.
Bound the packet counter to one less than the buffer size so writes stay
within the data buffer.
Reported-by: sashiko-bot@xxxxxxxxxx
Closes: https://sashiko.dev/#/bug/linux-951334ec-a996-4dc4-a03b-d7e6f716e5de
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/input/joystick/adi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 0b60c8067faf..43c2e60fcb1c 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -141,7 +141,8 @@ static void adi_read_packet(struct adi_port *port)
for (i = 0; i < 2; i++, w >>= 2, x >>= 2) {
t[i]--;
if ((w & 0x30) && s[i]) {
- if ((w & 0x30) < 0x30 && adi[i].ret < ADI_MAX_LENGTH && t[i] > 0) {
+ if ((w & 0x30) < 0x30 &&
+ adi[i].ret < ADI_MAX_LENGTH - 1 && t[i] > 0) {
adi[i].data[++adi[i].ret] = w;
t[i] = gameport_time(gameport, ADI_MAX_STROBE);
} else t[i] = 0;
--
2.56.1.839.g22a8290db9-goog