All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/i2c-aspeed: avoid invalid memory reference after timeout
@ 2022-01-09 13:26 ` Heyi Guo
  0 siblings, 0 replies; 24+ messages in thread
From: Heyi Guo @ 2022-01-09 13:26 UTC (permalink / raw)
  To: linux-kernel
  Cc: Heyi Guo, Brendan Higgins, Benjamin Herrenschmidt, Joel Stanley,
	Andrew Jeffery, Philipp Zabel, linux-i2c, openbmc,
	linux-arm-kernel, linux-aspeed

The memory will be freed by the caller if transfer timeout occurs,
then it would trigger kernel panic if the peer device responds with
something after timeout and triggers the interrupt handler of aspeed
i2c driver.

Set the msgs pointer to NULL to avoid invalid memory reference after
timeout to fix this potential kernel panic.

Signed-off-by: Heyi Guo <guoheyi@linux.alibaba.com>

-------

Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Joel Stanley <joel@jms.id.au>
Cc: Andrew Jeffery <andrew@aj.id.au>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: linux-i2c@vger.kernel.org
Cc: openbmc@lists.ozlabs.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-aspeed@lists.ozlabs.org
---
 drivers/i2c/busses/i2c-aspeed.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index 67e8b97c0c950..3ab0396168680 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -708,6 +708,11 @@ static int aspeed_i2c_master_xfer(struct i2c_adapter *adap,
 		spin_lock_irqsave(&bus->lock, flags);
 		if (bus->master_state == ASPEED_I2C_MASTER_PENDING)
 			bus->master_state = ASPEED_I2C_MASTER_INACTIVE;
+		/*
+		 * All the buffers may be freed after returning to caller, so
+		 * set msgs to NULL to avoid memory reference after freeing.
+		 */
+		bus->msgs = NULL;
 		spin_unlock_irqrestore(&bus->lock, flags);
 
 		return -ETIMEDOUT;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2022-06-01  2:01 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-09 13:26 [PATCH] drivers/i2c-aspeed: avoid invalid memory reference after timeout Heyi Guo
2022-01-09 13:26 ` Heyi Guo
2022-01-09 13:26 ` Heyi Guo
2022-01-11  7:52 ` Heyi Guo
2022-01-11  7:52   ` Heyi Guo
2022-01-11  7:52   ` Heyi Guo
2022-01-11 10:51   ` Joel Stanley
2022-01-11 10:51     ` Joel Stanley
2022-01-11 10:51     ` Joel Stanley
2022-01-14 14:01     ` Heyi Guo
2022-01-14 14:01       ` Heyi Guo
2022-01-14 14:01       ` Heyi Guo
2022-01-17  6:38       ` Joel Stanley
2022-01-17  6:38         ` Joel Stanley
2022-01-17  6:38         ` Joel Stanley
2022-01-19  2:59         ` Heyi Guo
2022-01-19  2:59           ` Heyi Guo
2022-01-19  2:59           ` Heyi Guo
2022-05-31  9:35           ` Lei Yu
2022-05-31  9:35             ` Lei Yu
2022-05-31  9:35             ` Lei Yu
2022-06-01  1:59             ` Heyi Guo
2022-06-01  1:59               ` Heyi Guo
2022-06-01  1:59               ` Heyi Guo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.