diff options
| author | Michael Zaidman <michael.zaidman@gmail.com> | 2026-08-27 00:40:02 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2026-09-02 14:27:27 +0200 |
| commit | 99529fb0fb709e579cdcbbd5e523d346c6fc6af9 (patch) | |
| tree | e492de3a20a88ba3b5945800ae7bd01b49b97af4 | |
| parent | ee77bdbe753840e634794cbdc56bd27ce8af88b6 (diff) | |
| download | linux-99529fb0fb709e579cdcbbd5e523d346c6fc6af9.tar.gz linux-99529fb0fb709e579cdcbbd5e523d346c6fc6af9.zip | |
HID: ft260: skip unexpected HID input reports
[ Upstream commit b7121e3c04440cc2af9cabbabb24efd23741294a ]
The FT260 is not supposed to generate unexpected HID reports. However,
in theory, the unsolicited HID Input reports can be issued by a specially
crafted malicious USB device masquerading as FT260 when the attacker has
physical access to the USB port. In this case, the read_buf pointer points
to the final data portion of the previous I2C Read transfer, and the memcpy
invoked in the ft260_raw_event() will try copying the content of the
unexpected report into the wrong location.
This commit sets the Read buffer pointer to NULL on the I2C Read
transaction completion and checks it in the ft260_raw_event() to detect
and skip the unsolicited Input report.
Reported-by: Enrik Berkhan <Enrik.Berkhan@inka.de>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Stable-dep-of: bf3e39df3a39 ("HID: ft260: fix stack-use-after-return write in I2C read race")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | drivers/hid/hid-ft260.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c index 854876b16880..6f6bfd305e22 100644 --- a/drivers/hid/hid-ft260.c +++ b/drivers/hid/hid-ft260.c @@ -471,17 +471,13 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, struct ft260_i2c_read_request_report rep; struct hid_device *hdev = dev->hdev; int timeout; - int ret; + int ret = 0; if (len > FT260_RD_DATA_MAX) { hid_err(hdev, "%s: unsupported rd len: %d\n", __func__, len); return -EINVAL; } - dev->read_idx = 0; - dev->read_buf = data; - dev->read_len = len; - rep.report = FT260_I2C_READ_REQ; rep.length = cpu_to_le16(len); rep.address = addr; @@ -492,25 +488,36 @@ static int ft260_i2c_read(struct ft260_device *dev, u8 addr, u8 *data, reinit_completion(&dev->wait); + dev->read_idx = 0; + dev->read_buf = data; + dev->read_len = len; + ret = ft260_hid_output_report(hdev, (u8 *)&rep, sizeof(rep)); if (ret < 0) { hid_err(hdev, "%s: failed to start transaction, ret %d\n", __func__, ret); - return ret; + goto ft260_i2c_read_exit; } timeout = msecs_to_jiffies(5000); if (!wait_for_completion_timeout(&dev->wait, timeout)) { + ret = -ETIMEDOUT; ft260_i2c_reset(hdev); - return -ETIMEDOUT; + goto ft260_i2c_read_exit; } + dev->read_buf = NULL; + ret = ft260_xfer_status(dev); - if (ret == 0) - return 0; + if (ret < 0) { + ret = -EIO; + ft260_i2c_reset(hdev); + goto ft260_i2c_read_exit; + } - ft260_i2c_reset(hdev); - return -EIO; +ft260_i2c_read_exit: + dev->read_buf = NULL; + return ret; } /* @@ -1033,6 +1040,13 @@ static int ft260_raw_event(struct hid_device *hdev, struct hid_report *report, ft260_dbg("i2c resp: rep %#02x len %d\n", xfer->report, xfer->length); + if ((dev->read_buf == NULL) || + (xfer->length > dev->read_len - dev->read_idx)) { + hid_err(hdev, "unexpected report %#02x, length %d\n", + xfer->report, xfer->length); + return -1; + } + memcpy(&dev->read_buf[dev->read_idx], &xfer->data, xfer->length); dev->read_idx += xfer->length; |
