Linux CAN drivers development
 help / color / mirror / Atom feed
* [PATCH] can: peak_pci: fix UAF and leak of PCIeC resources
@ 2026-11-23  9:01 b.lane130
  2026-11-23  9:09 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: b.lane130 @ 2026-11-23  9:01 UTC (permalink / raw)
  To: mkl, mailhol, s.grosjean, wg; +Cc: linux-can, Bruce Lane

From: Bruce Lane <b.lane130@outlook.com>

If register_sja1000dev() fails on the first channel in peak_pci_probe(),
failure_free_dev clears drvdata and frees dev without calling
peak_pciec_remove(), leaking the PCIeC card and leaving the I2C adapter
registered.

If probing fails on a later channel, failure_remove_channels frees all
devices in the loop and then dereferences chan->pciec_card afterwards,
causing a use-after-free. This is the same issue in commit 949fe9b35570
("can: peak_pci: peak_pci_remove(): fix UAF").

Call peak_pciec_remove() under failure_free_dev, and change the cleanup
order under failure_remove_channels.

Fixes: e6d9c80b7ca1 ("can: peak_pci: add support of some new PEAK-System PCI cards")
Signed-off-by: Bruce Lane <b.lane130@outlook.com>
---
 drivers/net/can/sja1000/peak_pci.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/sja1000/peak_pci.c b/drivers/net/can/sja1000/peak_pci.c
index 69c61ccf621d..d5f862f05480 100644
--- a/drivers/net/can/sja1000/peak_pci.c
+++ b/drivers/net/can/sja1000/peak_pci.c
@@ -697,6 +697,10 @@ static int peak_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	return 0;
 
 failure_free_dev:
+	/* free any PCIeC resources too */
+	if (!chan->prev_dev && chan->pciec_card)
+		peak_pciec_remove(chan->pciec_card);
+
 	pci_set_drvdata(pdev, chan->prev_dev);
 	free_sja1000dev(dev);
 
@@ -709,15 +713,12 @@ static int peak_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		priv = netdev_priv(dev);
 		chan = priv->priv;
 		prev_dev = chan->prev_dev;
-
+		if (!prev_dev && chan->pciec_card)
+			peak_pciec_remove(chan->pciec_card);
 		unregister_sja1000dev(dev);
 		free_sja1000dev(dev);
 	}
 
-	/* free any PCIeC resources too */
-	if (chan && chan->pciec_card)
-		peak_pciec_remove(chan->pciec_card);
-
 	pci_iounmap(pdev, reg_base);
 
 failure_unmap_cfg_base:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-23  9:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  9:01 [PATCH] can: peak_pci: fix UAF and leak of PCIeC resources b.lane130
2026-11-23  9:09 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox