Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Vojtech Pavlik <vojtech@ucw.cz>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 01/10] Input: adi - prevent off-by-one write in adi_read_packet()
Date: Fri, 27 Nov 2026 20:09:55 +0000	[thread overview]
Message-ID: <20261127201050.3532488-2-lee@kernel.org> (raw)
In-Reply-To: <20261127201050.3532488-1-lee@kernel.org>

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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 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


       reply	other threads:[~2026-11-27 20:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261127201050.3532488-1-lee@kernel.org>
2026-11-27 20:09 ` Lee Jones [this message]
2026-11-27 20:09 ` [PATCH 02/10] Input: adi - validate axis and button counts in adi_id_decode() Lee Jones
2026-11-27 20:09 ` [PATCH 03/10] Input: xpad - cancel presence work on xpad360w_start_input() failure Lee Jones
2026-11-27 20:09 ` [PATCH 04/10] Input: aw86927 - use devm_work_autocancel() for haptics play work Lee Jones
2026-11-27 20:09 ` [PATCH 05/10] Input: stmfts - fix i2c_smbus_read_i2c_block_data() check in status sysfs Lee Jones
2026-11-27 20:35   ` David Heidelberg
2026-11-27 20:10 ` [PATCH 06/10] Input: xen-kbdfront - check info->ptr and info->kbd before dereferencing Lee Jones
2026-11-27 20:10 ` [PATCH 07/10] Input: drv2665 - disable haptics work across suspend and resume Lee Jones
2026-11-27 20:10 ` [PATCH 08/10] Input: drv2667 " Lee Jones
2026-11-27 20:10 ` [PATCH 09/10] Input: goodix_berlin_i2c - check i2c_get_match_data() for NULL Lee Jones
2026-11-27 20:10 ` [PATCH 10/10] Input: goodix_berlin_spi - validate ic_data and SPI max transfer size Lee Jones

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=20261127201050.3532488-2-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=vojtech@ucw.cz \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox