Linux-i2c Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] HID: ft260: check data size in ft260_smbus_write()
@ 2021-04-13 15:12 Michael Zaidman
  2021-05-05 12:33 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Zaidman @ 2021-04-13 15:12 UTC (permalink / raw)
  To: dan.carpenter, jikos, benjamin.tissoires, wsa
  Cc: linux-kernel, linux-input, linux-i2c, 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
       --> __i2c_smbus_xfer
           --> ft260_smbus_xfer
               --> ft260_smbus_write

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

Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/hid/hid-ft260.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
index 047aa85a7c83..080623b3abbe 100644
--- a/drivers/hid/hid-ft260.c
+++ b/drivers/hid/hid-ft260.c
@@ -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;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] HID: ft260: check data size in ft260_smbus_write()
  2021-04-13 15:12 [PATCH] HID: ft260: check data size in ft260_smbus_write() Michael Zaidman
@ 2021-05-05 12:33 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2021-05-05 12:33 UTC (permalink / raw)
  To: Michael Zaidman
  Cc: dan.carpenter, benjamin.tissoires, wsa, linux-kernel,
	linux-input, linux-i2c

On Tue, 13 Apr 2021, Michael Zaidman wrote:

> 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().
> 
> Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

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

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 15:12 [PATCH] HID: ft260: check data size in ft260_smbus_write() Michael Zaidman
2021-05-05 12:33 ` Jiri Kosina

Linux-i2c Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-i2c/0 linux-i2c/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-i2c linux-i2c/ https://lore.kernel.org/linux-i2c \
		linux-i2c@vger.kernel.org
	public-inbox-index linux-i2c

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-i2c


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git