From: Roshan Kumar <roshaen09@gmail.com>
To: linux-wpan@vger.kernel.org, netdev@vger.kernel.org,
Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Alexander Aring <alex.aring@gmail.com>,
Stefan Schmidt <stefan@datenfreihafen.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Yousef Alhouseen <alhouseenyousef@gmail.com>,
Sashiko <netdev-bot+sashiko@kernel.org>
Subject: [PATCH net v2 2/2] ieee802154: hwsim: free the current PIB on registration failure
Date: Sun, 6 Dec 2026 13:30:36 +0530 [thread overview]
Message-ID: <20261206080036.2769662-3-roshaen09@gmail.com> (raw)
In-Reply-To: <20261206080036.2769662-1-roshaen09@gmail.com>
hwsim_add_one() stores the initial PIB locally before publishing it through
phy->pib. ieee802154_register_hw() publishes the PHY before creating its
default interface. A concurrent request using NL802154_CMD_SET_CHANNEL can
replace phy->pib before registration fails and queue the initial object for
RCU freeing.
The err_subscribe path can also replace the PIB through callbacks run by
ieee802154_unregister_hw(). Both paths then reach err_reg, which frees the
stale initial pointer instead of the final published PIB. This can free an
object already queued for RCU freeing and leak the current PIB.
At err_reg, either registration has failed or a successfully registered PHY
has been unregistered. Fetch the final published PIB and queue that object
for RCU freeing instead.
Sashiko found the issue while reviewing another submission for the teardown
bug. The analysis and fix were prepared with OpenAI Codex assistance.
Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
Reported-by: Sashiko <netdev-bot+sashiko@kernel.org>
Link: https://lore.kernel.org/r/179492373789.3136.2399679338709401263@kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Roshan Kumar <roshaen09@gmail.com>
---
New in v2.
The fault-injection test used a temporary, unsubmitted module parameter to
pause the second probe after PHY publication. Both interfaces were opened to
replace their PIBs before task-filtered failslab forced hwsim_alloc_edge()
to fail. An RCU barrier drained all deferred frees after every round.
Patch 1 only:
- one deterministic fault-injection round reproduced the KASAN double-free
in hwsim_add_one()
Patch 1 plus patch 2:
- 100 deterministic fault-injection rounds, with no sanitizer findings
Sashiko report:
https://lore.kernel.org/r/179492373789.3136.2399679338709401263@kernel.org/
drivers/net/ieee802154/mac802154_hwsim.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
index fc2b7415afec..056e64b31b91 100644
--- a/drivers/net/ieee802154/mac802154_hwsim.c
+++ b/drivers/net/ieee802154/mac802154_hwsim.c
@@ -988,7 +988,8 @@ static int hwsim_add_one(struct genl_info *info, struct device *dev,
err_subscribe:
ieee802154_unregister_hw(phy->hw);
err_reg:
- kfree(pib);
+ pib = rcu_access_pointer(phy->pib);
+ kfree_rcu(pib, rcu);
err_pib:
ieee802154_free_hw(phy->hw);
return err;
prev parent reply other threads:[~2026-12-06 8:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 8:00 [PATCH net v2 0/2] ieee802154: hwsim: fix PIB lifetime during teardown and error unwind Roshan Kumar
2026-12-06 8:00 ` [PATCH net v2 1/2] ieee802154: hwsim: free PIB after unregistering hardware Roshan Kumar
2026-12-06 8:00 ` Roshan Kumar [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=20261206080036.2769662-3-roshaen09@gmail.com \
--to=roshaen09@gmail.com \
--cc=alex.aring@gmail.com \
--cc=alhouseenyousef@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stefan@datenfreihafen.org \
/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