Linux Input/HID development
 help / color / mirror / Atom feed
From: Jiale Yao <yaojiale02@163.com>
To: Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Charles Wang <charles.goodix@gmail.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH] HID: goodix: validate coordinate package length
Date: Wed, 28 Oct 2026 13:09:01 +0800	[thread overview]
Message-ID: <20261028050901.139292-1-yaojiale02@163.com> (raw)

The coordinate package length comes from the device.  goodix_hid_irq()
checks only that it contains the length field before passing the
remaining length to hid_input_report().  A package length larger than
the fixed coordinate buffer therefore makes the HID core read beyond
the data fetched from the device.

Reject coordinate packages whose declared length exceeds the coordinate
buffer.

Fixes: 75e16c8ce283 ("HID: hid-goodix: Add Goodix HID-over-SPI driver")
Cc: stable@vger.kernel.org
Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 drivers/hid/hid-goodix-spi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-goodix-spi.c b/drivers/hid/hid-goodix-spi.c
index 03d549efbdce..eb63ee728a20 100644
--- a/drivers/hid/hid-goodix-spi.c
+++ b/drivers/hid/hid-goodix-spi.c
@@ -574,6 +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 package_size;
 	u16 report_size;
 
 	if (!test_bit(GOODIX_HID_STARTED, &ts->flags))
@@ -600,13 +601,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) {
+	package_size = le16_to_cpu(pkg->size);
+	if (package_size < GOODIX_HID_PKG_LEN_SIZE ||
+	    package_size > GOODIX_HID_COOR_PKG_LEN) {
 		dev_err(ts->dev, "invalid coordinate event package size, %d",
-			le16_to_cpu(pkg->size));
+			package_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);
+			 package_size - GOODIX_HID_PKG_LEN_SIZE, 1);
 
 	report_size = le16_to_cpu(event->hdr.size);
 	/* Check if there are other packages */
-- 
2.34.1


                 reply	other threads:[~2026-10-28  5:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261028050901.139292-1-yaojiale02@163.com \
    --to=yaojiale02@163.com \
    --cc=bentiss@kernel.org \
    --cc=charles.goodix@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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