🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #18784

Re: [PATCH net 2/2] net: sgi: ioc3-eth: fix IRQ lifetime against netdev teardown

#18784
From: netdev-bot+sashiko
Date: Wed, 18 Nov 2026 22:22
201 lines
15202 bytes
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.

Closes: https://lore.kernel.org/all/179473760071.2199510.16065103101920438822@kernel.org/

> diff --git a/drivers/net/ethernet/sgi/ioc3-eth.c b/drivers/net/ethernet/sgi/ioc3-eth.c
> index ee284a4f75ff2..e322a588d5c4d 100644
> --- a/drivers/net/ethernet/sgi/ioc3-eth.c
> +++ b/drivers/net/ethernet/sgi/ioc3-eth.c
> @@ -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().

> +
> +	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 */

[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(&regs->eisr);
    writel(eisr, &regs->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.

[ ... ]

> @@ -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.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116101934.25910-1-kaloz%40kernel.org
Technical Details
Message-ID: <179504054981.3136.8539477779059154181@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366486-linux-kernel-netdev=dewy.ru
References: <20261116101934.25910-3-kaloz@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-366486-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 2/2] net: sgi: ioc3-eth: fix IRQ lifetime against
 netdev teardown
Date: Wed, 18 Nov 2026 22:22:29 +0000
Organization: Usenet Network
Message-ID: <179504054981.3136.8539477779059154181@kernel.org>
References: <20261116101934.25910-3-kaloz@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2714209"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:RN/5WLe30+SecPt2ZqPJ2twCreE= sha256:a8Qbvy5S+CNKv2qQbKhmCeCz2VHgxAnRGXE0/RVI/hs=
	sha1:P3/2BR7dKHp9wLqymlasyfbq8K0= sha256:7nHGJK1Agt2rUnpccm9gTJhw0Y48Xs/u5ztUbNOPU7A=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 007DA115402; Thu, 19 Nov 2026 01:22:55 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id jSOsCjsEUpkb;
	Thu, 19 Nov 2026 01:22:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-366486-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 31F681153FE; Thu, 19 Nov 2026 01:22:39 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 5FAD5A9CCC; Wed, 18 Nov 2026 22:22:37 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795040557;
	b=THdEqqacVpadXPnbuu2Qs9gyGdI5vtcmiX4epr34TQesY4vhuZDXFkl8oVbKebLOhofD
	 76VnNEcJzpoiP4min2Ei6L2b5DMp92h/0aKoex7o6ZBZrVFyAMJWsFgXkMO/K5AJloWrq
	 TXubWpGxPn+CYRf19/vbJx5GEWqH0o7zE/17Rn8MMHdYctOArA1e+9zI+blJQtGvxW5D2
	 ic16gSYjebWrADqd76zucmhnUW2rZ0mTluNc9XjJRfZyfppYVdGkJSTSRPZiehL12CQ8N
	 rAFOibbfFLBjX/zC7aZLDJOXYuFQzat+QN6rr7KtpNzDJ67IQYoTB4mE8JYZ0mQ/ciA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795040557;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=deC16colvJ6YmP1UCuRm/b/DXcA7zKSPNYZR/ylPBC8=;
	b=kulIfkGjV+dG5l+r/tjexwUdM80O0bnIL5b+NPALRSEC0NMnPlcS2r5p0TzlSa57taIe
	 61nREJbQrqJA7kayw8YbyT6HR7frj4k99vDQD0tD5psj1fnxM9CFfJxo1slqmhLT8sE3W
	 Eo/UtcS+zE3pDgRjkmzcvTxV+vW/qchCGq+GOLZJkOGB2ahGuMKq/AqRimz8wxN74efrg
	 uG6qOwDO3PQIC5+2qzZbsw+6fV6/zz7/2ma4aZBjlYzsBEAhWhw6s/gaZspoYuHr+Kl+v
	 nqVbV7SpswUVtOd/z2O86VpyHLUNgmFdMBu4oEMJTmGGomu6VhoQ4Hx5FRrAtIXZE0Q==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="dY/uIibw";
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id EEA3A606A325;
	Wed, 18 Nov 2026 22:22:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dY/uIibw
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795040551;
	b=fSxVKF5IpLYkvxfUyGKsCM5cVbCMVnf7uRUH7tkxCMVifZGJHPbTHgrZrJ8i2a7LDZ3E
	 fCPPRYR/+jWV1R10cz3005d46ZlOXq8gSTPmobY5bmb0amH8eZqe+mv5rHYJyMEIhO/Sp
	 urGORKva2gJCgES1gEfMb6xxl0iTwhb/Oy4Rtq6Zz4rC3UOIdd8cefmb81tDNVcFg7n0U
	 GL86ywpH1TvV6CM026tT+1XJhOjEEHTBsVtV/9vbE/y2zDIXUM76TKXFEghC61sYqoH4O
	 wl2ubZcTqTOUse9eHQZ8QSIcPzuKkqys8ZquA9utffbR1JdUG2vToAsx2j6mjhXYscw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795040551;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=deC16colvJ6YmP1UCuRm/b/DXcA7zKSPNYZR/ylPBC8=;
	b=qkkJaJcW9KqFf3lMXzRZDAKBojYW1mb247bc8/5eGrlQ5xDAL3JADFtvD7vB25dgG/RK
	 HHq/Is66qHEiqrupd7RnEase63KPI+QSUpoXqrlUJF3BpNR01d2dGdwQagQTwrI3vYQnP
	 gn2Sevq8w3SkkELVILvH73d9J66qnhRyQqYgShGKVSDeDhWgHxFsFuEkTlYMAYDCgTbhc
	 vOq1oVOAZtnotRanmGnwUEzoLrD/G4YVchU8DToUt7mnKSo49Gm70BgHnZqBn0kKq865R
	 mgX6k0OPpeYMhetzos/l63nt9q8jPM/F4dPLC6oj7au/WDmAm9PAxOWQv0PvCb+Nn2w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="dY/uIibw";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 106AA606A31C;
	Wed, 18 Nov 2026 22:22:30 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E3DE1F000C4;
	Wed, 18 Nov 2026 22:22:30 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795040550;
	bh=deC16colvJ6YmP1UCuRm/b/DXcA7zKSPNYZR/ylPBC8=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=dY/uIibwHTdJA4M5PzAmm39IT2+od4JB7aY09mU24btvxJ4jk3dnClNHcU/Xd2djP
	 jf3W9adJTe1KBa18nNeR1HUjFY1ipuC/DlS+1h2u8Pcw0OOEahFVAt06XWlWnjGtEJ
	 VcVWV9oV8M1Lvh8KXF8+kwIGH/X7lWEU3MxDSa1FyJrGESKLZui9+4cHMBg5TpswEQ
	 MUgaMWg8/fULiXQlN4cTnjLvq0i7KPiJ+6YH9cORiD/F6pDZckA/75IPffo/tEi3ml
	 lpBelbATD3DsJfnSYzw2Mi9qOiI7FUasy4HzukKwvN5upqkMAQTOgO3JQbICSC1ssw
	 hxzz813wk3RsA==
X-Cc: tsbogend@alpha.franken.de, netdev@vger.kernel.org, andrew+netdev@lunn.ch,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
 stable@vger.kernel.org, sashiko-bot@kernel.org
X-In-Reply-To: <20261116101934.25910-3-kaloz@kernel.org>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list