Skip to contentSkip to conversation

serial: rp2: remove ports on IRQ request failure in probe

PATCH New Jiri Slaby (SUSE) 2 participants 2 messages Nov 25

Subsystems (3)
lore
Share & tools
lore

Jiri Slaby (SUSE)

author maintainer
#0 lore raw

PATCH 1/1 serial: rp2: remove ports on IRQ request failure in probe

Since commit 016002848c82 ("serial: rp2: use 'request_firmware' instead of 'request_firmware_nowait'"), rp2_probe() loads the firmware and registers all the UART ports (via rp2_load_firmware()) before requesting the IRQ. But if devm_request_irq() fails, probe just returns the error and leaves the ports registered with the serial core.

rp2_remove() is not called for a failed probe, so the ports stay registered, pointing to a card whose devm-managed memory (card->ports included) and iomaps are freed. Any later access to the tty devices then results in a use-after-free.

Call rp2_remove_ports() when the IRQ request fails.

Fixes 016002848c82 ("serial: rp2: use 'request_firmware' instead of 'request_firmware_nowait'")
Cc Kevin Cernekee <[email protected]>
---
 drivers/tty/serial/rp2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/rp2.c +2 -2
index 158b06424b56..f82270bf7060 100644
@@ -755,9 +755,9 @@ static int rp2_probe(struct pci_dev *pdev,
 	rc = devm_request_irq(&pdev->dev, pdev->irq, rp2_uart_interrupt,
 			      IRQF_SHARED, DRV_NAME, card);
 	if (rc)
-		return rc;
+		rp2_remove_ports(card);
 
-	return 0;
+	return rc;
 }
 
 static void rp2_remove(struct pci_dev *pdev)
Signature · 1 line
2.56.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

Since commit 016002848c82 ("serial: rp2: use 'request_firmware' instead of 'request_firmware_nowait'"), rp2_probe() loads the firmware and registers all the UART ports (via rp2_load_firmware()) before requesting the IRQ. But if devm_request_irq() fails, probe just returns the error and leaves the ports registered with the serial core.

rp2_remove() is not called for a failed probe, so the ports stay registered, pointing to a card whose devm-managed memory (card->ports included) and iomaps are freed. Any later access to the tty devices then results in a use-after-free.

Quoted 5 lines

Call rp2_remove_ports() when the IRQ request fails.

Fixes 016002848c82 ("serial: rp2: use 'request_firmware' instead of 'request_firmware_nowait'")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1