platform/chrome: sensorhub: Check FIFO read reply length
PATCH 1/1 platform/chrome: sensorhub: Check FIFO read reply length
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")
Signed-off-by Maoyi Xie <[email protected]>
---
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(+)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +7 -0
@@ -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,
Signature · 1 line
2.34.1