HID: mcp2221: prevent a buffer overflow in mcp_smbus_write()
authorHarshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Mon, 20 Jun 2022 16:28:24 +0000 (09:28 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:23:56 +0000 (14:23 +0200)
commit91443c669d280937968f0aa4edefa741cfe35314
treefe92903eb6f7c836ded558bb567a06c2cac04adf
parenteafb19c8fe04f0badd4a9febe37540298570ac44
HID: mcp2221: prevent a buffer overflow in mcp_smbus_write()

[ Upstream commit 62ac2473553a00229e67bdf3cb023b62cf7f5a9a ]

Smatch Warning:
drivers/hid/hid-mcp2221.c:388 mcp_smbus_write() error: __memcpy()
'&mcp->txbuf[5]' too small (59 vs 255)
drivers/hid/hid-mcp2221.c:388 mcp_smbus_write() error: __memcpy() 'buf'
too small (34 vs 255)

The 'len' variable can take a value between 0-255 as it can come from
data->block[0] and it is user data. So add an bound check to prevent a
buffer overflow in memcpy().

Fixes: 67a95c21463d ("HID: mcp2221: add usb to i2c-smbus host bridge")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hid/hid-mcp2221.c