Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] platform/chrome: sensorhub: Check FIFO read reply length
@ 2026-11-25 12:13 Maoyi Xie
  2026-11-27  4:53 ` Tzung-Bi Shih
  0 siblings, 1 reply; 2+ messages in thread
From: Maoyi Xie @ 2026-11-25 12:13 UTC (permalink / raw)
  To: Tzung-Bi Shih, Benson Leung
  Cc: Guenter Roeck, Tomasz Figa, chrome-platform, stable

cros_ec_sensorhub_ring_handler() processes number_data entries of the
EC reply to MOTIONSENSE_CMD_FIFO_READ. It checks number_data against the
FIFO count and the ring space, but not against the reply length.

A malfunctioning EC can send fewer entries than number_data. The loop
then uses stale bytes as samples. Past max_response bytes, it reads
beyond the message buffer.

Stop reading when the reply does not hold all number_data entries.

Found with a CodeQL-based static analysis tool that we are developing.
Reproduced in a userspace harness under AddressSanitizer. Not tested on
hardware.

Fixes: 145d59baff59 ("platform/chrome: cros_ec_sensorhub: Add FIFO support")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.

 drivers/platform/chrome/cros_ec_sensorhub_ring.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_sensorhub_ring.c b/drivers/platform/chrome/cros_ec_sensorhub_ring.c
index cbaec9ff8fbd..1a4ad45ad804 100644
--- a/drivers/platform/chrome/cros_ec_sensorhub_ring.c
+++ b/drivers/platform/chrome/cros_ec_sensorhub_ring.c
@@ -969,6 +969,13 @@ static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub)
 				 number_data, fifo_info->count - i);
 			break;
 		}
+		if (ret < struct_size(&sensorhub->resp->fifo_read, data,
+				      number_data)) {
+			dev_warn_ratelimited(sensorhub->dev,
+					     "Invalid EC data: %d entries in %d bytes\n",
+					     number_data, ret);
+			break;
+		}
 		if (out + number_data >
 		    sensorhub->ring + fifo_info->count) {
 			dev_warn(sensorhub->dev,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-27  4:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 12:13 [PATCH] platform/chrome: sensorhub: Check FIFO read reply length Maoyi Xie
2026-11-27  4:53 ` Tzung-Bi Shih

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox