Skip to contentSkip to conversation

HID: ft260: check data size in ft260_smbus_write()

PATCH In review Michael Zaidman 2 participants 2 messages Apr 13, 2021 – May 5, 2021

Subsystems (3)
lore
Share & tools
lore

Michael Zaidman

author maintainer
#0 lore raw

PATCH 1/1 HID: ft260: check data size in ft260_smbus_write()

Fixes 98189a0adfa0 ("HID: ft260: add usb hid to i2c host bridge driver")

The SMbus block transaction limits the number of bytes transferred to 32, but nothing prevents a user from specifying via ioctl a larger data size than the ft260 can handle in a single transfer.

i2cdev_ioctl_smbus()
--> i2c_smbus_xfer

       --> __i2c_smbus_xfer
           --> ft260_smbus_xfer
               --> ft260_smbus_write

This patch adds data size checking in the ft260_smbus_write().

---
 drivers/hid/hid-ft260.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hid/hid-ft260.c +4 -1
index 047aa85a7c83..080623b3abbe 100644
@@ -201,7 +201,7 @@ struct ft260_i2c_write_request_report {
 	u8 address;		/* 7-bit I2C address */
 	u8 flag;		/* I2C transaction condition */
 	u8 length;		/* data payload length */
-	u8 data[60];		/* data payload */
+	u8 data[FT260_WR_DATA_MAX]; /* data payload */
 } __packed;
 
 struct ft260_i2c_read_request_report {
@@ -429,6 +429,9 @@ static int ft260_smbus_write(struct ft260_device *dev, u8 addr, u8 cmd,
 	struct ft260_i2c_write_request_report *rep =
 		(struct ft260_i2c_write_request_report *)dev->write_buf;
 
+	if (data_len >= sizeof(rep->data))
+		return -EINVAL;
+
 	rep->address = addr;
 	rep->data[0] = cmd;
 	rep->length = data_len + 1;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 8 lines · Michael Zaidman
Fixes 98189a0adfa0 ("HID: ft260: add usb hid to i2c host bridge driver")

The SMbus block transaction limits the number of bytes transferred to 32, but nothing prevents a user from specifying via ioctl a larger data size than the ft260 can handle in a single transfer.

i2cdev_ioctl_smbus()
--> i2c_smbus_xfer

Quoted 8 lines
       --> __i2c_smbus_xfer
           --> ft260_smbus_xfer
               --> ft260_smbus_write

This patch adds data size checking in the ft260_smbus_write().

I have moved the 'Fixes:' tag to place where it belongs, and applied. Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs