Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: liguangshuo@mail.sdu.edu.cn
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
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	[thread overview]
Message-ID: <179630247542.3146.8091475871652821143@kernel.org> (raw)
In-Reply-To: <20261202-19c6929445-net-wan@mail.sdu.edu.cn>

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

      reply	other threads:[~2026-12-03 12:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:51 [PATCH net] net: wan: fsl_ucc_hdlc: Fix potential use-after-free on removal Guangshuo Li
2026-12-03 12:54 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179630247542.3146.8091475871652821143@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=kuba@kernel.org \
    --cc=liguangshuo@mail.sdu.edu.cn \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=qiang.zhao@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox