🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16654

Re: [PATCH net] net: fealnx: Fix potential use-after-free during removal

#16654
From: netdev-bot+sashiko
Date: Sun, 15 Nov 2026 12:37
147 lines
13219 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 (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).

- [Medium] The patch's Fixes: tag points at the wrong commit.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but netdev_close()
  does not stop the interrupt handler and timers before it stops the…

--

net: fealnx: Fix potential use-after-free during removal

This patch moves unregister_netdev() ahead of the dma_free_coherent() calls
in fealnx_remove_one(). With that order, netdev_close() no longer walks
the tx and rx descriptor rings after they have been freed.

> Fixes: 8f1482080104 ("eth: fealnx: bring back this old driver")

[Severity: Medium]
Is this the right commit for the Fixes: tag?

Commit 8f1482080104 is a straight revert of d5e2d038dbec ("eth: fealnx:
delete the driver for Myson MTD-800"), and it only re-added the file.

Before the deletion, fealnx_remove_one() already used the same ordering:

	dma_free_coherent(&pdev->dev, TX_TOTAL_SIZE, np->tx_ring,
			  np->tx_ring_dma);
	dma_free_coherent(&pdev->dev, RX_TOTAL_SIZE, np->rx_ring,
			  np->rx_ring_dma);
	unregister_netdev(dev);

git blame at d5e2d038dbec^ attributes the function body and the
unregister_netdev() call to 1da177e4c3f4 ("Linux-2.6.12-rc2"). The
dma_free_coherent() lines come from the 2020 pci_free_consistent
conversion, 405e30e23cb3.

The driver was only deleted for v6.2. That means 6.1.y, 5.15.y and 5.10.y
still carry it, with the same use-after-free on removal. None of those
branches contain 8f1482080104, so wouldn't Fixes-based stable selection
skip them?

Would Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2"), plus
Cc: stable@vger.kernel.org, be more accurate?

> diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
> index bdc38aac58509..68194c9ef3326 100644
> --- a/drivers/net/ethernet/fealnx.c
> +++ b/drivers/net/ethernet/fealnx.c
> @@ -682,11 +682,11 @@ static void fealnx_remove_one(struct pci_dev *pdev)
>  	if (dev) {
>  		struct netdev_private *np = netdev_priv(dev);
>  
> +		unregister_netdev(dev);
>  		dma_free_coherent(&pdev->dev, TX_TOTAL_SIZE, np->tx_ring,
>  				  np->tx_ring_dma);
>  		dma_free_coherent(&pdev->dev, RX_TOTAL_SIZE, np->rx_ring,
>  				  np->rx_ring_dma);
> -		unregister_netdev(dev);
>  		pci_iounmap(pdev, np->mem);
>  		free_netdev(dev);

[Severity: High]
This is a pre-existing issue and was not introduced by this patch. Can
removal still end in a use-after-free when netdev_close() races with
intr_handler()?

netdev_close() never takes np->lock. It also calls free_irq() only after
it has stopped the chip and deleted the timers:

drivers/net/ethernet/fealnx.c:netdev_close() {
	...
	iowrite32(0x0000, ioaddr + IMR);
	stop_nic_rxtx(ioaddr, 0);
	timer_delete_sync(&np->timer);
	timer_delete_sync(&np->reset_timer);
	free_irq(np->pci_dev->irq, dev);
	...
}

The IRQ is requested with IRQF_SHARED, so intr_handler() can run on
another CPU during this whole sequence. If the handler runs out of
boguscnt after timer_delete_sync(&np->reset_timer), it re-arms the timer:

drivers/net/ethernet/fealnx.c:intr_handler() {
	...
	if (!np->reset_timer_armed) {
		np->reset_timer_armed = 1;
		np->reset_timer.expires = RUN_AT(HZ/2);
		add_timer(&np->reset_timer);
	...
}

free_irq() waits for the handler to finish, but netdev_close() then
returns with reset_timer still pending. fealnx_remove_one() goes on to
call pci_iounmap() and free_netdev(), which frees netdev_private and the
timer_list embedded in it.

About HZ/2 later, reset_timer() would take np->lock in freed memory and
do MMIO through the unmapped np->mem.

The chip can also be restarted after the stop_nic_rxtx() call in close:

  - The RBU branch in intr_handler() and the netdev_rx() error path write
    np->crvalue back to TCRRCR. netdev_close() never clears
    CR_W_RXEN/CR_W_TXEN from np->crvalue. intr_handler() also writes
    np->imrvalue back to IMR on exit.

  - If reset_timer() fires between stop_nic_rxtx() and
    timer_delete_sync(&np->reset_timer), enable_rxtx() rewrites the ring
    base addresses, turns RX/TX back on through __set_rx_mode() and
    unmasks IMR.

  - On a link-up media change, netdev_timer() can write crvalue, with the
    enable bits set, back to TCRRCR before
    timer_delete_sync(&np->timer) runs.

In addition, stop_nic_rxtx() gives up silently after 0x1000 polls. The
driver never does a BCR soft reset and never calls pci_disable_device()
or pci_clear_master().

With this patch, the coherent rings are freed right after
unregister_netdev() returns. Could a chip that is still bus mastering
then DMA into the freed rings and RX skbs?

One possible order:

  - call free_irq() first, or mask IMR under np->lock and then call
    synchronize_irq()
  - delete the timers so that reset_timer cannot be re-armed
  - do the final hardware stop
  - confirm the stop and reset the chip before the rings are released

Would that close these windows?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111-e5624093d6-net-fealnx%40mail.sdu.edu.cn
Technical Details
Message-ID: <179474623827.2199510.10084653332786224058@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-363702-linux-kernel-netdev=dewy.ru
References: <20261111-e5624093d6-net-fealnx@mail.sdu.edu.cn>

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-363702-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: fealnx: Fix potential use-after-free during removal
Date: Sun, 15 Nov 2026 12:37:18 +0000
Organization: Usenet Network
Message-ID: <179474623827.2199510.10084653332786224058@kernel.org>
References: <20261111-e5624093d6-net-fealnx@mail.sdu.edu.cn>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1797389"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:xLQhM9Fd7laMm5O1SnviOlqFxnc= sha256:yzgPKPkNPqOKZVdJLHQ9qRIdpP1wa50dMrp8cHApRyc=
	sha1:pzwbFLHlXoiLT1Z6ADdWC46wqos= sha256:gb/uckDEnYPewIBpN1Ig+yR2w1fMtP/Xj5Q5ql0LtEo=
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 A149C1149CD; Sun, 15 Nov 2026 15:37:35 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 mbLbx6-LIO55;
	Sun, 15 Nov 2026 15:37:31 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-363702-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 2B1FF1149C9; Sun, 15 Nov 2026 15:37:23 +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 622E942CCF; Sun, 15 Nov 2026 12:37:21 +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=1794746240;
	b=zLeJsHvAu0oLv5GdBCCgddrvA5X5Ckfw5F7a6MEvx56NimM/Th1a9IlgIlIDZThNjG1B
	 CfG2nfKGZ9N9I6u4Y5ML/rs7UinlhYFdJUiyHecYAVkyA+QdMpK32UM2O36ORQSROPpaD
	 5Bd0GLh1Ba6HovqmIfEAun8m7cmJqIGR3nGA9hR6do3+wQk/l5Do53iK3D//5IR0gWa8c
	 wHjXXvdxs1T7p6FYej6++DRxOYy4miZpdnlpBhSEjZpJp1GH/RmPv3mcv/b1tlOaN84rA
	 xV8M8Uxje08jDdcRKkQRjiliuM5bvD+Iww8luCnqvwIfGP6OEMWCPDnMh3tj+e6mQQA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794746240;
	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=2DJW9TGlzvjVKygKaa9hS/L8TMifB5wje9A1GePfQ/E=;
	b=gIR3WhKwDp3fESELXhLZi/8bXElydntYRcvOzzXBWIIaW8GrvL44QecPbY5Rjd/E0OZb
	 EKN0NqnMRW7daMib7c56fKAkI+L9cBdKPlDE2MzfaMwvF6uySBvd7WgT/1ZcNeteV15uV
	 mv3qGRTnmrrgWoM+ncm37tu+VPxcAqRNkvYgsB8ovDVQvqawuTWUObHgBz42eIO9wDiBW
	 I+qIxxUK/4zFE8O16gXcdr6T5x8lSfOjOx//SLRhZVUr6M1RRgMbtwmneG7T/Ajc/H8to
	 d5Dmk2tVPUOWp0CfL9LiKX1rqDm5TMIhFuo6N9jGli1tus0p8DQLq1oAPtTS0KHCqAg==
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=WVQSMaWL;
	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 621A2606A332;
	Sun, 15 Nov 2026 12:37:20 +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=WVQSMaWL
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=1794746239;
	b=LFQRl/vvJ5Rd+LaUFRvhD3xKc2BD9woU+CV2H3arxF6x37U0z349hhseQTDfaOtRseul
	 Zysp/FancIceVBq6HYY7fUQPoR25aOqGqGoVXhy0i2FJICxhjIkiVmsI+hmlvj8M04FuV
	 8Lkxq0plbaAfw134JllZnIErHzDNsrgupedmi8xlRbgydRpDfkFUpM6O8sH0AuZzC5lyL
	 d9CMzpKAldGItVlzhiGa8NX2ROKR2sag+dvRaSlo1fbOhX8nWrEtGiKtXDFF1N19olsSc
	 4kzmVu0lg5pr6SFKMALEvTokRjgjGRrjeDlfgMeTJy4RlWZCe7TzD+QlQSYaWyM0acQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794746239;
	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=2DJW9TGlzvjVKygKaa9hS/L8TMifB5wje9A1GePfQ/E=;
	b=kFAK0Q+T5oDCDjn1ThGH8121ytedp1NdVb8l1ef8VafJRCSsSUuq0vMhi+O0Tn1kjjdL
	 Ein7Z4LgWEd3TNpJRrSrm1GnsIhWwiewVvRQYTCbZOxxRJXwCDjQy7a/V9r7jKdCFfZwy
	 2CIwchLkk3SzyJe6lSCSe6Dqzc1HEeU+eVVQ2mHah15K8CK44vNQu624NZWbbZg7dW7Gx
	 YAX1S8VvyLbiwKT7G3p0AR1NkTs4vFjzfEYWOmncFWBnEOwnGqP1EBo92z3knw6qyXog9
	 GSyhlunKdfSOc8470QuRVFLhMqn/zKdVoyrRrJTxzJfjJZKi1IMjX3SebppTuEAdB5g==
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=WVQSMaWL;
	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 8173B606A31A;
	Sun, 15 Nov 2026 12:37:19 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2AC71F000C4;
	Sun, 15 Nov 2026 12:37:18 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794746239;
	bh=2DJW9TGlzvjVKygKaa9hS/L8TMifB5wje9A1GePfQ/E=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=WVQSMaWLPZfrCBFVNew7/CTBSu0U0bATNpsbDK2VH8gQtfhJXNdvrvYSa+5G3fc7o
	 M2O6PxZ0ymYphj/aH5+bHbnKsEGDocLKOoFHkE+xZAIqz3CUU3GUVOUZMm6NKm/5ZF
	 y+lvS093dtCPq/CqfweKCHBwn2tBWAGM+5shanI7iv5ydu5hYcKqtKe/fy4NN77tTE
	 0DKq8ofDXstn4bBrzl3TFKeQEA/rgPLFF4cSNKDff0o+3eQLue+OO7QQXvk9gKgRGe
	 ZewZ3IOkzLxVm5hqn9mphFKw6wtM4GUqFl472BQIvbMW0uYTqPKcn3IFWbya0t3wuF
	 9hkk8xvhtuB+w==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <20261111-e5624093d6-net-fealnx@mail.sdu.edu.cn>
X-sashiko-severity: Medium
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