From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Thu, 3 Dec 2026 12:54:36 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD81D1F000C1; Thu, 3 Dec 2026 12:54:35 +0000 (UTC) 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== Subject: Re: [PATCH net] net: wan: fsl_ucc_hdlc: Fix potential use-after-free on removal 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 Date: Thu, 03 Dec 2026 12:54:35 +0000 Message-ID: <179630247542.3146.8091475871652821143@kernel.org> In-Reply-To: <20261202-19c6929445-net-wan@mail.sdu.edu.cn> References: <20261202-19c6929445-net-wan@mail.sdu.edu.cn> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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