Skip to contentSkip to conversation

i2c: i801: Don't generate an interrupt on bus reset

PATCH Applied Jean Delvare 3 participants 3 messages May 25, 2021 – May 27, 2021

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

PATCH 1/1 i2c: i801: Don't generate an interrupt on bus reset

Now that the i2c-i801 driver supports interrupts, setting the KILL bit in a attempt to recover from a timed out transaction triggers an interrupt. Unfortunately, the interrupt handler (i801_isr) is not prepared for this situation and will try to process the interrupt as if it was signaling the end of a successful transaction. In the case of a block transaction, this can result in an out-of-range memory access.

This condition was reproduced several times by syzbot:
https://syzkaller.appspot.com/bug?extid=ed71512d469895b5b34e
https://syzkaller.appspot.com/bug?extid=8c8dedc0ba9e03f6c79e
https://syzkaller.appspot.com/bug?extid=c8ff0b6d6c73d81b610e
https://syzkaller.appspot.com/bug?extid=33f6c360821c399d69eb
https://syzkaller.appspot.com/bug?extid=be15dc0b1933f04b043a
https://syzkaller.appspot.com/bug?extid=b4d3fd1dfd53e90afd79

So disable interrupts while trying to reset the bus. Interrupts will be enabled again for the following transaction.

Fixes 636752bcb517 ("i2c-i801: Enable IRQ for SMBus transactions")
Reported-by [email protected]
Cc Jarkko Nikula <[email protected]>
---
 drivers/i2c/busses/i2c-i801.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-i801.c +2 -4
@@ -401,11 +401,9 @@ static int i801_check_post(struct i801_p
 		dev_err(&priv->pci_dev->dev, "Transaction timeout\n");
 		/* try to stop the current command */
 		dev_dbg(&priv->pci_dev->dev, "Terminating the current operation\n");
-		outb_p(inb_p(SMBHSTCNT(priv)) | SMBHSTCNT_KILL,
-		       SMBHSTCNT(priv));
+		outb_p(SMBHSTCNT_KILL, SMBHSTCNT(priv));
 		usleep_range(1000, 2000);
-		outb_p(inb_p(SMBHSTCNT(priv)) & (~SMBHSTCNT_KILL),
-		       SMBHSTCNT(priv));
+		outb_p(0, SMBHSTCNT(priv));
 
 		/* Check if it worked */
 		status = inb_p(SMBHSTSTS(priv));
Signature · 2 lines
Jean Delvare
SUSE L3 Support
Tested-by on v1 1/1
#1 lore raw

Hi

Quoted 19 lines · Jean Delvare

Now that the i2c-i801 driver supports interrupts, setting the KILL bit in a attempt to recover from a timed out transaction triggers an interrupt. Unfortunately, the interrupt handler (i801_isr) is not prepared for this situation and will try to process the interrupt as if it was signaling the end of a successful transaction. In the case of a block transaction, this can result in an out-of-range memory access.

This condition was reproduced several times by syzbot:
https://syzkaller.appspot.com/bug?extid=ed71512d469895b5b34e
https://syzkaller.appspot.com/bug?extid=8c8dedc0ba9e03f6c79e
https://syzkaller.appspot.com/bug?extid=c8ff0b6d6c73d81b610e
https://syzkaller.appspot.com/bug?extid=33f6c360821c399d69eb
https://syzkaller.appspot.com/bug?extid=be15dc0b1933f04b043a
https://syzkaller.appspot.com/bug?extid=b4d3fd1dfd53e90afd79

So disable interrupts while trying to reset the bus. Interrupts will be enabled again for the following transaction.

Quoted 9 lines
Fixes 636752bcb517 ("i2c-i801: Enable IRQ for SMBus transactions")
Reported-by [email protected]
Cc Jarkko Nikula <[email protected]>
---
  drivers/i2c/busses/i2c-i801.c |    6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)

I hope I managed to test this properly. At least I was able to trigger KASAN quite easily and after your patch not anymore.

My test was to run "i2cdump -y 0 0x50 i" a few times with this hack:

drivers/i2c/busses/i2c-i801.c +5 -2
@@ -653,6 +653,7 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
 	struct i801_priv *priv = dev_id;
 	u16 pcists;
 	u8 status;
+	static int count = 0;
 
 	/* Confirm this is our interrupt */
 	pci_read_config_word(priv->pci_dev, SMBPCISTS, &pcists);
@@ -676,8 +677,10 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
 	status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS;
 	if (status) {
 		outb_p(status, SMBHSTSTS(priv));
-		priv->status = status;
-		wake_up(&priv->waitq);
+		if ((count++ % 10)) {
+				priv->status = status;
+				wake_up(&priv->waitq);
+		}
 	}
 
 	return IRQ_HANDLED;
Applied
#2 lore raw
In reply to Jean Delvare
Quoted 16 lines · Jean Delvare

Now that the i2c-i801 driver supports interrupts, setting the KILL bit in a attempt to recover from a timed out transaction triggers an interrupt. Unfortunately, the interrupt handler (i801_isr) is not prepared for this situation and will try to process the interrupt as if it was signaling the end of a successful transaction. In the case of a block transaction, this can result in an out-of-range memory access.

This condition was reproduced several times by syzbot:
https://syzkaller.appspot.com/bug?extid=ed71512d469895b5b34e
https://syzkaller.appspot.com/bug?extid=8c8dedc0ba9e03f6c79e
https://syzkaller.appspot.com/bug?extid=c8ff0b6d6c73d81b610e
https://syzkaller.appspot.com/bug?extid=33f6c360821c399d69eb
https://syzkaller.appspot.com/bug?extid=be15dc0b1933f04b043a
https://syzkaller.appspot.com/bug?extid=b4d3fd1dfd53e90afd79

Quoted 8 lines

So disable interrupts while trying to reset the bus. Interrupts will be enabled again for the following transaction.

Fixes 636752bcb517 ("i2c-i801: Enable IRQ for SMBus transactions")
Reported-by [email protected]
Cc Jarkko Nikula <[email protected]>

Applied to for-current, thanks!