platform/chrome: sensorhub: Bound the EC-reported sensor number

Each EC FIFO event carries an 8-bit sensor number (in->sensor_num).
cros_ec_sensorhub_ring_handler() validates the FIFO event count, the
per-read count and the ring bound, but not the sensor number, which
cros_ec_sensor_ring_process_event() then uses unchecked to index
sensorhub->batch_state[] - allocated with only sensorhub->sensor_num
entries. A sensor number of sensor_num or larger is an out-of-bounds
read and write of batch_state[].

Validate the sensor number in the ring handler, where each event is read
from the EC, and drop a malformed event before it is used.

Fixes: 145d59baff ("platform/chrome: cros_ec_sensorhub: Add FIFO support")
Cc: [email protected]
Signed-off-by: Bryam Vargas <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Tzung-Bi Shih <[email protected]>
This commit is contained in:
Bryam Vargas authored and Tzung-Bi Shih committed 2026-06-29 02:47:59 +00:00
1 parent dc59e4fea9
commit 833740a233
1 file changed
+8
@@ -890,6 +890,14 @@ static void cros_ec_sensorhub_ring_handler(struct cros_ec_sensorhub *sensorhub)
for (in = sensorhub->resp->fifo_read.data, j = 0;
j < number_data; j++, in++) {
/* Skip event if sensor_num from EC is out of bounds. */
if (in->sensor_num >= sensorhub->sensor_num) {
dev_warn_ratelimited(sensorhub->dev,
"Invalid sensor number %u from EC\n",
in->sensor_num);
continue;
}
if (cros_ec_sensor_ring_process_event(
sensorhub, fifo_info,
fifo_timestamp,