Re: [PATCH 7/10] i2c: usbio: Validate full reply length in split-read loop
From: Antti Laakso
Date: Fri Dec 04 2026 - 11:53:20 EST
On Thu, Dec 03, 2026 at 06:31:11PM +0000, Lee Jones wrote:
> In usbio_i2c_read(), the split-read loop checks only whether
> usbio_bulk_msg() returned a negative error code before copying rxchunk
> bytes from rbuf->data into msg->buf. On a short USB bulk reply, stale
> bytes remaining in the reused i2c->rwbuf buffer are copied into
> msg->buf and leaked to callers.
>
> Validate that usbio_bulk_msg() returns exactly sizeof(*rbuf) + rxchunk,
> matching the non-split path.
>
> Fixes: daf161343a39 ("i2c: Add Intel USBIO I2C driver")
> Closes: https://sashiko.dev/#/bug/linux-68c6624e-612b-4fc9-94f7-ecb3df8ff838
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
> ---
Tested-by: Antti Laakso <antti.laakso@xxxxxxxxxxxxxxx>
> drivers/i2c/busses/i2c-usbio.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-usbio.c b/drivers/i2c/busses/i2c-usbio.c
> index 12a4154860a4..063577cc0ddf 100644
> --- a/drivers/i2c/busses/i2c-usbio.c
> +++ b/drivers/i2c/busses/i2c-usbio.c
> @@ -103,8 +103,8 @@ static int usbio_i2c_read(struct i2c_adapter *adap, struct i2c_msg *msg)
> USBIO_I2CCMD_READ, true,
> rbuf, len == 0 ? sizeof(*rbuf) : 0,
> rbuf, sizeof(*rbuf) + rxchunk);
> - if (ret < 0)
> - return ret;
> + if (ret != sizeof(*rbuf) + rxchunk)
> + return (ret < 0) ? ret : -EIO;
>
> memcpy(&msg->buf[len], rbuf->data, rxchunk);
> len += rxchunk;
> --
> 2.56.1.911.g883d8bcb20-goog