net: sgi: ioc3-eth: two teardown fixes
Subsystems (5)
cover net: sgi: ioc3-eth: two teardown fixes
Two teardown fixes for ioc3-eth: probe never stores the net_device that remove fetches, and the shared IRQ outlives free_netdev().
Tested on an SGI Fuel.
Imre Kaloz (2):
net: sgi: ioc3-eth: set platform drvdata in probe
net: sgi: ioc3-eth: fix IRQ lifetime against netdev teardown
drivers/net/ethernet/sgi/ioc3-eth.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4
Signature · 1 line
2.47.3
PATCH 1/2 net: sgi: ioc3-eth: set platform drvdata in probe
ioc3eth_remove() fetches the net_device with platform_get_drvdata(), but probe never stores it, so unbinding the device oopses in unregister_netdev().
Reproduced and tested on an SGI Fuel.
--- drivers/net/ethernet/sgi/ioc3-eth.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/sgi/ioc3-eth.c +1 -0
@@ -848,6 +848,7 @@ static int ioc3eth_probe(struct platform_device *pdev)return -ENOMEM ;SET_NETDEV_DEV (dev, &pdev->dev); +platform_set_drvdata (pdev, dev); ip =netdev_priv (dev); ip->dma_dev = pdev->dev.parent;
Signature · 1 line
2.47.3
PATCH 2/2 net: sgi: ioc3-eth: fix IRQ lifetime against netdev teardown
In reply to Imre KalozThe shared IRQ is requested before the lock and timer its handler uses are initialized, and stays registered past free_netdev() on the probe error paths and in remove, so the handler can run on freed memory.
Reproduced with CONFIG_DEBUG_SHIRQ=y and slub_debug=P and tested on an SGI Fuel.
--- drivers/net/ethernet/sgi/ioc3-eth.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/ethernet/sgi/ioc3-eth.c +7 -5
@@ -870,16 +870,16 @@ static int ioc3eth_probe(struct platform_device *pdev) goto out_free; } -if (devm_request_irq (&pdev->dev, dev->irq, ioc3_interrupt, -IRQF_SHARED ,"ioc3-eth" , dev)) { +spin_lock_init (&ip->ioc3_lock); +timer_setup (&ip->ioc3_timer, ioc3_timer,0 ); + +if (request_irq (dev->irq, ioc3_interrupt,IRQF_SHARED ,"ioc3-eth" , + dev)) {dev_err (&pdev->dev,"Can't get irq %d\n" , dev->irq); err = -ENODEV ; goto out_free; } -spin_lock_init (&ip->ioc3_lock); -timer_setup (&ip->ioc3_timer, ioc3_timer,0 ); -ioc3_stop (ip);/* Allocate rx ring. 4kb = 512 entries, must be 4kb aligned */
@@ -951,6 +951,7 @@ static int ioc3eth_probe(struct platform_device *pdev)return 0 ; out_stop: +free_irq (dev->irq, dev);timer_delete_sync (&ip->ioc3_timer);if (ip->rxr) dma_free_coherent(ip->dma_dev, RX_RING_SIZE, ip->rxr,
@@ -969,6 +970,7 @@ static void ioc3eth_remove(struct platform_device *pdev)struct ioc3_private *ip =netdev_priv (dev);unregister_netdev (dev); +free_irq (dev->irq, dev);timer_delete_sync (&ip->ioc3_timer);dma_free_coherent (ip->dma_dev,RX_RING_SIZE , ip->rxr, ip->rxr_dma);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH net 2/2] net: sgi: ioc3-eth: fix IRQ lifetime against netdev teardown
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] The IRQ handler can still reach freed skb memory during teardown.
- [Medium] In ioc3eth_probe() (drivers/net/ethernet/sgi/ioc3-eth.c), the shared IRQ is still requested before the state its handler uses exists.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but ioc3_error() can deadlock against the timer callback and warns on every error…
--
net: sgi: ioc3-eth: fix IRQ lifetime against netdev teardown
This patch moves spin_lock_init() and timer_setup() ahead of the IRQ request in ioc3eth_probe(), and replaces devm_request_irq() with request_irq(). It also adds free_irq() calls on the probe error path and in ioc3eth_remove(), so the handler is gone before free_netdev() runs.
drivers/net/ethernet/sgi/ioc3-eth.c static int ioc3eth_probe(struct platform_device *pdev) · line 874
Quoted 12 lines
drivers/net/ethernet/sgi/ioc3-eth.c +2
-2@@ -870,16 +870,16 @@ static int ioc3eth_probe(struct platform_device *pdev) goto out_free; } -if (devm_request_irq (&pdev->dev, dev->irq, ioc3_interrupt, -IRQF_SHARED ,"ioc3-eth" , dev)) { +spin_lock_init (&ip->ioc3_lock); +timer_setup (&ip->ioc3_timer, ioc3_timer,0 );
[Severity: High]
This is a pre-existing issue, not one introduced by this patch. The timer is set up here without TIMER_IRQSAFE. Can ioc3_error() deadlock against the timer callback?
ioc3_error() runs in hardirq context from ioc3_interrupt(). It takes the lock and then calls ioc3_init():
ioc3_interrupt()
ioc3_error()
spin_lock(&ip->ioc3_lock);
...
ioc3_init(dev);
timer_delete_sync(&ip->ioc3_timer);Because the timer is not TIMER_IRQSAFE, every error interrupt should hit this check in __timer_delete_sync():
WARN_ON(in_hardirq() && !(timer->flags & TIMER_IRQSAFE));
The timer callback takes the same lock:
ioc3_timer()
ioc3_setup_duplex()
spin_lock_irq(&ip->ioc3_lock);
Suppose CPU1 is in ioc3_timer() spinning on ioc3_lock, while CPU0 holds ioc3_lock in ioc3_error(). CPU0 would then spin forever in the ret < 0 loop of __timer_delete_sync(), waiting for CPU1's callback to finish.
The timer is re-armed every 1.2s while the interface is up. Heavy incoming traffic can cause RX overflow errors.
ioc3_timeout() has the same pattern. It holds spin_lock_irq(&ip->ioc3_lock) across ioc3_init() -> timer_delete_sync().
Quoted 4 lines
drivers/net/ethernet/sgi/ioc3-eth.c +3
-0+ +if (request_irq (dev->irq, ioc3_interrupt,IRQF_SHARED ,"ioc3-eth" , + dev)) {dev_err (&pdev->dev,"Can't get irq %d\n" , dev->irq);
drivers/net/ethernet/sgi/ioc3-eth.c static int ioc3eth_probe(struct platform_device *pdev) · line 885
Quoted 10 lines
drivers/net/ethernet/sgi/ioc3-eth.c +0
-3err = -ENODEV ; goto out_free; } -spin_lock_init (&ip->ioc3_lock); -timer_setup (&ip->ioc3_timer, ioc3_timer,0 ); -ioc3_stop (ip);/* Allocate rx ring. 4kb = 512 entries, must be 4kb aligned */
[Severity: Medium]
The commit message says the handler could run before its state was initialized. Doesn't the same problem still apply to the rings?
When request_irq() returns, ioc3_stop() has not run yet. ip->rxr, ip->txr, rx_skbs[] and tx_skbs[] are all still NULL from alloc_etherdev(). ioc3_init(), which resets the MAC with EMCR_RST, also runs later.
ioc3_interrupt() acts on the raw EISR value. It does not mask it with EIER, does not check any device state, and always returns IRQ_HANDLED:
eisr = readl(®s->eisr);
writel(eisr, ®s->eisr);
...
if (eisr & (EISR_RXOFLO | ...))
ioc3_error(dev_id, eisr);
if (eisr & EISR_RXTIMERINT)
ioc3_rx(dev_id);If an EISR bit is latched when the handler runs here, ioc3_rx() would dereference a NULL rx_skbs[0]:
skb = ip->rx_skbs[rx_entry];
rxb = (struct ioc3_erxbuf *)(skb->data - RX_OFFSET);ioc3_error() -> ioc3_clean_tx_ring() would also write through a NULL ip->txr:
ip->txr[i].cmd = 0;
The rings do exist after later failures, such as no PHY being found or register_netdev() failing. In that case ioc3_error() would allocate and DMA-map new RX skbs and call ioc3_start(), which turns DMA and EIER back on. The out_stop path would then free the rings with DMA still running and leak those skbs.
ioc3_stop() only clears EMCR and EIER and never acks EISR. The parent's ioc3_setup() in drivers/mfd/ioc3.c clears EISR separately from EIER. That suggests the status bits can stay latched while EIER is 0.
There are two ways the handler can run in this window:
- another device asserts the shared line.
- CONFIG_DEBUG_SHIRQ makes its extra handler call from the free_irq() this patch adds on the out_stop path.
Should the rings be set up and EISR acked before the IRQ is requested? Alternatively, request_irq() and free_irq() could move into ndo_open and ndo_stop.
[ ... ]
drivers/net/ethernet/sgi/ioc3-eth.c static void ioc3eth_remove(struct platform_device *pdev) · line 976
Quoted 8 lines
drivers/net/ethernet/sgi/ioc3-eth.c +1
-0@@ -969,6 +970,7 @@ static void ioc3eth_remove(struct platform_device *pdev)struct ioc3_private *ip =netdev_priv (dev);unregister_netdev (dev); +free_irq (dev->irq, dev);timer_delete_sync (&ip->ioc3_timer);dma_free_coherent (ip->dma_dev,RX_RING_SIZE , ip->rxr, ip->rxr_dma);
[Severity: High]
Can the handler still reach freed skbs in this teardown path?
unregister_netdev() runs ioc3_close() before this free_irq():
ioc3_close()
timer_delete_sync(&ip->ioc3_timer);
netif_stop_queue(dev);
ioc3_stop(ip);
ioc3_free_rx_bufs(ip);
ioc3_clean_tx_ring(ip);ioc3_close() has no synchronize_irq(), and ioc3_rx() takes no lock. A handler already running on another CPU when EIER is cleared can therefore race with ioc3_free_rx_bufs().
ioc3_free_rx_bufs() frees rx_skbs[rx_ci..rx_pi) with dev_kfree_skb_any(). It leaves the pointers in ip->rx_skbs[] and does not reset rx_ci or rx_pi.
The handler can run after that in two ways:
- a shared-line interrupt arrives while the interface is down.
- CONFIG_DEBUG_SHIRQ makes its extra call inside this new free_irq(). The commit message names that config as the reproduction method.
ioc3_interrupt() acts on EISR without checking EIER or IFF_UP:
- EISR_RXTIMERINT goes to ioc3_rx(), which dereferences the freed ip->rx_skbs[rx_ci]->data and can pass a freed skb to netif_rx().
- The error bits go to ioc3_error(), which runs ioc3_free_rx_bufs() again over the stale indices and frees the same skbs twice. It then allocates new RX skbs and calls ioc3_start(). That turns DMA and EIER back on for a downed interface just before the dma_free_coherent() calls below, and the new skbs are leaked.
Would it be better to move request_irq() and free_irq() into ndo_open and ndo_stop? The other option is to add synchronize_irq(), ack EISR in the stop path and clear rx_skbs[] after freeing.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116101934.25910-1-kaloz%40kernel.org
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Mon, 16 Nov 2026 11:19:32 +0100 you wrote:
Two teardown fixes for ioc3-eth: probe never stores the
net_devicethat remove fetches, and the shared IRQ outlivesfree_netdev().Tested on an SGI Fuel.
Imre Kaloz (2):
net: sgi: ioc3-eth: set platform drvdata in probe
net: sgi: ioc3-eth: fix IRQ lifetime against netdev teardown[...]
Here is the summary with links:
- [net,1/2] net: sgi: ioc3-eth: set platform drvdata in probe
https://git.kernel.org/netdev/net-next/c/944841b8af49
- [net,2/2] net: sgi: ioc3-eth: fix IRQ lifetime against netdev teardown (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html