Skip to contentSkip to conversation

i2c: aspeed: fixed potential null pointer dereference

PATCH Applied Brendan Higgins 3 participants 7 messages Jul 29, 2017 – Aug 14, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: aspeed: fixed potential null pointer dereference

Before I skipped null checks when the master is in the STOP state; this fixes that.

---
 drivers/i2c/busses/i2c-aspeed.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-aspeed.c +3 -2
index f19348328a71..6fdf9231c23c 100644
@@ -410,10 +410,11 @@ static bool aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus)
 	}
 
 	/* We are in an invalid state; reset bus to a known state. */
-	if (!bus->msgs && bus->master_state != ASPEED_I2C_MASTER_STOP) {
+	if (!bus->msgs) {
 		dev_err(bus->dev, "bus in unknown state");
 		bus->cmd_err = -EIO;
-		aspeed_i2c_do_stop(bus);
+		if (bus->master_state != ASPEED_I2C_MASTER_STOP)
+			aspeed_i2c_do_stop(bus);
 		goto out_no_complete;
 	}
 	msg = &bus->msgs[bus->msgs_index];
Signature · 1 line
2.14.0.rc0.400.g1c36432dff-goog
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Brendan Higgins

Before I skipped null checks when the master is in the STOP state; this fixes that.

Out of interest, was this found by code review, or did you hit this in testing?

Cheers,

Joel

Quoted 25 lines
---
 drivers/i2c/busses/i2c-aspeed.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-aspeed.c +3 -3
index f19348328a71..6fdf9231c23c 100644
@@ -410,10 +410,11 @@ static bool aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus)
        }
 
        /* We are in an invalid state; reset bus to a known state. */
-       if (!bus->msgs && bus->master_state != ASPEED_I2C_MASTER_STOP) {
+       if (!bus->msgs) {
                dev_err(bus->dev, "bus in unknown state");
                bus->cmd_err = -EIO;
-               aspeed_i2c_do_stop(bus);
+               if (bus->master_state != ASPEED_I2C_MASTER_STOP)
+                       aspeed_i2c_do_stop(bus);
                goto out_no_complete;
        }
        msg = &bus->msgs[bus->msgs_index];
--

2.14.0.rc0.400.g1c36432dff-goog

#2 lore raw
Quoted 10 lines · Joel Stanley
Quoted 4 lines · Brendan Higgins

Before I skipped null checks when the master is in the STOP state; this fixes that.

Out of interest, was this found by code review, or did you hit this in testing?

I am pretty sure we hit it in testing. Unfortunately, we had trouble reproducing it, but we did see a null pointer dereference.

Quoted 4 lines

Cheers,

Joel

maintainer
#3 lore raw

[dropping upstream cc]

Quoted 6 lines · Brendan Higgins
Quoted 5 lines · Joel Stanley
Quoted 3 lines · Brendan Higgins

Before I skipped null checks when the master is in the STOP state; this fixes that.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Out of interest, was this found by code review, or did you hit this in testing?

I am pretty sure we hit it in testing. Unfortunately, we had trouble reproducing it, but we did see a null pointer dereference.

Thanks. I've applied it to the openbmc dev-4.10 tree as well.

Cheers,

Joel

maintainer
#5 lore raw
Quoted 8 lines · Wolfram Sang
Quoted 4 lines · Brendan Higgins

Before I skipped null checks when the master is in the STOP state; this fixes that.

Is there a suitable "Fixes:" tag for this?

The driver was introduced in 4.13, so we could add:

Fixes f327c686d3ba ("i2c: aspeed: added driver for Aspeed I2C")

Cheers,

Joel