HID: mcp2221: validate report size in raw_event handler
Subsystems (3)
PATCH v2 1/1 HID: mcp2221: validate report size in raw_event handler
mcp2221_raw_event() accesses the data buffer at offsets up to 55 without validating the size parameter. Since __hid_input_report() invokes the driver's raw_event callback before hid_report_raw_event() performs its own report-size validation, a device sending a truncated HID report can cause out-of-bounds heap reads in the kernel.
The most critical access is the memcpy from data[50] into mcp->adc_values (6 bytes) when CONFIG_IIO is reachable. Other unchecked accesses include data[20] and a memcpy at data[22]. Additionally, a memcpy with device-controlled length (data[3], up to 60 bytes) from data[4] does not verify that size is large enough to cover the copy.
MCP2221 devices use 64-byte HID reports. Add a check at the top of the handler to reject any report shorter than expected, and log a warning to aid debugging.
--- drivers/hid/hid-mcp2221.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/hid/hid-mcp2221.c +5 -0
@@ -850,6 +850,11 @@ static int mcp2221_raw_event(struct hid_device *hdev, {u8 *buf;struct mcp2221 *mcp =hid_get_drvdata (hdev); +/* MCP2221 always sends 64-byte reports */ +if (size <64 ) { +hid_warn (hdev,"report too short: %d < 64\n" , size); +return 0 ; + }switch (data[0 ]) {
Signature · 1 line
2.43.0