[PATCH] drivers/i2c-aspeed: avoid invalid memory reference after timeout

Joel Stanley joel at jms.id.au
Tue Jan 11 02:51:22 PST 2022


On Tue, 11 Jan 2022 at 07:52, Heyi Guo <guoheyi at linux.alibaba.com> wrote:
>
> Hi all,
>
> Any comments?
>
> Thanks,
>
> Heyi
>
> 在 2022/1/9 下午9:26, Heyi Guo 写道:
> > 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.

Thanks for the patch. How did you discover this issue? Do you have a
test I can run to reproduce the crash?

Can you provide a Fixes tag?

Do other i2c master drivers do this? I took a quick look at the meson
driver and it doesn't appear to clear it's pointer to msgs.

> >
> > Signed-off-by: Heyi Guo <guoheyi at linux.alibaba.com>
> >
> > -------
> >
> > Cc: Brendan Higgins <brendanhiggins at google.com>
> > Cc: Benjamin Herrenschmidt <benh at kernel.crashing.org>
> > Cc: Joel Stanley <joel at jms.id.au>
> > Cc: Andrew Jeffery <andrew at aj.id.au>
> > Cc: Philipp Zabel <p.zabel at pengutronix.de>
> > Cc: linux-i2c at vger.kernel.org
> > Cc: openbmc at lists.ozlabs.org
> > Cc: linux-arm-kernel at lists.infradead.org
> > Cc: linux-aspeed at 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;



More information about the linux-arm-kernel mailing list