* [PATCH net] net: wan: fsl_ucc_hdlc: Fix potential use-after-free on removal
@ 2026-12-02 12:51 Guangshuo Li
2026-12-03 12:54 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-12-02 12:51 UTC (permalink / raw)
To: qiang.zhao, andrew+netdev, davem, edumazet, kuba, pabeni
Cc: netdev, linuxppc-dev
Removal frees the HDLC private state without unregistering its network
device. The registered device retains that pointer and its operations
can access freed memory.
Unregister and free the network device before releasing its private
state and hardware resources.
This issue was found by our static analysis tool under development.
Confirmed by tracing removal and the netdev callbacks in the source.
Build-tested on powerpc with allyesconfig and allmodconfig, W=1 and
CONFIG_WERROR=n after reproducing existing baseline warnings. No
hardware, reproducer or kernel selftest runs were performed.
Fixes: c19b6d246a35 ("drivers/net: support hdlc function for QE-UCC")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/net/wan/fsl_ucc_hdlc.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/wan/fsl_ucc_hdlc.c b/drivers/net/wan/fsl_ucc_hdlc.c
index 809f21fb93f5..5cdabe14e606 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);
if (priv->utdm && priv->utdm->si_regs) {
base-commit: b6c8f45ed340f00bf2004d407cf7316fe3e24c48
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: wan: fsl_ucc_hdlc: Fix potential use-after-free on removal
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
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 12:54 UTC (permalink / raw)
To: liguangshuo
Cc: qiang.zhao, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linuxppc-dev
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 12:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox