๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26385

Re: [PATCH net] net: wan: fsl_ucc_hdlc: Fix potential use-after-free on removal

#26385
From: netdev-bot+sashiko
Date: Thu, 03 Dec 2026 12:54
108 lines
11605 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 0 ยท 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] Removing the device while the HDLC interface is up still causes
  use-after-free.

--

net: wan: fsl_ucc_hdlc: Fix potential use-after-free on removal

This patch adds unregister_hdlc_device() and free_netdev() calls to
ucc_hdlc_remove(). The goal is to tear down the HDLC network device
before uhdlc_memclean() and kfree() release priv and the hardware
resources.

> diff --git a/drivers/net/wan/fsl_ucc_hdlc.c b/drivers/net/wan/fsl_ucc_hdlc.c
> index 809f21fb93f56..5cdabe14e606d 100644
> --- a/drivers/net/wan/fsl_ucc_hdlc.c
> +++ b/drivers/net/wan/fsl_ucc_hdlc.c
> @@ -1255,6 +1255,8 @@ static void ucc_hdlc_remove(struct platform_device *pdev)
>  {
>  	struct ucc_hdlc_private *priv = dev_get_drvdata(&pdev->dev);
>  
> +	unregister_hdlc_device(priv->ndev);
> +	free_netdev(priv->ndev);
>  	uhdlc_memclean(priv);

[Severity: High]
What happens if the interface is still up when ucc_hdlc_remove() runs?
It looks like uhdlc_close() never gets called on this path. If so, the
use-after-free on removal can still happen.

unregister_hdlc_device() detaches the protocol before it unregisters the
device:

drivers/net/wan/hdlc.c:unregister_hdlc_device() {
	rtnl_lock();
	detach_hdlc_protocol(dev);
	unregister_netdevice(dev);
	rtnl_unlock();
}

detach_hdlc_protocol() ends with hdlc_setup_dev(), which overwrites
dev->flags and clears IFF_UP:

drivers/net/wan/hdlc.c:hdlc_setup_dev() {
	dev->flags		 = IFF_POINTOPOINT | IFF_NOARP;
	...
}

When unregister_netdevice() reaches netif_close_many(), the device is
then dropped from the close list:

net/core/dev.c:netif_close_many() {
	...
		if (!(dev->flags & IFF_UP))
			list_del_init(&dev->close_list);
	...
}

So ndo_stop (uhdlc_close()) is never called. That skips napi_disable(),
the QE stop commands, ucc_fast_disable() and free_irq(). uhdlc_close()
is the only place in this driver that calls free_irq().

ucc_hdlc_remove() then frees the netdev. Next, uhdlc_memclean() frees the
BD rings, the RX/TX DMA buffers and uccf, and finally priv is freed.
During all of this the UCC is still enabled and can still DMA into those
buffers.

On the next UCC interrupt, can ucc_hdlc_irq_handler(), still registered
with dev_id == priv, dereference the freed priv and uccf and touch the
unmapped UCC registers? After rmmod, the handler would also point into
unloaded module text.

The same path has two related effects.

First, free_netdev()->netdev_napi_exit() would hit the WARN_ON in
__netif_napi_del_locked(), because priv->napi was never disabled.

Second, with the Cisco protocol attached, cisco_start() armed st->timer
when the device was opened. detach_hdlc_protocol() frees hdlc->state
without calling proto->stop, so the timer_delete_sync() in cisco_stop()
never runs. Can cisco_timer() then fire on the freed state?

Would it be enough to close the device before unregister_hdlc_device(),
for example:

	rtnl_lock();
	dev_close(priv->ndev);
	rtnl_unlock();

Another option is to change unregister_hdlc_device() in the hdlc core so
it closes the device before detaching the protocol.

>  
>  	if (priv->utdm && priv->utdm->si_regs) {

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-19c6929445-net-wan%40mail.sdu.edu.cn
Technical Details
Message-ID: <179630247542.3146.8091475871652821143@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376611-linux-kernel-netdev=dewy.ru
References: <20261202-19c6929445-net-wan@mail.sdu.edu.cn>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376611-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: wan: fsl_ucc_hdlc: Fix potential use-after-free
 on removal
Date: Thu, 03 Dec 2026 12:54:35 +0000
Organization: Usenet Network
Message-ID: <179630247542.3146.8091475871652821143@kernel.org>
References: <20261202-19c6929445-net-wan@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="2494297"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:yBNQ48aDHglHkxUUclLWsUBVEbc= sha256:27uKIUhBwfwmtdO/ii4HrZNovgi6Jk8RavBVJeVu3DQ=
	sha1:X473oRnhS4/nz5JSex+GiP1k8Ek= sha256:tN3In4u/PRUy4xEXDmRqOVSGbDCluPJXu+PSNibujMM=
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 0CE0611794D; Thu,  3 Dec 2026 15:55:01 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.64
X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.24, 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 HLlL8inwZqWY;
	Thu,  3 Dec 2026 15:54:58 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376611-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 16083117942; Thu,  3 Dec 2026 15:54:49 +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 1BCDB2CF76; Thu,  3 Dec 2026 12:54:38 +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=1796302477;
	b=m4StelAG6J3tJiz+uYmfFBSNXZXzyenILc/4ORvcX41LAMXNj4w96zjlA9Fj7MgmxJMu
	 IuKo1xAXqNhOv9txHGjyGAhMI1rdFR+N4k7tN3LShHCIQ+nfHyBNL+yrrVWyCEWxKuJdQ
	 ZkmtDNBCFrf+jjspo6/GyBuIIsG2ugHtl0JdxYArxlu9uzpyWNM2cOwLPZ4+ijnCpOAHo
	 nJB2pTGRCtHtK2T8aK+ul52RYKjMtclyjJVFy/w8lPH6tpFM+e17Av5M66Yr7ViQssHVl
	 v+cSs/4OnhC8SuXlBEXaAHjKAnLN6e2l8PGMwEDpTiQIq3+7V9ZFZ51VPLl7++4/gZw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796302477;
	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=pM5//0cY5oLjPPSsmPPbGLCbdP1OfLyz+kXxtOlCabo=;
	b=gDGhOkl4usV3zaouQKeJ6ss2EaM210EFgm1nCxerZKErTsM3NsN6HBQT9RRgDqshl18X
	 F7e/XmTZ0+1n9kEs8voTGHQQgpHUsnubYLK/whNUxn0X5C8tIkJqVfymuupOm2Pyb8OrW
	 bHvbdQKFTtGBU9Du+6CrjuY/woucV3PIk8JHLCRW+ozw5DGfQyRAAZR9477tgTBSiBhEO
	 6omu2ukzcB3daRx0QIHzcLEsfGlyJ9zTOxQ7J81ey4BC4m3NE0kWQPYK+Cz5IQeQM2129
	 qE5qxeuABaXO3KUBl3VCmEaX1Za+NONpAwI1rtF5MePgHbN8NX10vEim3iva4xJl1kA==
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=kojgz809;
	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 44FCC606A32C;
	Thu,  3 Dec 2026 12:54:37 +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=kojgz809
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=1796302476;
	b=aRXUqkpb6FSsMHZAd53Kdavo0MwtKlY0yINH6mff/RJR7MogDwHM37NYxPBSaZOk0KMD
	 7VUbKuNFMm6vMn+4sKLWKVzOsoB5x4WrYZfJsGJWakyLY465UeVbgjkeLljaP8IdGZ+W+
	 0/+y9oonmHW8fcse3MPVgE4bFOfpyRpYI7iVdIDOPGeNZ4Jt5xa8XXQsQDDUOOncNbSFv
	 SZ7kunmShTBrjcqLWPhOrnydIu/Os4pPlLJLRuH0JOp4rx/VakVbuyk/jcbPgRz86k6te
	 osMa4unuy3mLCsFQfhLE6212DJQFGYMcmQvROBrOaPtW1tNX8l+AHRfcTWLq0naLz0A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796302476;
	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=pM5//0cY5oLjPPSsmPPbGLCbdP1OfLyz+kXxtOlCabo=;
	b=2F4+8GxehdXSKp2tHb+Pphv9e/Ndsu+bWFndG+bfWSP2NKFv364TRoa1hvZcfDF/ctqg
	 /p+TbWVTJlzLguATN4DVMd34sPlnMmEpL8/0urHBg6NNcI56e2wmnafq9Bsbq0Q8FYJqW
	 XZ7TmJe+O0geJeL00QM4VmB09cpynkcXvAjbPpHSm1xZPFwRQpEoWJuOEdFF3YSpN7Qrv
	 1zC0W+pfnK21PvkiG5iRcvDM/x0Uvfl9V0F0YFeKf5f4OtxIceJuZiG8CJceTbLXOmrmf
	 uKi4C8khCCCQf6AyI1pKLXvkhO2W8CkpYrQmuTzEPHO9Pttqks7mgCJNgdfe/CVELLA==
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=kojgz809;
	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 680C9606A339
	for <netdev@vger.kernel.org>; Thu,  3 Dec 2026 12:54:36 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD81D1F000C1;
	Thu,  3 Dec 2026 12:54:35 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796302476;
	bh=pM5//0cY5oLjPPSsmPPbGLCbdP1OfLyz+kXxtOlCabo=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=kojgz809Cvz49ZUh60VixjbI5ANBjLhq14/Y6JOS+RYvorQ+9g46OwtfKjb/zzdHf
	 57h6Q1rkvruX9pFs0JIRvBU3Y5+w0RBLdiUr0uSEEZiq12kvmiALrcuc4w3A3LHz34
	 0oPtJM8PfPBLLPnkUN0SGwXuLN9bhj16Bz6F7j4qVHSoUgj6XlSS70TDo7qf2LMIpD
	 8ffJdjkB0WK5532Zv38HkFJ16wJ5tNCI92yKuzAcSFaxm3ZTpJ39Y+zeERFgi6ozP4
	 V6vQI2YmJi6w5lXIgBFGAaJo4sYf4HprT7SCpbo87byPSc2xMTQUKCKqdf+8C3K4gv
	 wjI3o7+tVNwSQ==
X-Cc: qiang.zhao@nxp.com, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
X-In-Reply-To: <20261202-19c6929445-net-wan@mail.sdu.edu.cn>
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