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 4/4] Input: adi - check the decoded counts against the device tables
Date: Tue, 1 Dec 2026 20:23:14 +0800 [thread overview]
Message-ID: <20261201122314.361354-5-zhugl3@xiaopeng.com> (raw)
In-Reply-To: <20261201122314.361354-1-zhugl3@xiaopeng.com>
adi_id_decode() decodes the number of axes, hats and buttons from the
ID packet, and adi_init_input(), adi_init_center() and adi_decode()
then walk adi->abs and adi->key, the axis and key tables of the device:
for (i = 0; i < adi->axes10 + adi->axes8 +
(adi->hats + (adi->pad != -1)) * 2; i++)
set_bit(adi->abs[i], input_dev->absbit);
The packet is free to claim more axes or buttons than the device has,
which walks past the end of those static tables. Keep the size of both
tables next to the pointers and reject an ID packet whose counts do not
fit.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Guanglei Zhu <zhugl3@xiaopeng.com>
---
Tested with the same builder: an ID packet for device 0 that asks for
15 axes and 15 buttons passes the length check, and the setup loop then
reads adi_wmi_abs[9..14], past the end of that 9 entry table; ASan
reports a global-buffer-overflow. With this patch the packet is
rejected with length = 0.
drivers/input/joystick/adi.c | 48 +++++++++++++++++++++++++++++++-----
1 file changed, 42 insertions(+), 6 deletions(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 57a7978..a329fcb 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -67,11 +67,37 @@ static short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_B
static short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 };
static short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
-static char* adi_abs[] = { adi_wmi_abs, adi_wmgpe_abs, adi_wmf_abs, adi_cm2_abs, adi_wmi_abs, adi_wmf_abs,
- adi_wmgpe_abs, adi_wmed3d_abs, adi_wmgpe_abs, adi_wmgpe_abs, adi_wmi_abs };
+struct adi_tables {
+ char *abs;
+ unsigned int abs_count;
+ short *key;
+ unsigned int key_count;
+};
-static short* adi_key[] = { adi_wmi_key, adi_wmgpe_key, adi_cm2_key, adi_cm2_key, adi_wmi_key, adi_cm2_key,
- adi_wmgpe_key, adi_wmed3d_key, adi_wmgpe_key, adi_wmgpe_key, adi_wmi_key };
+static const struct adi_tables adi_tables[] = {
+ { adi_wmi_abs, ARRAY_SIZE(adi_wmi_abs), adi_wmi_key,
+ ARRAY_SIZE(adi_wmi_key) },
+ { adi_wmgpe_abs, ARRAY_SIZE(adi_wmgpe_abs), adi_wmgpe_key,
+ ARRAY_SIZE(adi_wmgpe_key) },
+ { adi_wmf_abs, ARRAY_SIZE(adi_wmf_abs), adi_cm2_key,
+ ARRAY_SIZE(adi_cm2_key) },
+ { adi_cm2_abs, ARRAY_SIZE(adi_cm2_abs), adi_cm2_key,
+ ARRAY_SIZE(adi_cm2_key) },
+ { adi_wmi_abs, ARRAY_SIZE(adi_wmi_abs), adi_wmi_key,
+ ARRAY_SIZE(adi_wmi_key) },
+ { adi_wmf_abs, ARRAY_SIZE(adi_wmf_abs), adi_cm2_key,
+ ARRAY_SIZE(adi_cm2_key) },
+ { adi_wmgpe_abs, ARRAY_SIZE(adi_wmgpe_abs), adi_wmgpe_key,
+ ARRAY_SIZE(adi_wmgpe_key) },
+ { adi_wmed3d_abs, ARRAY_SIZE(adi_wmed3d_abs), adi_wmed3d_key,
+ ARRAY_SIZE(adi_wmed3d_key) },
+ { adi_wmgpe_abs, ARRAY_SIZE(adi_wmgpe_abs), adi_wmgpe_key,
+ ARRAY_SIZE(adi_wmgpe_key) },
+ { adi_wmgpe_abs, ARRAY_SIZE(adi_wmgpe_abs), adi_wmgpe_key,
+ ARRAY_SIZE(adi_wmgpe_key) },
+ { adi_wmi_abs, ARRAY_SIZE(adi_wmi_abs), adi_wmi_key,
+ ARRAY_SIZE(adi_wmi_key) },
+};
/*
* Hat to axis conversion arrays.
@@ -403,6 +429,16 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
adi->pad = -1;
break;
}
+
+ t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX;
+ if (adi->axes10 + adi->axes8 +
+ (adi->hats + (adi->pad != -1)) * 2 > adi_tables[t].abs_count ||
+ adi->buttons > adi_tables[t].key_count) {
+ printk(KERN_WARNING "adi: Device %#x has no room for %d axes and %d buttons\n",
+ adi->id, adi->axes10 + adi->axes8 +
+ (adi->hats + (adi->pad != -1)) * 2, adi->buttons);
+ adi->length = 0;
+ }
}
static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
@@ -421,8 +457,8 @@ static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
snprintf(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];
- adi->key = adi_key[t];
+ adi->abs = adi_tables[t].abs;
+ adi->key = adi_tables[t].key;
input_dev->name = adi->name;
input_dev->phys = adi->phys;
--
2.43.0
next prev parent reply other threads:[~2026-12-01 12:23 UTC|newest]
Thread overview: 36+ 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: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 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 ` [PATCH v3 3/4] Input: adi - reject ID packets with wrapped axis or button counts Guanglei Zhu
2026-12-01 12:23 ` Guanglei Zhu [this message]
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-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-5-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
all inboxes | Powered by JetHome®