nfc: nxp-nci: fix IRQ use-after-free in i2c remove
Subsystems (5)
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.
--- drivers/nfc/nxp-nci/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nfc/nxp-nci/i2c.c +1 -1
@@ -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[] = {
Quoted 7 lines · Aldo Ariel Panzardo
nxp_nci_i2c_remove()callsnxp_nci_remove()beforefree_irq().nxp_nci_remove()unregisters the NCI device and frees ndev vianci_free_device(). The IRQ handlernxp_nci_i2c_irq_thread_fn()dereferencesphy->ndevand callsnci_get_drvdata()on it; if the interrupt fires between thenxp_nci_remove()andfree_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")Signed-off-by Aldo Ariel Panzardo <[email protected]>