[PATCH 01/10] Input: adi - prevent off-by-one write in adi_read_packet()

From: Lee Jones

Date: Fri Nov 27 2026 - 15:11:10 EST


adi[i].data holds ADI_MAX_LENGTH bytes and adi[i].ret is initialised to
-1 and pre-incremented before indexing adi[i].data[++adi[i].ret].
Checking adi[i].ret < ADI_MAX_LENGTH therefore allows a write to
adi[i].data[ADI_MAX_LENGTH] when adi[i].ret is ADI_MAX_LENGTH - 1,
corrupting the adjacent field in struct adi_port.

Compare adi[i].ret against ADI_MAX_LENGTH - 1 so the pre-incremented
index always stays within bounds.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Closes: https://sashiko.dev/#/bug/linux-951334ec-a996-4dc4-a03b-d7e6f716e5de
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/input/joystick/adi.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index e07b71978509..cfd585f89c2c 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -141,10 +141,14 @@ 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;
+ } else {
+ t[i] = 0;
+ }
} else if (!(x & 0x30)) s[i] = 1;
}
} while (t[0] > 0 || t[1] > 0);
--
2.56.1.839.g22a8290db9-goog