From: Triet Hoang <triet.hoang.dev@gmail.com>
To: linux-i2c@vger.kernel.org
Cc: bence98@sch.bme.hu, andi.shyti@kernel.org,
linux-kernel@vger.kernel.org,
Triet Hoang <triet.hoang.dev@gmail.com>
Subject: [PATCH] i2c: cp2615: Validate read length before copying
Date: Tue, 18 Aug 2026 12:47:37 +0000 [thread overview]
Message-ID: <20260818124737.64478-1-triet.hoang.dev@gmail.com> (raw)
The read_len field comes from the untrusted USB payload, which could
potentially exceed the client's originally requested buffer length or
MAX_I2C_SIZE, allowing an out-of-bounds read and write.
Limit read_len to the maximum size of the response buffer and return
-EPROTO for an invalid response.
Signed-off-by: Triet Hoang <triet.hoang.dev@gmail.com>
---
drivers/i2c/busses/i2c-cp2615.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-cp2615.c b/drivers/i2c/busses/i2c-cp2615.c
index 951de6249834..2c79530da306 100644
--- a/drivers/i2c/busses/i2c-cp2615.c
+++ b/drivers/i2c/busses/i2c-cp2615.c
@@ -136,7 +136,7 @@ cp2615_i2c_send(struct usb_interface *usbif, struct cp2615_i2c_transfer *i2c_w)
}
static int
-cp2615_i2c_recv(struct usb_interface *usbif, unsigned char tag, void *buf)
+cp2615_i2c_recv(struct usb_interface *usbif, unsigned char tag, void *buf, int len)
{
struct usb_device *usbdev = interface_to_usbdev(usbif);
struct cp2615_iop_msg *msg;
@@ -160,6 +160,11 @@ cp2615_i2c_recv(struct usb_interface *usbif, unsigned char tag, void *buf)
return -EIO;
}
+ if (i2c_r->read_len > len || i2c_r->read_len > MAX_I2C_SIZE) {
+ kfree(msg);
+ return -EPROTO;
+ }
+
res = cp2615_check_status(i2c_r->status);
if (!res)
memcpy(buf, &i2c_r->data, i2c_r->read_len);
@@ -236,7 +241,7 @@ cp2615_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
ret = cp2615_i2c_send(usbif, &i2c_w);
if (ret)
break;
- ret = cp2615_i2c_recv(usbif, i2c_w.tag, msg->buf);
+ ret = cp2615_i2c_recv(usbif, i2c_w.tag, msg->buf, msg->len);
}
if (ret < 0)
return ret;
--
2.53.0
reply other threads:[~2026-08-18 12:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260818124737.64478-1-triet.hoang.dev@gmail.com \
--to=triet.hoang.dev@gmail.com \
--cc=andi.shyti@kernel.org \
--cc=bence98@sch.bme.hu \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox