From: Andreas Kemnade <andreas@kemnade.info>
To: Lee Jones <lee@kernel.org>
Cc: Vignesh R <vigneshr@ti.com>, Aaro Koskinen <aaro.koskinen@iki.fi>,
Kevin Hilman <khilman@baylibre.com>,
Roger Quadros <rogerq@kernel.org>,
Tony Lindgren <tony@atomide.com>,
Janusz Krzysztofik <jmkrzyszt@gmail.com>,
Andi Shyti <andi.shyti@kernel.org>,
Imre Deak <imre.deak@nokia.com>,
Juha Yrjola <juha.yrjola@solidboot.com>,
Syed Khasim <x0khasim@ti.com>, Nishant Menon <nm@ti.com>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Shubhrajyoti D <shubhrajyoti@ti.com>, Felipe Balbi <balbi@ti.com>,
linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 04/10] i2c: omap: Check buf_len before buffer accesses in data transfer helpers
Date: Thu, 3 Dec 2026 23:00:21 +0100 [thread overview]
Message-ID: <20261203230021.17cbf5a7@kemnade.info> (raw)
In-Reply-To: <20261203183214.1939736-5-lee@kernel.org>
On Thu, 3 Dec 2026 18:31:08 +0000
Lee Jones <lee@kernel.org> wrote:
> omap_i2c_receive_data() and omap_i2c_transmit_data() dereference
> omap->buf without checking omap->buf_len. On controllers with
> OMAP_I2C_FLAG_16BIT_DATA_REG, any odd-length message reads or writes
> one byte past msg->buf and underflows omap->buf_len; FIFO counts
> exceeding omap->buf_len also overflow the message buffer.
>
The 16bit argument seems valid. But I do not get why
FIFO count could exceed buf_len.
I would expect the line
omap->threshold = clamp(size, (u8) 1, omap->fifo_size);
to guard against that. At least that seems to be the idea behind
the offending patch, which removes the checks.
If you can easily find any clear reasoning, it might
be nice to have that in the commit message.
But besides of that:
Reviewed-by: Andreas Kemnade <andreas@kemnade.info>
> Guard all omap->buf accesses and omap->buf_len decrements against a
> zero remaining length, matching omap_i2c_omap1_isr().
>
Yes, better err on the side of caution here. At least it is not totally obvious
that these checks are not needed.
> Fixes: dd74548ddece ("i2c: omap: resize fifos before each message")
> Closes: https://sashiko.dev/#/bug/linux-288ca65a-55c7-4651-8d27-2629e158106e
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
> drivers/i2c/busses/i2c-omap.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
> index 6a577db3cb64..4684e0d64cff 100644
> --- a/drivers/i2c/busses/i2c-omap.c
> +++ b/drivers/i2c/busses/i2c-omap.c
> @@ -1003,14 +1003,17 @@ static void omap_i2c_receive_data(struct omap_i2c_dev *omap, u8 num_bytes,
>
> while (num_bytes--) {
> w = omap_i2c_read_reg(omap, OMAP_I2C_DATA_REG);
> - *omap->buf++ = w;
> - omap->buf_len--;
> + if (omap->buf_len) {
> + *omap->buf++ = w;
> + omap->buf_len--;
> + }
>
> /*
> * Data reg in 2430, omap3 and
> * omap4 is 8 bit wide
> */
> - if (omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) {
> + if ((omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) &&
> + omap->buf_len) {
BTW: Dead code in next, but not in stable, so your fix is of
course needed. (of course taking the brush now is not needed)
> *omap->buf++ = w >> 8;
> omap->buf_len--;
> }
> @@ -1023,6 +1026,8 @@ static int omap_i2c_transmit_data(struct omap_i2c_dev *omap, u8 num_bytes,
> u16 w;
>
> while (num_bytes--) {
> + if (!omap->buf_len)
> + break;
> w = *omap->buf++;
> omap->buf_len--;
>
> @@ -1030,7 +1035,8 @@ static int omap_i2c_transmit_data(struct omap_i2c_dev *omap, u8 num_bytes,
> * Data reg in 2430, omap3 and
> * omap4 is 8 bit wide
> */
> - if (omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) {
> + if ((omap->flags & OMAP_I2C_FLAG_16BIT_DATA_REG) &&
> + omap->buf_len) {
Same here.
> w |= *omap->buf++ << 8;
> omap->buf_len--;
> }
next prev parent reply other threads:[~2026-12-03 22:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 18:31 [PATCH 00/10] i2c: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 18:31 ` [PATCH 01/10] i2c: imx-lpi2c: Clear rx_cmd_buf pointer after freeing in lpi2c_imx_dma_xfer() Lee Jones
2026-12-03 20:36 ` Frank Li
2026-12-03 18:31 ` [PATCH 02/10] i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer Lee Jones
2026-12-03 18:31 ` [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer() Lee Jones
2026-12-03 18:31 ` [PATCH 04/10] i2c: omap: Check buf_len before buffer accesses in data transfer helpers Lee Jones
2026-12-03 22:00 ` Andreas Kemnade [this message]
2026-12-03 18:31 ` [PATCH 05/10] i2c: stm32f7: Prevent duplicate execution of stm32f7_i2c_dma_callback() Lee Jones
2026-12-03 18:31 ` [PATCH 06/10] i2c: stm32f7: Allocate smbus_buf separately for DMA safety Lee Jones
2026-12-03 18:31 ` [PATCH 07/10] i2c: usbio: Validate full reply length in split-read loop Lee Jones
2026-12-03 18:31 ` [PATCH 08/10] i2c: amd-mp2: Synchronise IRQ completion with command timeout Lee Jones
2026-12-03 18:31 ` [PATCH 09/10] i2c: mlxbf: Reject zero-length SMBus reads to prevent stack overflow Lee Jones
2026-12-03 18:31 ` [PATCH 10/10] i2c: octeon: Guard to_pci_dev() with dev_is_pci() in octeon_i2c_set_clock() Lee Jones
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=20261203230021.17cbf5a7@kemnade.info \
--to=andreas@kemnade.info \
--cc=aaro.koskinen@iki.fi \
--cc=andi.shyti@kernel.org \
--cc=balbi@ti.com \
--cc=imre.deak@nokia.com \
--cc=jmkrzyszt@gmail.com \
--cc=juha.yrjola@solidboot.com \
--cc=khilman@baylibre.com \
--cc=lee@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=nm@ti.com \
--cc=rogerq@kernel.org \
--cc=shubhrajyoti@ti.com \
--cc=stable@vger.kernel.org \
--cc=tony@atomide.com \
--cc=vigneshr@ti.com \
--cc=wsa+renesas@sang-engineering.com \
--cc=x0khasim@ti.com \
/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
all inboxes | Powered by JetHome®