* [PATCH 01/10] i2c: imx-lpi2c: Clear rx_cmd_buf pointer after freeing in lpi2c_imx_dma_xfer()
[not found] <20261203183214.1939736-1-lee@kernel.org>
@ 2026-12-03 18:31 ` Lee Jones
2026-12-03 18:31 ` [PATCH 02/10] i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer Lee Jones
` (8 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Dong Aisheng, Andi Shyti, Frank Li, Sascha Hauer,
Pengutronix Kernel Team, Fabio Estevam, Carlos Song, Gao Pan,
linux-i2c, imx, linux-arm-kernel
Cc: linux-kernel, stable
lpi2c_imx->dma persists across transfers. On a DMA read, the
disable_dma path frees dma->rx_cmd_buf without clearing the pointer.
If a subsequent DMA read fails in lpi2c_dma_config() or
lpi2c_dma_submit() before lpi2c_imx_alloc_rx_cmd_buf() runs, the
cleanup path calls kfree(dma->rx_cmd_buf) a second time on the stale
pointer.
Reset dma->rx_cmd_buf to NULL immediately after freeing it.
Fixes: a09c8b3f9047 ("i2c: imx-lpi2c: add eDMA mode support for LPI2C")
Closes: https://sashiko.dev/#/bug/linux-17d925e1-8c99-4efb-a920-2c90ce2b53b5
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/i2c/busses/i2c-imx-lpi2c.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
index ecf2bed01b29..f911b3b7367e 100644
--- a/drivers/i2c/busses/i2c-imx-lpi2c.c
+++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
@@ -1097,8 +1097,10 @@ static int lpi2c_imx_dma_xfer(struct lpi2c_imx_struct *lpi2c_imx,
/* Disable I2C DMA function */
writel(0, lpi2c_imx->base + LPI2C_MDER);
- if (dma->dma_msg_flag & I2C_M_RD)
+ if (dma->dma_msg_flag & I2C_M_RD) {
kfree(dma->rx_cmd_buf);
+ dma->rx_cmd_buf = NULL;
+ }
if (ret)
i2c_put_dma_safe_msg_buf(dma->dma_buf, msg, false);
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 02/10] i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer
[not found] <20261203183214.1939736-1-lee@kernel.org>
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 18:31 ` 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
` (7 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Mukesh Kumar Savaliya, Viken Dadhaniya, Andi Shyti,
Sumit Semwal, Christian König, Philipp Stanner,
Roja Rani Yarubandi, Akash Asthana, Wolfram Sang, linux-i2c,
linux-arm-msm, linux-media, dri-devel, linaro-mm-sig
Cc: linux-kernel, stable
geni_i2c_rx_msg_cleanup() and geni_i2c_tx_msg_cleanup() release
gi2c->dma_buf without setting it back to NULL. If a subsequent
transfer fails geni_se_{rx,tx}_dma_prep() and falls back to FIFO mode,
gi2c->dma_buf retains the stale pointer from the previous transfer,
causing the cleanup helper to unprepare and free the buffer a second
time.
Set gi2c->dma_buf to NULL after releasing it in both cleanup functions.
Fixes: 357ee8841d0b ("i2c: qcom-geni: Store DMA mapping data in geni_i2c_dev struct")
Closes: https://sashiko.dev/#/bug/linux-d60db3da-ca85-40ac-8a6c-62b1d80be7ac
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/i2c/busses/i2c-qcom-geni.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/i2c/busses/i2c-qcom-geni.c b/drivers/i2c/busses/i2c-qcom-geni.c
index 926bc484ead2..6779719bbefa 100644
--- a/drivers/i2c/busses/i2c-qcom-geni.c
+++ b/drivers/i2c/busses/i2c-qcom-geni.c
@@ -505,6 +505,7 @@ static void geni_i2c_rx_msg_cleanup(struct geni_i2c_dev *gi2c,
geni_i2c_rx_fsm_rst(gi2c);
geni_se_rx_dma_unprep(&gi2c->se, gi2c->dma_addr, gi2c->xfer_len);
i2c_put_dma_safe_msg_buf(gi2c->dma_buf, cur, !gi2c->err);
+ gi2c->dma_buf = NULL;
}
}
@@ -517,6 +518,7 @@ static void geni_i2c_tx_msg_cleanup(struct geni_i2c_dev *gi2c,
geni_i2c_tx_fsm_rst(gi2c);
geni_se_tx_dma_unprep(&gi2c->se, gi2c->dma_addr, gi2c->xfer_len);
i2c_put_dma_safe_msg_buf(gi2c->dma_buf, cur, !gi2c->err);
+ gi2c->dma_buf = NULL;
}
}
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 03/10] i2c: sh_mobile: Terminate DMA before freeing bounce buffer in sh_mobile_xfer()
[not found] <20261203183214.1939736-1-lee@kernel.org>
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 18:31 ` [PATCH 02/10] i2c: qcom-geni: Clear dma_buf pointer after releasing DMA buffer Lee Jones
@ 2026-12-03 18:31 ` Lee Jones
2026-12-03 18:31 ` [PATCH 04/10] i2c: omap: Check buf_len before buffer accesses in data transfer helpers Lee Jones
` (6 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Wolfram Sang, Andi Shyti, Sumit Semwal, Christian König,
Philipp Stanner, Carlos Munoz, Niklas Söderlund,
linux-renesas-soc, linux-i2c, linux-media, dri-devel,
linaro-mm-sig
Cc: linux-kernel, stable
In sh_mobile_xfer(), i2c_put_dma_safe_msg_buf() is called immediately
after wait_event_timeout(), before checking for a timeout or an active
DMA transfer and calling sh_mobile_i2c_cleanup_dma(). On a timeout or
early NACK wakeup while DMA is still running, the bounce buffer is
freed while still mapped for DMA.
Select the DMA channel from the immutable message direction flag rather
than mutable pd->dma_direction, always synchronise and terminate the
channel in sh_mobile_xfer() before calling i2c_put_dma_safe_msg_buf(),
re-check pd->dma_direction after dmaengine_terminate_sync() to avoid
double unmapping, and update pd->pos, pd->stop_after_dma, and ICIC
before clearing pd->dma_direction in sh_mobile_i2c_dma_callback().
Fixes: cebc07d84ad7 ("i2c: sh_mobile: fix leak when using DMA bounce buffer")
Closes: https://sashiko.dev/#/bug/linux-af86edab-c752-40c1-9d09-2abb42f140f3
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/i2c/busses/i2c-sh_mobile.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 0d10742a8ec0..d7aa710767c7 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -445,12 +445,17 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
static void sh_mobile_i2c_cleanup_dma(struct sh_mobile_i2c_data *pd, bool terminate)
{
- struct dma_chan *chan = pd->dma_direction == DMA_FROM_DEVICE
+ struct dma_chan *chan = (pd->msg->flags & I2C_M_RD)
? pd->dma_rx : pd->dma_tx;
/* only allowed from thread context! */
- if (terminate)
+ if (terminate) {
+ if (IS_ERR_OR_NULL(chan))
+ return;
dmaengine_terminate_sync(chan);
+ if (pd->dma_direction == DMA_NONE)
+ return;
+ }
dma_unmap_single(chan->device->dev, sg_dma_address(&pd->sg),
pd->msg->len, pd->dma_direction);
@@ -462,11 +467,10 @@ static void sh_mobile_i2c_dma_callback(void *data)
{
struct sh_mobile_i2c_data *pd = data;
- sh_mobile_i2c_cleanup_dma(pd, false);
pd->pos = pd->msg->len;
pd->stop_after_dma = true;
-
iic_set_clr(pd, ICIC, 0, ICIC_TDMAE | ICIC_RDMAE);
+ sh_mobile_i2c_cleanup_dma(pd, false);
}
static struct dma_chan *sh_mobile_i2c_request_dma_chan(struct device *dev,
@@ -682,15 +686,15 @@ static int sh_mobile_xfer(struct sh_mobile_i2c_data *pd,
pd->sr & (ICSR_TACK | SW_DONE),
pd->adap.timeout);
+ if (pd->dma_buf)
+ sh_mobile_i2c_cleanup_dma(pd, true);
+
/* 'stop_after_dma' tells if DMA xfer was complete */
i2c_put_dma_safe_msg_buf(pd->dma_buf, pd->msg,
pd->stop_after_dma);
}
if (!time_left) {
- if (pd->dma_direction != DMA_NONE)
- sh_mobile_i2c_cleanup_dma(pd, true);
-
err = -ETIMEDOUT;
break;
}
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 04/10] i2c: omap: Check buf_len before buffer accesses in data transfer helpers
[not found] <20261203183214.1939736-1-lee@kernel.org>
` (2 preceding siblings ...)
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 ` Lee Jones
2026-12-03 18:31 ` [PATCH 05/10] i2c: stm32f7: Prevent duplicate execution of stm32f7_i2c_dma_callback() Lee Jones
` (5 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Vignesh R, Aaro Koskinen, Andreas Kemnade, Kevin Hilman,
Roger Quadros, Tony Lindgren, Janusz Krzysztofik, Andi Shyti,
Imre Deak, Juha Yrjola, Syed Khasim, Nishant Menon, Wolfram Sang,
Shubhrajyoti D, Felipe Balbi, linux-omap, linux-i2c
Cc: linux-kernel, stable
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
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 05/10] i2c: stm32f7: Prevent duplicate execution of stm32f7_i2c_dma_callback()
[not found] <20261203183214.1939736-1-lee@kernel.org>
` (3 preceding siblings ...)
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 18:31 ` Lee Jones
2026-12-03 18:31 ` [PATCH 06/10] i2c: stm32f7: Allocate smbus_buf separately for DMA safety Lee Jones
` (4 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Pierre-Yves MORDRET, Alain Volmat, Andi Shyti,
Maxime Coquelin, Alexandre Torgue, Cedric Madianga,
Clément Le Goffic, linux-i2c, linux-stm32, linux-arm-kernel
Cc: linux-kernel, stable
stm32f7_i2c_dma_callback() can be invoked both by the DMA engine upon
transfer completion and directly by the threaded IRQ handler on NACK,
error, or timeout conditions. When these race, dma_unmap_single() and
i2c_put_dma_safe_msg_buf() execute twice on the same buffer, causing
double DMA unmap and double free.
Guard stm32f7_i2c_dma_callback() with an atomic dma_cleanup_pending
flag so cleanup runs at most once per prepared DMA transfer, and route
threaded IRQ error/timeout paths through a helper that calls
dmaengine_terminate_sync() first so any in-flight DMA callback has
completed before proceeding or advancing to the next message.
Fixes: 6aae87fe7f18 ("i2c: stm32f7: unmap DMA mapped buffer")
Closes: https://sashiko.dev/#/bug/linux-ec58601d-83aa-4888-8bad-aa0356a7ae85
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/i2c/busses/i2c-stm32f7.c | 35 +++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 2e1cc6a92b81..1ebb2e0bc1b0 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -14,6 +14,7 @@
* This driver is based on i2c-stm32f4.c
*
*/
+#include <linux/atomic.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/err.h>
@@ -320,6 +321,7 @@ struct stm32f7_i2c_alert {
* slave)
* @dma: dma data
* @use_dma: boolean to know if dma is used in the current transfer
+ * @dma_cleanup_pending: tracks whether a DMA transfer awaits cleanup
* @regmap: holds SYSCFG phandle for Fast Mode Plus bits
* @fmp_sreg: register address for setting Fast Mode Plus bits
* @fmp_creg: register address for clearing Fast Mode Plus bits
@@ -353,6 +355,7 @@ struct stm32f7_i2c_dev {
bool master_mode;
struct stm32_i2c_dma *dma;
bool use_dma;
+ atomic_t dma_cleanup_pending;
struct regmap *regmap;
u32 fmp_sreg;
u32 fmp_creg;
@@ -735,6 +738,9 @@ static void stm32f7_i2c_dma_callback(void *arg)
struct stm32_i2c_dma *dma = i2c_dev->dma;
struct stm32f7_i2c_msg *f7_msg = &i2c_dev->f7_msg;
+ if (!atomic_xchg(&i2c_dev->dma_cleanup_pending, 0))
+ return;
+
stm32f7_i2c_disable_dma_req(i2c_dev);
dmaengine_terminate_async(dma->chan_using);
dma_unmap_single(i2c_dev->dev, dma->dma_buf, dma->dma_len,
@@ -744,6 +750,12 @@ static void stm32f7_i2c_dma_callback(void *arg)
complete(&dma->dma_complete);
}
+static void stm32f7_i2c_dma_abort(struct stm32f7_i2c_dev *i2c_dev)
+{
+ dmaengine_terminate_sync(i2c_dev->dma->chan_using);
+ stm32f7_i2c_dma_callback(i2c_dev);
+}
+
static void stm32f7_i2c_hw_config(struct stm32f7_i2c_dev *i2c_dev)
{
struct stm32f7_i2c_timings *t = &i2c_dev->timing;
@@ -928,12 +940,14 @@ static void stm32f7_i2c_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
dma_buf = i2c_get_dma_safe_msg_buf(msg, STM32F7_I2C_DMA_LEN_MIN);
if (dma_buf) {
f7_msg->buf = dma_buf;
+ atomic_set(&i2c_dev->dma_cleanup_pending, 1);
ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma,
msg->flags & I2C_M_RD,
f7_msg->count, f7_msg->buf,
stm32f7_i2c_dma_callback,
i2c_dev);
if (ret) {
+ atomic_set(&i2c_dev->dma_cleanup_pending, 0);
dev_warn(i2c_dev->dev, "can't use DMA\n");
i2c_put_dma_safe_msg_buf(f7_msg->buf, msg, false);
f7_msg->buf = msg->buf;
@@ -1102,15 +1116,18 @@ static int stm32f7_i2c_smbus_xfer_msg(struct stm32f7_i2c_dev *i2c_dev,
/* Configure DMA or enable RX/TX interrupt */
i2c_dev->use_dma = false;
if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN) {
+ atomic_set(&i2c_dev->dma_cleanup_pending, 1);
ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma,
cr2 & STM32F7_I2C_CR2_RD_WRN,
f7_msg->count, f7_msg->buf,
stm32f7_i2c_dma_callback,
i2c_dev);
- if (!ret)
+ if (!ret) {
i2c_dev->use_dma = true;
- else
+ } else {
+ atomic_set(&i2c_dev->dma_cleanup_pending, 0);
dev_warn(i2c_dev->dev, "can't use DMA\n");
+ }
}
if (!i2c_dev->use_dma) {
@@ -1196,16 +1213,19 @@ static void stm32f7_i2c_smbus_rep_start(struct stm32f7_i2c_dev *i2c_dev)
if (i2c_dev->dma && f7_msg->count >= STM32F7_I2C_DMA_LEN_MIN &&
f7_msg->size != I2C_SMBUS_BLOCK_DATA &&
f7_msg->size != I2C_SMBUS_BLOCK_PROC_CALL) {
+ atomic_set(&i2c_dev->dma_cleanup_pending, 1);
ret = stm32_i2c_prep_dma_xfer(i2c_dev->dev, i2c_dev->dma,
cr2 & STM32F7_I2C_CR2_RD_WRN,
f7_msg->count, f7_msg->buf,
stm32f7_i2c_dma_callback,
i2c_dev);
- if (!ret)
+ if (!ret) {
i2c_dev->use_dma = true;
- else
+ } else {
+ atomic_set(&i2c_dev->dma_cleanup_pending, 0);
dev_warn(i2c_dev->dev, "can't use DMA\n");
+ }
}
if (!i2c_dev->use_dma)
@@ -1552,7 +1572,7 @@ static irqreturn_t stm32f7_i2c_handle_isr_errs(struct stm32f7_i2c_dev *i2c_dev,
/* Disable dma */
if (i2c_dev->use_dma)
- stm32f7_i2c_dma_callback(i2c_dev);
+ stm32f7_i2c_dma_abort(i2c_dev);
i2c_dev->master_mode = false;
complete(&i2c_dev->complete);
@@ -1617,7 +1637,7 @@ static irqreturn_t stm32f7_i2c_isr_event_thread(int irq, void *data)
__func__, f7_msg->addr);
writel_relaxed(STM32F7_I2C_ICR_NACKCF, base + STM32F7_I2C_ICR);
if (i2c_dev->use_dma)
- stm32f7_i2c_dma_callback(i2c_dev);
+ stm32f7_i2c_dma_abort(i2c_dev);
f7_msg->result = -ENXIO;
}
@@ -1635,8 +1655,9 @@ static irqreturn_t stm32f7_i2c_isr_event_thread(int irq, void *data)
ret = wait_for_completion_timeout(&i2c_dev->dma->dma_complete, HZ);
if (!ret) {
dev_dbg(i2c_dev->dev, "<%s>: Timed out\n", __func__);
- stm32f7_i2c_dma_callback(i2c_dev);
+ stm32f7_i2c_dma_abort(i2c_dev);
f7_msg->result = -ETIMEDOUT;
+ f7_msg->stop = true;
}
}
if (f7_msg->stop) {
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 06/10] i2c: stm32f7: Allocate smbus_buf separately for DMA safety
[not found] <20261203183214.1939736-1-lee@kernel.org>
` (4 preceding siblings ...)
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 ` Lee Jones
2026-12-03 18:31 ` [PATCH 07/10] i2c: usbio: Validate full reply length in split-read loop Lee Jones
` (3 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Pierre-Yves MORDRET, Alain Volmat, Andi Shyti,
Maxime Coquelin, Alexandre Torgue, Cedric Madianga, Wolfram Sang,
linux-i2c, linux-stm32, linux-arm-kernel
Cc: linux-kernel, stable
smbus_buf is embedded directly inside struct stm32f7_i2c_msg (and thus
struct stm32f7_i2c_dev), sharing a CPU cacheline with adjacent driver
state. Passing it to dma_map_single() on non-coherent ARM/ARM64 SoCs
can corrupt adjacent fields during cache invalidation or corrupt DMA
data via concurrent CPU writes.
Allocate smbus_buf separately with devm_kzalloc() during probe so it is
isolated in its own DMA-safe allocation.
Fixes: 7ecc8cfde553 ("i2c: i2c-stm32f7: Add DMA support")
Closes: https://sashiko.dev/#/bug/linux-0de0fdd3-8e61-4777-a456-ad4761a2207c
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/i2c/busses/i2c-stm32f7.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-stm32f7.c b/drivers/i2c/busses/i2c-stm32f7.c
index 1ebb2e0bc1b0..720e1d46da09 100644
--- a/drivers/i2c/busses/i2c-stm32f7.c
+++ b/drivers/i2c/busses/i2c-stm32f7.c
@@ -285,7 +285,7 @@ struct stm32f7_i2c_msg {
bool smbus;
int size;
char read_write;
- u8 smbus_buf[I2C_SMBUS_BLOCK_MAX + 3] __aligned(4);
+ u8 *smbus_buf;
};
/**
@@ -2186,6 +2186,12 @@ static int stm32f7_i2c_probe(struct platform_device *pdev)
if (!i2c_dev)
return -ENOMEM;
+ i2c_dev->f7_msg.smbus_buf = devm_kzalloc(&pdev->dev,
+ I2C_SMBUS_BLOCK_MAX + 3,
+ GFP_KERNEL);
+ if (!i2c_dev->f7_msg.smbus_buf)
+ return -ENOMEM;
+
setup = of_device_get_match_data(&pdev->dev);
if (!setup)
return dev_err_probe(&pdev->dev, -ENODEV, "Can't get device data\n");
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 07/10] i2c: usbio: Validate full reply length in split-read loop
[not found] <20261203183214.1939736-1-lee@kernel.org>
` (5 preceding siblings ...)
2026-12-03 18:31 ` [PATCH 06/10] i2c: stm32f7: Allocate smbus_buf separately for DMA safety Lee Jones
@ 2026-12-03 18:31 ` Lee Jones
2026-12-03 18:31 ` [PATCH 08/10] i2c: amd-mp2: Synchronise IRQ completion with command timeout Lee Jones
` (2 subsequent siblings)
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Israel Cepeda, Hans de Goede, Sakari Ailus, Andi Shyti,
Greg Kroah-Hartman, Wolfram Sang, linux-i2c
Cc: linux-kernel, stable
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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
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
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 08/10] i2c: amd-mp2: Synchronise IRQ completion with command timeout
[not found] <20261203183214.1939736-1-lee@kernel.org>
` (6 preceding siblings ...)
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 ` 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
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Elie Morisse, Shyam Sundar S K, Andi Shyti,
Bakulchandra Shah, Wolfram Sang, linux-i2c
Cc: linux-kernel, stable
On transfer timeout, amd_mp2_rw_timeout() resets i2c_common->reqcmd to
i2c_none without synchronising against amd_mp2_irq_isr() or clearing
i2c_common->msg. A delayed interrupt then invokes
i2c_amd_cmd_completion(), which dereferences the freed
i2c_common->msg->buf in dev_dbg() and unconditionally calls complete(),
prematurely waking a subsequent transfer.
Protect command state transitions and IRQ completion dispatch with a
spinlock, ignore interrupts when reqcmd is i2c_none, clear
i2c_common->msg when a command ends, and drop the racy msg->buf
dev_dbg() from i2c_amd_cmd_completion().
Fixes: 529766e0a011 ("i2c: Add drivers for the AMD PCIe MP2 I2C controller")
Closes: https://sashiko.dev/#/bug/linux-e7a691b1-b6dc-40c3-9444-f514df014d30
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/i2c/busses/i2c-amd-mp2-pci.c | 29 +++++++++++++++++++++------
drivers/i2c/busses/i2c-amd-mp2-plat.c | 5 -----
drivers/i2c/busses/i2c-amd-mp2.h | 3 +++
3 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
index cc24a4f648fa..495a131dcfc3 100644
--- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
+++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
@@ -43,13 +43,15 @@ static int amd_mp2_cmd(struct amd_i2c_common *i2c_common,
union i2c_cmd_base i2c_cmd_base)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
+ unsigned long flags;
void __iomem *reg;
- i2c_common->reqcmd = i2c_cmd_base.s.i2c_cmd;
-
reg = privdata->mmio + ((i2c_cmd_base.s.bus_id == 1) ?
AMD_C2P_MSG1 : AMD_C2P_MSG0);
+ spin_lock_irqsave(&privdata->lock, flags);
+ i2c_common->reqcmd = i2c_cmd_base.s.i2c_cmd;
writel(i2c_cmd_base.ul, reg);
+ spin_unlock_irqrestore(&privdata->lock, flags);
return 0;
}
@@ -184,6 +186,7 @@ void amd_mp2_process_event(struct amd_i2c_common *i2c_common)
{
struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
struct pci_dev *pdev = privdata->pci_dev;
+ unsigned long flags;
if (unlikely(i2c_common->reqcmd == i2c_none)) {
pci_warn(pdev, "received msg but no cmd was sent (bus = %d)!\n",
@@ -193,7 +196,10 @@ void amd_mp2_process_event(struct amd_i2c_common *i2c_common)
__amd_mp2_process_event(i2c_common);
+ spin_lock_irqsave(&privdata->lock, flags);
i2c_common->reqcmd = i2c_none;
+ i2c_common->msg = NULL;
+ spin_unlock_irqrestore(&privdata->lock, flags);
amd_mp2_c2p_mutex_unlock(i2c_common);
}
EXPORT_SYMBOL_GPL(amd_mp2_process_event);
@@ -203,6 +209,7 @@ static irqreturn_t amd_mp2_irq_isr(int irq, void *dev)
struct amd_mp2_dev *privdata = dev;
struct pci_dev *pdev = privdata->pci_dev;
struct amd_i2c_common *i2c_common;
+ unsigned long flags;
u32 val;
unsigned int bus_id;
void __iomem *reg;
@@ -215,15 +222,19 @@ static irqreturn_t amd_mp2_irq_isr(int irq, void *dev)
reg = privdata->mmio + ((bus_id == 0) ?
AMD_P2C_MSG1 : AMD_P2C_MSG2);
+ spin_lock_irqsave(&privdata->lock, flags);
val = readl(reg);
if (val != 0) {
writel(0, reg);
writel(0, privdata->mmio + AMD_P2C_MSG_INTEN);
- i2c_common->eventval.ul = val;
- i2c_common->cmd_completion(i2c_common);
+ if (i2c_common->reqcmd != i2c_none) {
+ i2c_common->eventval.ul = val;
+ i2c_common->cmd_completion(i2c_common);
+ }
ret = IRQ_HANDLED;
}
+ spin_unlock_irqrestore(&privdata->lock, flags);
}
if (ret != IRQ_HANDLED) {
@@ -240,7 +251,13 @@ static irqreturn_t amd_mp2_irq_isr(int irq, void *dev)
void amd_mp2_rw_timeout(struct amd_i2c_common *i2c_common)
{
+ struct amd_mp2_dev *privdata = i2c_common->mp2_dev;
+ unsigned long flags;
+
+ spin_lock_irqsave(&privdata->lock, flags);
i2c_common->reqcmd = i2c_none;
+ i2c_common->msg = NULL;
+ spin_unlock_irqrestore(&privdata->lock, flags);
amd_mp2_c2p_mutex_unlock(i2c_common);
}
EXPORT_SYMBOL_GPL(amd_mp2_rw_timeout);
@@ -350,12 +367,12 @@ static int amd_mp2_pci_probe(struct pci_dev *pci_dev,
return -ENOMEM;
privdata->pci_dev = pci_dev;
+ mutex_init(&privdata->c2p_lock);
+ spin_lock_init(&privdata->lock);
rc = amd_mp2_pci_init(privdata, pci_dev);
if (rc)
return rc;
- mutex_init(&privdata->c2p_lock);
-
pm_runtime_set_autosuspend_delay(&pci_dev->dev, 1000);
pm_runtime_use_autosuspend(&pci_dev->dev);
pm_runtime_put_autosuspend(&pci_dev->dev);
diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c b/drivers/i2c/busses/i2c-amd-mp2-plat.c
index 6fa369be3981..9d4f8d0cb15b 100644
--- a/drivers/i2c/busses/i2c-amd-mp2-plat.c
+++ b/drivers/i2c/busses/i2c-amd-mp2-plat.c
@@ -85,11 +85,6 @@ static void i2c_amd_start_cmd(struct amd_i2c_dev *i2c_dev)
static void i2c_amd_cmd_completion(struct amd_i2c_common *i2c_common)
{
struct amd_i2c_dev *i2c_dev = amd_i2c_dev_common(i2c_common);
- union i2c_event *event = &i2c_common->eventval;
-
- if (event->r.status == i2c_readcomplete_event)
- dev_dbg(&i2c_dev->pdev->dev, "readdata:%*ph\n", event->r.length,
- i2c_common->msg->buf);
complete(&i2c_dev->cmd_complete);
}
diff --git a/drivers/i2c/busses/i2c-amd-mp2.h b/drivers/i2c/busses/i2c-amd-mp2.h
index 9b7e9494dd12..d883606be3cf 100644
--- a/drivers/i2c/busses/i2c-amd-mp2.h
+++ b/drivers/i2c/busses/i2c-amd-mp2.h
@@ -12,6 +12,7 @@
#include <linux/i2c.h>
#include <linux/pci.h>
#include <linux/pm_runtime.h>
+#include <linux/spinlock.h>
#define PCI_DEVICE_ID_AMD_MP2 0x15E6
@@ -174,6 +175,7 @@ struct amd_i2c_common {
* @mmio: iommapped registers
* @c2p_lock: controls access to the C2P mailbox shared between
* the two adapters
+ * @lock: protects command state against concurrent IRQ handling
* @c2p_lock_busid: id of the adapter which locked c2p_lock
*/
struct amd_mp2_dev {
@@ -181,6 +183,7 @@ struct amd_mp2_dev {
struct amd_i2c_common *busses[2];
void __iomem *mmio;
struct mutex c2p_lock;
+ spinlock_t lock; /* protects command state against IRQ handling */
u8 c2p_lock_busid;
unsigned int probed;
int dev_irq;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 09/10] i2c: mlxbf: Reject zero-length SMBus reads to prevent stack overflow
[not found] <20261203183214.1939736-1-lee@kernel.org>
` (7 preceding siblings ...)
2026-12-03 18:31 ` [PATCH 08/10] i2c: amd-mp2: Synchronise IRQ completion with command timeout Lee Jones
@ 2026-12-03 18:31 ` 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
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Khalil Blaiech, Asmaa Mnebhi, Andi Shyti, Vadim Pasternak,
Wolfram Sang, linux-i2c
Cc: linux-kernel, stable
For I2C_SMBUS_QUICK with read set, mlxbf_i2c_smbus_quick_command()
sets operation->length to 0 and leaves operation->buffer NULL while
setting MLXBF_I2C_F_READ. In mlxbf_i2c_smbus_start_transaction(),
subtracting 1 from the 8-bit length underflows read_len to 255,
overflowing the 128-byte data_desc stack buffer and dereferencing NULL
in memcpy().
Reject I2C_SMBUS_QUICK reads with -EOPNOTSUPP in mlxbf_i2c_smbus_xfer()
and validate operation->length and operation->buffer in
mlxbf_i2c_smbus_start_transaction() before computing read_len.
Fixes: b5b5b32081cd ("i2c: mlxbf: I2C SMBus driver for Mellanox BlueField SoC")
Closes: https://sashiko.dev/#/bug/linux-9d901144-2e2e-4106-9c52-4e02d97fca08
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/i2c/busses/i2c-mlxbf.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/i2c/busses/i2c-mlxbf.c b/drivers/i2c/busses/i2c-mlxbf.c
index 432d9588f32d..e85345906c76 100644
--- a/drivers/i2c/busses/i2c-mlxbf.c
+++ b/drivers/i2c/busses/i2c-mlxbf.c
@@ -772,6 +772,12 @@ mlxbf_i2c_smbus_start_transaction(struct mlxbf_i2c_priv *priv,
* than once?
*/
if (flags & MLXBF_I2C_F_READ) {
+ if (!operation->length ||
+ operation->length > MLXBF_I2C_MASTER_DATA_DESC_SIZE ||
+ !operation->buffer) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
read_en = 1;
/* Subtract 1 as required by HW. */
read_len = operation->length - 1;
@@ -2038,6 +2044,8 @@ static s32 mlxbf_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr,
switch (size) {
case I2C_SMBUS_QUICK:
+ if (read)
+ return -EOPNOTSUPP;
mlxbf_i2c_smbus_quick_command(&request, read);
dev_dbg(&adap->dev, "smbus quick, slave 0x%02x\n", addr);
break;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 10/10] i2c: octeon: Guard to_pci_dev() with dev_is_pci() in octeon_i2c_set_clock()
[not found] <20261203183214.1939736-1-lee@kernel.org>
` (8 preceding siblings ...)
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 ` Lee Jones
9 siblings, 0 replies; 10+ messages in thread
From: Lee Jones @ 2026-12-03 18:31 UTC (permalink / raw)
To: lee, Robert Richter, Andi Shyti, Siemens Networks,
Piyush Malgujar, Suneel Garapati, linux-i2c
Cc: linux-kernel, stable
octeon_i2c_set_clock() unconditionally passes i2c->dev to to_pci_dev()
and inspects pdev->subsystem_device. When invoked from the OCTEON
platform driver, i2c->dev belongs to a struct platform_device rather
than a struct pci_dev, resulting in an out-of-bounds slab read.
Check dev_is_pci(i2c->dev) before calling to_pci_dev().
Fixes: 114c69f4be3f ("i2c: thunderx: Clock divisor logic changes")
Closes: https://sashiko.dev/#/bug/linux-b92a3410-8945-4cb5-b326-12bdf64a66f5
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/i2c/busses/i2c-octeon-core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-octeon-core.c
index 93a49e4637ec..206476007351 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -833,7 +833,8 @@ void octeon_i2c_set_clock(struct octeon_i2c *i2c)
unsigned int thp, mdiv_min, mdiv = 2, ndiv = 0, ds = 10;
unsigned int delta_hz = INITIAL_DELTA_HZ;
- is_plat_otx2 = octeon_i2c_is_otx2(to_pci_dev(i2c->dev));
+ is_plat_otx2 = dev_is_pci(i2c->dev) &&
+ octeon_i2c_is_otx2(to_pci_dev(i2c->dev));
if (is_plat_otx2) {
thp = TWSI_MASTER_CLK_REG_OTX2_VAL;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 10+ messages in thread