Skip to contentSkip to conversation

nfc: nxp-nci: fix IRQ use-after-free in i2c remove

PATCH In review Aldo Ariel Panzardo 2 participants 2 messages Sep 25 – Sep 30

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

PATCH 1/1 nfc: nxp-nci: fix IRQ use-after-free in i2c remove

nxp_nci_i2c_remove() calls nxp_nci_remove() before free_irq(). nxp_nci_remove() unregisters the NCI device and frees ndev via nci_free_device(). The IRQ handler nxp_nci_i2c_irq_thread_fn() dereferences phy->ndev and calls nci_get_drvdata() on it; if the interrupt fires between the nxp_nci_remove() and free_irq() calls the handler operates on freed memory.

Swap the order: disable the interrupt first with free_irq(), then tear down the device.

Fixes 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI driver")
---
 drivers/nfc/nxp-nci/i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nfc/nxp-nci/i2c.c +1 -1
index XXXXXXX..YYYYYYY 100644
@@ -346,8 +346,8 @@ static void nxp_nci_i2c_remove(struct i2c_client *client)
 {
 	struct nxp_nci_i2c_phy *phy = i2c_get_clientdata(client);
 
-	nxp_nci_remove(phy->ndev);
 	free_irq(client->irq, phy);
+	nxp_nci_remove(phy->ndev);
 }
 
 static const struct i2c_device_id nxp_nci_i2c_id_table[] = {
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Aldo Ariel Panzardo

nxp_nci_i2c_remove() calls nxp_nci_remove() before free_irq(). nxp_nci_remove() unregisters the NCI device and frees ndev via nci_free_device(). The IRQ handler nxp_nci_i2c_irq_thread_fn() dereferences phy->ndev and calls nci_get_drvdata() on it; if the interrupt fires between the nxp_nci_remove() and free_irq() calls the handler operates on freed memory.

Quoted 6 lines

Swap the order: disable the interrupt first with free_irq(), then tear down the device.

Fixes 6be88670fc59 ("NFC: nxp-nci_i2c: Add I2C support to NXP NCI driver")