From: Guanglei Zhu <zhugl3@xiaopeng.com>
To: dmitry.torokhov@gmail.com
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
liuc63@xiaopeng.com, stable@vger.kernel.org
Subject: [PATCH v3 3/4] Input: adi - reject ID packets with wrapped axis or button counts
Date: Tue, 1 Dec 2026 20:23:13 +0800 [thread overview]
Message-ID: <20261201122314.361354-4-zhugl3@xiaopeng.com> (raw)
In-Reply-To: <20261201122314.361354-1-zhugl3@xiaopeng.com>
adi_id_decode() derives the counts from fields of the ID packet and
hands them to adi_decode() and the input device setup:
adi->axes10 = adi->axes8 - i;
...
adi->buttons -= 4;
Nothing checks that the packet leaves enough behind for the split. A
10-bit axis count larger than the 8-bit one, or a TPD or WGP packet
with fewer than four buttons, subtracts below zero, and the loops that
report the axes and buttons then quietly do nothing. The fields are
plain char as well, so what they hold depends on whether char is
signed on the architecture.
Store the byte fields as u8 and pad as s8 so the values do not change
with the architecture, and reject an ID packet whose split or button
count would wrap instead of letting the wrapped value reach the loops
that walk the axis and button tables.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Guanglei Zhu <zhugl3@xiaopeng.com>
---
Tested with a bit stream builder for the ID packet, built with ASan.
On master a packet whose 10-bit split is larger than the 8-bit count
gives axes10 = -1, and a TPD packet with three buttons gives
buttons = -1; the reporting loops then skip them. With this patch both
packets are rejected with length = 0. Storing the counts as u8 without
the checks wraps them to 255 instead, and the wrapped counts walk past
adi_key[] and adi_abs[] - ASan reports a read past the 8 entry table.
drivers/input/joystick/adi.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index ad0845e..57a7978 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -91,18 +91,18 @@ struct adi {
int length;
int ret;
int idx;
- unsigned char id;
- char buttons;
- char axes10;
- char axes8;
- signed char pad;
- char hats;
+ u8 id;
+ u8 buttons;
+ u8 axes10;
+ u8 axes8;
+ s8 pad;
+ u8 hats;
char *abs;
short *key;
char name[ADI_MAX_NAME_LENGTH];
char cname[ADI_MAX_CNAME_LENGTH];
char phys[ADI_MAX_PHYS_LENGTH];
- unsigned char data[ADI_MAX_LENGTH];
+ u8 data[ADI_MAX_LENGTH];
};
struct adi_port {
@@ -364,6 +364,12 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
i = adi_get_bits(adi, 4);
if (t & ADI_FLAG_10BIT) {
+ if (i > adi->axes8) {
+ printk(KERN_WARNING "adi: Bad axis split (%d of %d 10-bit)\n",
+ i, adi->axes8);
+ adi->length = 0;
+ return;
+ }
adi->axes10 = adi->axes8 - i;
adi->axes8 = i;
}
@@ -383,11 +389,14 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
switch (adi->id) {
case ADI_ID_TPD:
- adi->pad = 4;
- adi->buttons -= 4;
- break;
case ADI_ID_WGP:
- adi->pad = 0;
+ if (adi->buttons < 4) {
+ printk(KERN_WARNING "adi: Bad button count (%d) for device %#x\n",
+ adi->buttons, adi->id);
+ adi->length = 0;
+ return;
+ }
+ adi->pad = adi->id == ADI_ID_TPD ? 4 : 0;
adi->buttons -= 4;
break;
default:
--
2.43.0
next prev parent reply other threads:[~2026-12-01 12:23 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 8:41 [PATCH] Input: joydev - avoid an undefined shift in the legacy 0x read Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: joydev - avoid signed overflow in the broken-axis correction Guanglei Zhu
2026-11-03 8:48 ` sashiko-bot
2026-11-03 8:55 ` [PATCH v2] " Guanglei Zhu
2026-11-04 3:38 ` Dmitry Torokhov
2026-11-04 5:50 ` [PATCH v3] " Guanglei Zhu
2026-11-04 23:45 ` Dmitry Torokhov
2026-11-04 6:02 ` Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: adi - bound the two-stream packet merge Guanglei Zhu
2026-11-03 8:55 ` sashiko-bot
2026-11-03 11:17 ` [PATCH v2] " Guanglei Zhu
2026-11-04 22:17 ` Dmitry Torokhov
2026-12-01 12:23 ` [PATCH v3 0/4] Input: adi - more bounds checks in the gameport packet path Guanglei Zhu
2026-12-01 12:23 ` [PATCH v3 1/4] Input: adi - reject stream merges that do not fit the buffer Guanglei Zhu
2026-12-01 12:23 ` [PATCH v3 2/4] Input: adi - fix the packet length guard in adi_read_packet() Guanglei Zhu
2026-12-01 12:23 ` Guanglei Zhu [this message]
2026-12-01 12:23 ` [PATCH v3 4/4] Input: adi - check the decoded counts against the device tables Guanglei Zhu
2026-12-01 12:41 ` [PATCH v3 0/4] Input: adi - more bounds checks in the gameport packet path Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: db9 - enlarge the Saturn multitap packet buffer Guanglei Zhu
2026-11-04 23:46 ` Dmitry Torokhov
2026-11-03 8:41 ` [PATCH] Input: lpc32xx-keys - reject matrices bigger than the hardware has Guanglei Zhu
2026-11-03 18:54 ` Dmitry Torokhov
2026-11-04 3:07 ` [PATCH v2] " Guanglei Zhu
2026-11-04 6:25 ` Dmitry Torokhov
2026-11-06 1:49 ` [PATCH v3] " Guanglei Zhu
2026-11-09 8:07 ` Dmitry Torokhov
2026-11-05 15:53 ` [PATCH v2] " sashiko-bot
2026-11-03 8:41 ` [PATCH] Input: mt6779-keypad - check the reported row and column Guanglei Zhu
2026-11-04 23:52 ` Dmitry Torokhov
2026-11-03 8:41 ` [PATCH] Input: tegra-kbc - check the pin numbers from the device tree Guanglei Zhu
2026-11-04 17:08 ` Dmitry Torokhov
2026-11-05 2:13 ` [PATCH v2] " Guanglei Zhu
2026-11-09 8:11 ` Dmitry Torokhov
2026-11-03 8:41 ` [PATCH] Input: cyapa_gen3 - clamp the reported finger count to the array Guanglei Zhu
2026-11-04 20:09 ` Dmitry Torokhov
2026-12-01 12:23 ` [PATCH v2] Input: cyapa_gen3 - reject reports with too many fingers Guanglei Zhu
2026-11-03 18:45 ` [PATCH] Input: joydev - avoid an undefined shift in the legacy 0x read Dmitry Torokhov
2026-11-04 3:07 ` [PATCH v2] " Guanglei Zhu
2026-11-09 8:19 ` 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=20261201122314.361354-4-zhugl3@xiaopeng.com \
--to=zhugl3@xiaopeng.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuc63@xiaopeng.com \
--cc=stable@vger.kernel.org \
/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