From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Tianchu Chen <flynnnchen@tencent.com>,
Pan Chuang <panchuang@vivo.com>,
Charles Wang <charles.goodix@gmail.com>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 07/10] HID: hid-goodix-spi: Validate package sizes in goodix_hid_irq()
Date: Mon, 23 Nov 2026 15:50:51 +0000 [thread overview]
Message-ID: <20261123155138.2907049-8-lee@kernel.org> (raw)
In-Reply-To: <20261123155138.2907049-1-lee@kernel.org>
goodix_hid_irq() reads incoming SPI reports into the 95-byte
ts->event_buf heap buffer. For the coordinate package, pkg->size is
only checked against the 2-byte minimum header size with no upper bound
check against GOODIX_HID_COOR_PKG_LEN (84 bytes), allowing an
out-of-bounds read of up to 65533 bytes via hid_input_report(). For
the trailing attachment package, neither the minimum header size nor
the remaining report byte count is checked, allowing both a 32-bit
unsigned length underflow when pkg->size < 2 and an out-of-bounds read
past ts->event_buf.
Validate that the coordinate package size does not exceed
GOODIX_HID_COOR_PKG_LEN, that the remaining report bytes hold a full
package header before reading the attachment, and that the attachment
package size lies within [GOODIX_HID_PKG_LEN_SIZE, rem_size].
Fixes: 75e16c8ce283 ("HID: hid-goodix: Add Goodix HID-over-SPI driver")
Closes: https://sashiko.dev/#/bug/linux-07f163f5-b48d-4fd5-addc-ba577c30fc6e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/hid/hid-goodix-spi.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/drivers/hid/hid-goodix-spi.c b/drivers/hid/hid-goodix-spi.c
index a2c6b92f74ee..c8c158a74235 100644
--- a/drivers/hid/hid-goodix-spi.c
+++ b/drivers/hid/hid-goodix-spi.c
@@ -574,7 +574,7 @@ static irqreturn_t goodix_hid_irq(int irq, void *data)
struct goodix_ts_data *ts = data;
struct goodix_hid_report_event *event;
struct goodix_hid_report_package *pkg;
- u16 report_size;
+ u16 report_size, pkg_size, rem_size;
if (!test_bit(GOODIX_HID_STARTED, &ts->flags))
return IRQ_HANDLED;
@@ -600,13 +600,15 @@ static irqreturn_t goodix_hid_irq(int irq, void *data)
return IRQ_HANDLED;
pkg = (struct goodix_hid_report_package *)event->data;
- if (le16_to_cpu(pkg->size) < GOODIX_HID_PKG_LEN_SIZE) {
- dev_err(ts->dev, "invalid coordinate event package size, %d",
- le16_to_cpu(pkg->size));
+ pkg_size = le16_to_cpu(pkg->size);
+ if (pkg_size < GOODIX_HID_PKG_LEN_SIZE ||
+ pkg_size > GOODIX_HID_COOR_PKG_LEN) {
+ dev_err(ts->dev, "invalid coordinate event package size, %u\n",
+ pkg_size);
return IRQ_HANDLED;
}
hid_input_report(ts->hid, HID_INPUT_REPORT, pkg->data,
- le16_to_cpu(pkg->size) - GOODIX_HID_PKG_LEN_SIZE, 1);
+ pkg_size - GOODIX_HID_PKG_LEN_SIZE, 1);
report_size = le16_to_cpu(event->hdr.size);
/* Check if there are other packages */
@@ -614,22 +616,34 @@ static irqreturn_t goodix_hid_irq(int irq, void *data)
return IRQ_HANDLED;
if (report_size >= ts->hid_max_event_sz) {
- dev_err(ts->dev, "package size exceed limit %d vs %d",
+ dev_err(ts->dev, "package size exceed limit %d vs %d\n",
report_size, ts->hid_max_event_sz);
return IRQ_HANDLED;
}
+ rem_size = report_size - GOODIX_HID_COOR_PKG_LEN;
+ if (rem_size < GOODIX_HID_PKG_LEN_SIZE) {
+ dev_err(ts->dev, "invalid attachment data length, %u\n", rem_size);
+ return IRQ_HANDLED;
+ }
+
/* Read the package behind the coordinate data */
pkg = goodix_get_event_report(ts, ts->hid_report_addr + sizeof(*event),
- ts->event_buf,
- report_size - GOODIX_HID_COOR_PKG_LEN);
+ ts->event_buf, rem_size);
if (!pkg) {
- dev_err(ts->dev, "failed read attachment data content");
+ dev_err(ts->dev, "failed read attachment data content\n");
+ return IRQ_HANDLED;
+ }
+
+ pkg_size = le16_to_cpu(pkg->size);
+ if (pkg_size < GOODIX_HID_PKG_LEN_SIZE || pkg_size > rem_size) {
+ dev_err(ts->dev, "invalid attachment package size, %u vs %u\n",
+ pkg_size, rem_size);
return IRQ_HANDLED;
}
hid_input_report(ts->hid, HID_INPUT_REPORT, pkg->data,
- le16_to_cpu(pkg->size) - GOODIX_HID_PKG_LEN_SIZE, 1);
+ pkg_size - GOODIX_HID_PKG_LEN_SIZE, 1);
return IRQ_HANDLED;
}
--
2.56.1.750.gf70dc682cf-goog
next prev parent reply other threads:[~2026-11-23 15:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 15:50 [PATCH 00/10] HID: Assorted bug fixes across HID core and drivers Lee Jones
2026-11-23 15:50 ` [PATCH 01/10] HID: core: Protect hid->inputs traversal in hid_check_keys_pressed() Lee Jones
2026-11-23 15:50 ` [PATCH 02/10] HID: mcp2221: Synchronise rxbuf access against raw_event callback Lee Jones
2026-11-23 15:50 ` [PATCH 03/10] HID: logitech-hidpp: Synchronise send_receive_buf against raw events Lee Jones
2026-11-23 15:50 ` [PATCH 04/10] HID: sensor-hub: Serialise synchronous read teardown under data->lock Lee Jones
2026-11-23 15:50 ` [PATCH 05/10] HID: roccat: pyra: Resolve USB device from parent in actual_profile Lee Jones
2026-11-23 15:50 ` [PATCH 06/10] HID: hyperv: Validate VMBus packet and payload bounds on receive Lee Jones
2026-11-23 15:50 ` Lee Jones [this message]
2026-11-23 15:50 ` [PATCH 08/10] HID: wacom: Stop HID hardware before releasing resources on mode change Lee Jones
2026-11-23 15:50 ` [PATCH 09/10] HID: debug: Hold driver_input_lock while dumping raw report descriptor Lee Jones
2026-11-23 15:50 ` [PATCH 10/10] HID: playstation: Cancel DualSense output worker on create failure 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=20261123155138.2907049-8-lee@kernel.org \
--to=lee@kernel.org \
--cc=bentiss@kernel.org \
--cc=charles.goodix@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=flynnnchen@tencent.com \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=panchuang@vivo.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