Skip to content

Commit b56cc41

Browse files
ArnaudLcmBenjamin Tissoires
authored andcommitted
hid: fix I2C read buffer overflow in raw_event() for mcp2221
As reported by syzbot, mcp2221_raw_event lacked validation of incoming I2C read data sizes, risking buffer overflows in mcp->rxbuf during multi-part transfers. As highlighted in the DS20005565B spec, p44, we have: "The number of read-back data bytes to follow in this packet: from 0 to a maximum of 60 bytes of read-back bytes." This patch enforces we don't exceed this limit. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=52c1a7d3e5b361ccd346 Tested-by: [email protected] Signed-off-by: Arnaud Lecomte <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 9fc5194 commit b56cc41

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/hid/hid-mcp2221.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ static int mcp2221_raw_event(struct hid_device *hdev,
906906
}
907907
if (data[2] == MCP2221_I2C_READ_COMPL ||
908908
data[2] == MCP2221_I2C_READ_PARTIAL) {
909+
if (!mcp->rxbuf || mcp->rxbuf_idx < 0 || data[3] > 60) {
910+
mcp->status = -EINVAL;
911+
break;
912+
}
909913
buf = mcp->rxbuf;
910914
memcpy(&buf[mcp->rxbuf_idx], &data[4], data[3]);
911915
mcp->rxbuf_idx = mcp->rxbuf_idx + data[3];

0 commit comments

Comments
 (0)