From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Vignesh R <vigneshr@ti.com>,
Aaro Koskinen <aaro.koskinen@iki.fi>,
Andreas Kemnade <andreas@kemnade.info>,
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
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 04/10] i2c: omap: Check buf_len before buffer accesses in data transfer helpers
Date: Thu, 3 Dec 2026 18:31:08 +0000 [thread overview]
Message-ID: <20261203183214.1939736-5-lee@kernel.org> (raw)
In-Reply-To: <20261203183214.1939736-1-lee@kernel.org>
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.
Guard all omap->buf accesses and omap->buf_len decrements against a
zero remaining length, matching omap_i2c_omap1_isr().
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) {
*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) {
w |= *omap->buf++ << 8;
omap->buf_len--;
}
--
2.56.1.911.g883d8bcb20-goog
prev parent reply other threads:[~2026-12-03 18:32 UTC|newest]
Thread overview: 2+ 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 ` Lee Jones [this message]
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=20261203183214.1939736-5-lee@kernel.org \
--to=lee@kernel.org \
--cc=aaro.koskinen@iki.fi \
--cc=andi.shyti@kernel.org \
--cc=andreas@kemnade.info \
--cc=balbi@ti.com \
--cc=imre.deak@nokia.com \
--cc=jmkrzyszt@gmail.com \
--cc=juha.yrjola@solidboot.com \
--cc=khilman@baylibre.com \
--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