Article View: linux.kernel.netdev
Article #17904Re: [PATCH net] ieee802154: hwsim: free PIB after hardware unregister
From: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 13:55
Date: Tue, 17 Nov 2026 13:55
128 lines
12338 bytes
12338 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] The patch fixes the stale-PIB double free in hwsim_del(), but
the error unwind in hwsim_add_one()…
--
ieee802154: hwsim: free PIB after hardware unregister
This patch reorders hwsim_del() so that ieee802154_unregister_hw() runs
before the PIB is freed. The current phy->pib is then detached under
pib_lock with rcu_replace_pointer(), and only that object is passed to
kfree_rcu(). This avoids a double free when a scan abort replaces the PIB
during teardown.
Closes: https://lore.kernel.org/all/6af5f575.b350cda4.2b6a63.0000.GAE@google.com/T/
> diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
> index a9bd1555d2dc7..a65ae2afb789b 100644
> --- a/drivers/net/ieee802154/mac802154_hwsim.c
> +++ b/drivers/net/ieee802154/mac802154_hwsim.c
> @@ -1008,12 +1008,16 @@ static void hwsim_del(struct hwsim_phy *phy)
> list_del_rcu(&e->list);
> hwsim_free_edge(e);
> }
> - pib = rcu_dereference(phy->pib);
> rcu_read_unlock();
>
> + ieee802154_unregister_hw(phy->hw);
> +
> + spin_lock_bh(&phy->pib_lock);
> + pib = rcu_replace_pointer(phy->pib, NULL,
> + lockdep_is_held(&phy->pib_lock));
> + spin_unlock_bh(&phy->pib_lock);
> kfree_rcu(pib, rcu);
[Severity: High]
This fixes hwsim_del(). Does the error unwind in hwsim_add_one() still
have the same stale PIB problem?
hwsim_add_one() keeps the original PIB in a local variable and frees that
pointer directly on failure:
drivers/net/ieee802154/mac802154_hwsim.c:hwsim_add_one() {
...
rcu_assign_pointer(phy->pib, pib);
...
err = ieee802154_register_hw(hw);
if (err)
goto err_reg;
...
err_subscribe:
ieee802154_unregister_hw(phy->hw);
err_reg:
kfree(pib);
err_pib:
ieee802154_free_hw(phy->hw);
}
After wpan_phy_register() runs inside ieee802154_register_hw(), driver
callbacks can replace phy->pib through hwsim_update_pib(). That function
calls kfree_rcu(pib_old) on the original object. Some of the paths that
get there:
NL802154_CMD_SET_CHANNEL -> ieee802154_set_channel() -> drv_set_channel()
-> hwsim_hw_channel() -> hwsim_update_pib()
interface open -> drv_start() -> set_promiscuous_mode / set_hw_addr_filt
scan abort inside ieee802154_unregister_hw(), which is the path the
commit message describes
On the err_subscribe path, ieee802154_unregister_hw() runs first and then
falls through to kfree(pib). This happens when hwsim_probe() calls with
init set and hwsim_subscribe_all_others() fails with -ENOMEM.
The HWSIM_CMD_NEW_RADIO path can also reach err_reg, when
ieee802154_if_add() fails after wpan_phy_register() has succeeded.
wpan_phy_register() drops rtnl before ieee802154_register_hw() takes it
again. A SET_CHANNEL request can run in that window and replace the PIB:
net/mac802154/main.c:ieee802154_register_hw() {
...
rc = wpan_phy_register(local->phy);
if (rc < 0)
goto out_mac_wq;
rtnl_lock();
dev = ieee802154_if_add(local, "wpan%d", NET_NAME_ENUM,
NL802154_IFTYPE_NODE,
cpu_to_le64(0x0000000000000000ULL));
if (IS_ERR(dev)) {
rtnl_unlock();
rc = PTR_ERR(dev);
goto out_phy;
}
...
}
In both cases, wouldn't kfree(pib) free an object that is already queued
for kfree_rcu()? Wouldn't it also leak the PIB that is currently
installed in phy->pib?
The commit message says the change "avoids freeing a PIB that was already
replaced during teardown". Should the hwsim_add_one() unwind follow the
same sequence that hwsim_del() now uses? That would mean detaching
phy->pib under pib_lock with rcu_replace_pointer() after unregistering
the hardware, and passing the result to kfree_rcu(), rather than calling
kfree() on the saved local pointer.
>
> - ieee802154_unregister_hw(phy->hw);
> ieee802154_free_hw(phy->hw);
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/0D7C088B45E7283A%2B20261113134141.2626113-1-chenyichong%40uniontech.com
Technical Details
Message-ID:
<179492373789.3136.2399679338709401263@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365316-linux-kernel-netdev=dewy.ruReferences:
<0D7C088B45E7283A+20261113134141.2626113-1-chenyichong@uniontech.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365316-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] ieee802154: hwsim: free PIB after hardware unregister Date: Tue, 17 Nov 2026 13:55:37 +0000 Organization: Usenet Network Message-ID: <179492373789.3136.2399679338709401263@kernel.org> References: <0D7C088B45E7283A+20261113134141.2626113-1-chenyichong@uniontech.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2345035"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:Gp+fIpPKMC+F9hUiX+eC7cqk2f4= sha256:ZLqZW/sFIEFeJ+rJhy5iacRwhuBpEjcglm/anqYtHK8= sha1:P6FE+OasHm6DtRRLe7R2cZ602Aw= sha256:yKhdZONGLKB7S/iOyYucyVfJHIdXQT/E10nC1bIOqWc= 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 0E9B3114F8E; Tue, 17 Nov 2026 16:56:12 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 QwZqoNV5yNAs; Tue, 17 Nov 2026 16:56:00 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-365316-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 404B6114F48; Tue, 17 Nov 2026 16:55:51 +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 42DB435A5E; Tue, 17 Nov 2026 13:55:45 +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=1794923745; b=ahjn4Y/ZF8X63QA9oUcn/d6t7LugvsgjeOu0hF01tgJ/at4Xa/QbqUuH/Ob/+u9NFctZ SfOzjEU0UhdFGq1FsftgadPcY/Pufzvq72seUCrXYcZ0seILCynsl1+y+ABvUcbdYI54P rBfYDEghTZl9A666bMMDTMVXnlQGZhXgmipVUDTy0AUaxRKat8piaC/5XGc/Pwf7OeECV xXcwShgceIkuchnrRuSZlJsj3+amqxyL8t+BM7ON6AQTAWtMDkjKark6jtCqhgwJ/S1UM L1ynRKzBT4knvJdtIibg3MHIyxVSz3VN2pROs7q6GdmYR9PwkKgujsdui02M6KfKw9g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794923745; 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=70rfcJx4ppckiFBPTRygMuzYZpbn/QbilZ5teuDYXJQ=; b=Id4B3eN39639P5SwpCabof6YelSwa8dW15WveZGGvJv+/vrrlAFcuiSMLNBb0adjYPjE Jar/0wdq5sqPTyKQKaSTY3GhSxW8gYdo2HPTQmhOj2k/ulEXqemgPVgDl6XDy90DGj1AQ LOAQZ4QckIMGxQ7QNxg2tbGxqvLCPPrG1L8kCk4XQk4QnB2Hs76FGWtflbjghM0EJYmNd hk+nQeNfvfXxYUzGSd+Uxzy63U2K9wolb/91bHba5Omk9PCp4open/8ZPaWxXTAQC/OLi V0pUcQPKGZnfhzuGPhmzataotUXvzzRTEwOnNZmq2UjaW5vKAu7LWc9Ty9yQE/2/Iew== 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=cq1gMyW3; 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 01D91606A339; Tue, 17 Nov 2026 13:55:45 +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=cq1gMyW3 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=1794923739; b=1o4BesyL1bg2bBXAJF/DL+5YY8n3Q6OCjbiED7/EOHo7E++WcBLCjurjBdMu0UlQKbLR nuVemdDU1VS03kUcyDFOMRmjsAe8t+gypvjRfMG56xSX2ipnTlpe4zNkWG3dsNiwdJtF7 tBcIzn9mcM0ssgHUiOwkghc5H9qMoKh9rXR6yHThYKP2SKkgxMn2CWwLIaD40RA4B87HL tmfGnhh5yDHkA8NZ5ePhOlmX5PPVEexVUemtyBx/WRZDYQgDNaODcfPxFJwcfi8YHKNw+ Dg7MZVQwi374p6akugqTU7KHcaKEJs9Q8vTP6+hMOLKvWnFzum9tqwyPS1purnLj6cA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794923739; 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=70rfcJx4ppckiFBPTRygMuzYZpbn/QbilZ5teuDYXJQ=; b=ITN7v1vWKTU1bODsmR532Hz0uWqPcQcJkF81opWkShSMW/ZZ4egyZh0RCvJk1VbyubJd MfQ1pJZL6OalB7Ak0E2xVlGpDpWHvdXldu8+IZ3aG8TBiEk7lgARTkyge8hKoOV5d075J j7DCXECp7BumreWYWOn+wPSgtOttpii7yuTWe/7YtVr87cwEDyoYIg8ibopAvr3ixaOel Y3GBleiU/eirNQrF3V+UdnrmKz/yc+brinJhy4HiL6COe1dIRAvKixfNvU4L+MiaKMiSc LyBxAkk2TA4Kh0lUCfDfImV+2ITYRxpim+o+qDsW9YHSxbOv1KNHEujND5gQRGyu2Fw== 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=cq1gMyW3; 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 21816606A323; Tue, 17 Nov 2026 13:55:39 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 603B81F000C4; Tue, 17 Nov 2026 13:55:38 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794923739; bh=70rfcJx4ppckiFBPTRygMuzYZpbn/QbilZ5teuDYXJQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=cq1gMyW3B/17uRd16MqBTJQARqK4AQkyVxzdXhwPf/ADQG95sL+i6Id5F1aGXXHk4 vXii/bZkq9eHrmHzFoInhJ4Typ8l9y8WnVLUVl+RQjTWzvTldzgoP3Dmdrjqc+Qrca 1dko5XDFSP2kAQjZS7XRj/FLJqs/DZW4RCJpBL4m0qd06cQBbH0cKJafs9wJBbMtiA L85T+F7qVSbmhnF7eCD3Z85y1spfeE5y7hH/T6qhtCJUnLMrIJPkLk0ac9ZQg3AKqr fJe8XEOamTyiFIhzVc6X7PbgMSzltpE+uaI+rIHZ7VjnRLl6pYLJK1g34ON0E7mA8a k4Mp9TFN+3CeQ== X-Cc: alex.aring@gmail.com, stefan@datenfreihafen.org, miquel.raynal@bootlin.com, linux-wpan@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, zhanjun@uniontech.com, syzbot+8a8482d4c33cc58babb4@syzkaller.appspotmail.com, stable@vger.kernel.org, kuba@kernel.org X-In-Reply-To: <0D7C088B45E7283A+20261113134141.2626113-1-chenyichong@uniontech.com> 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