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 <netd…@kernel.org>
Link: https://lore.kernel.org/r/1794…@kernel.org
Cc: stab…@vger.kernel.org
Signed-off-by: Roshan Kumar <rosh…@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/1794…@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;
[PATCH net v2 2/2] ieee802154: hwsim: free the current PIB on registration failure
- From
- rosh…@gmail.com (Roshan Kumar)
- Organization
- Usenet Network
- Message-ID
- <2026…@gmail.com>
- Date
- Newsgroups
- linux.kernel.netdev