HID: ft260: validate report size and payload length in raw_event
Subsystems (3)
PATCH v2 1/1 HID: ft260: validate report size and payload length in raw_event
ft260_raw_event() casts the raw data buffer to a ft260_i2c_input_report struct and accesses its fields 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.
Additionally, even with a full-sized report, a corrupted xfer->length field can cause memcpy to read beyond the report buffer. The existing check only validates against the destination buffer size, not the source data available in the report.
Add two checks: reject reports shorter than FT260_REPORT_MAX_LENGTH, and verify that xfer->length does not exceed the actual data available in the report. Log warnings to aid debugging.
--- drivers/hid/hid-ft260.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/hid/hid-ft260.c +11 -0
@@ -1068,6 +1068,17 @@ static int ft260_raw_event(struct hid_device *hdev, struct hid_report *report,struct ft260_device *dev =hid_get_drvdata (hdev);struct ft260_i2c_input_report *xfer = (void *)data; +if (size <FT260_REPORT_MAX_LENGTH ) { +hid_warn (hdev,"short report: %d\n" , size); +return 0 ; + } + +if (xfer->length > size - offsetof(struct ft260_i2c_input_report , data)) { +hid_warn (hdev,"payload %d exceeds report size %d\n" , + xfer->length, size); +return 0 ; + } +if (xfer->report >=FT260_I2C_REPORT_MIN && xfer->report <=FT260_I2C_REPORT_MAX ) { ft260_dbg("i2c resp: rep %#02x len %d\n", xfer->report,
Signature · 1 line
2.43.0