Thread (7 messages) flat view 7 messages, 3 authors, 3d ago

Re: [PATCH 1/2] HID: Intel-thc-hid: Intel-quicki2c: Use hid_safe_input_report()

From: sashiko-bot@kernel.org
Date: 2026-09-22 03:03:45

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] hid: intel-quicki2c: OOB memory access due to unadjusted buffer size in hid_safe_input_report()
--

commit fd2fb2220e67b32415f7045570713d7e64755020
Author: Even Xu [off-list ref]

HID: Intel-thc-hid: Intel-quicki2c: Use hid_safe_input_report()

This commit replaces the deprecated hid_input_report() with
hid_safe_input_report(). It tracks the allocated size of the input buffer and
passes it along to allow hid-core to validate the reported data length against
the actual buffer size.
quoted hunk ↗ jump to hunk
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
index 0d2ad7bc3648a..6cf19dac8e181 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c
@@ -315,7 +315,7 @@ static int handle_input_report(struct quicki2c_device *qcdev)
 		if (qcdev->state != QUICKI2C_ENABLED)
 			continue;
 
-		quicki2c_hid_send_report(qcdev, pkt->data,
+		quicki2c_hid_send_report(qcdev, pkt->data, qcdev->input_len,
 					 HIDI2C_DATA_LEN(le16_to_cpu(pkt->len)));
[Severity: High]
Does this code pass the unadjusted buffer size when pkt->data is offset by 2
bytes from the start of the buffer?

The buffer qcdev->input_buf is dynamically allocated to qcdev->input_len
bytes.

Since pkt is mapped to qcdev->input_buf, pkt->data is offset by
HIDI2C_LENGTH_LEN (2 bytes) from the start of the allocation.

Passing the full qcdev->input_len overstates the remaining capacity for
pkt->data by 2 bytes.

[ ... ]
quoted hunk ↗ jump to hunk
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c
index 8075992e8732e..1a220a50d934c 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -157,16 +157,18 @@ void quicki2c_hid_remove(struct quicki2c_device *qcdev)
  *
  * @qcdev: point to quicki2c device
  * @data: point to input report data buffer
+ * @buf_size: the allocated size of the input report data buffer
  * @data_len: the length of input report data
  *
  * Return: 0 on success, non zero on error.
  */
 int quicki2c_hid_send_report(struct quicki2c_device *qcdev,
-			     void *data, size_t data_len)
+			     void *data, size_t buf_size, size_t data_len)
 {
 	int ret;
 
-	ret = hid_input_report(qcdev->hid_dev, HID_INPUT_REPORT, data, data_len, 1);
+	ret = hid_safe_input_report(qcdev->hid_dev, HID_INPUT_REPORT, data,
+				    buf_size, data_len, 1);
[Severity: High]
Can passing this unadjusted buf_size to hid_safe_input_report() lead to an
out-of-bounds access?

If a device sends a pkt->len such that HIDI2C_DATA_LEN(pkt->len) equals
qcdev->input_len, hid_safe_input_report() will trust the data length since it
does not exceed the provided buf_size.

This would neutralize the core's bounds checks, allowing the core to read or
zero-pad 2 bytes past the end of the qcdev->input_buf allocation.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260922025437.940072-1-even.xu@intel.com?part=1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help