Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/2] ieee802154: hwsim: fix PIB lifetime during teardown and error unwind
@ 2026-12-06  8:00 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 ` [PATCH net v2 2/2] ieee802154: hwsim: free the current PIB on registration failure Roshan Kumar
  0 siblings, 2 replies; 3+ messages in thread
From: Roshan Kumar @ 2026-12-06  8:00 UTC (permalink / raw)
  To: linux-wpan, netdev, Miquel Raynal
  Cc: Alexander Aring, Stefan Schmidt, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Yousef Alhouseen

Miquel asked me to forward Yousef's teardown fix after no v2 was posted.
Patch 1 preserves Yousef's authorship and existing Signed-off-by. It moves
the final PIB lookup and free after unregistering the hardware, uses
rcu_access_pointer() as requested, and corrects the Fixes tag after checking
the file history.

Patch 2 fixes the related error unwind issue reported by Sashiko. Once the
PHY is published, a callback can replace phy->pib and queue the original
object for RCU freeing. The unwind must therefore free the final published
PIB rather than the stale local pointer.

OpenAI Codex assisted with the lifetime analysis, the two-line second fix,
commit and cover letter drafting, and test automation. The Codex session was
prompted to trace PIB ownership through registration, callback replacement,
error unwind, and teardown; minimize the fixes; inspect history and credit;
and construct deterministic KASAN and failslab validation.

Testing:
- full KASAN W=1 bzImage and hwsim module build after patch 1, followed
  by a successful incremental W=1 hwsim module rebuild after patch 2
- targeted W=1 allmodconfig and allyesconfig builds, with no hwsim
  diagnostics
- 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
- patch 1 plus patch 2: 200 teardown race rounds, with no sanitizer
  findings

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, then task-filtered failslab forced hwsim_alloc_edge() to
fail. An RCU barrier drained all deferred frees after every round.

v1:
https://lore.kernel.org/r/20260627235805.17310-1-alhouseenyousef@gmail.com/

Forwarding request:
https://lore.kernel.org/r/87wlqbn514.fsf@bootlin.com/

Sashiko report:
https://lore.kernel.org/r/179492373789.3136.2399679338709401263@kernel.org/

Roshan Kumar (1):
  ieee802154: hwsim: free the current PIB on registration failure

Yousef Alhouseen (1):
  ieee802154: hwsim: free PIB after unregistering hardware

 drivers/net/ieee802154/mac802154_hwsim.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)


base-commit: bc10f5da3e77499a7024d4c2d263d3ca04f8481d

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net v2 1/2] ieee802154: hwsim: free PIB after unregistering hardware
  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 ` Roshan Kumar
  2026-12-06  8:00 ` [PATCH net v2 2/2] ieee802154: hwsim: free the current PIB on registration failure Roshan Kumar
  1 sibling, 0 replies; 3+ messages in thread
From: Roshan Kumar @ 2026-12-06  8:00 UTC (permalink / raw)
  To: linux-wpan, netdev, Miquel Raynal
  Cc: Alexander Aring, Stefan Schmidt, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Yousef Alhouseen,
	syzbot+4707bb8a43a42fca2b97, syzbot+8a8482d4c33cc58babb4

From: Yousef Alhouseen <alhouseenyousef@gmail.com>

hwsim_del() queues the currently published PIB for RCU freeing before
unregistering the hardware. The unregister path can still invoke driver
callbacks, including set_promiscuous_mode(), after that grace period has
started. Depending on timing, a callback can consequently dereference the
freed PIB or queue the same object for RCU freeing twice.

Unregister the hardware first, then fetch and free the final PIB. This also
handles a PIB replacement performed by a callback during unregister.

Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
Reported-by: syzbot+4707bb8a43a42fca2b97@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=4707bb8a43a42fca2b97
Reported-by: syzbot+8a8482d4c33cc58babb4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=8a8482d4c33cc58babb4
Cc: stable@vger.kernel.org
Signed-off-by: Yousef Alhouseen <alhouseenyousef@gmail.com>
Signed-off-by: Roshan Kumar <roshaen09@gmail.com>
---
Changes in v2:
- move the final PIB lookup and free after ieee802154_unregister_hw()
- use rcu_access_pointer(), as requested by Miquel
- correct the Fixes tag to f25da51fdc38
- rebase on wpan.git commit bc10f5da3e77
- preserve Yousef's authorship and existing sign-off while forwarding
- complete 200 KASAN teardown race rounds after both patches, with no
  sanitizer findings
- complete targeted W=1 allmodconfig and allyesconfig builds, with no hwsim
  diagnostics

v1:
https://lore.kernel.org/r/20260627235805.17310-1-alhouseenyousef@gmail.com/

 drivers/net/ieee802154/mac802154_hwsim.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
index a9bd1555d2dc..fc2b7415afec 100644
--- a/drivers/net/ieee802154/mac802154_hwsim.c
+++ b/drivers/net/ieee802154/mac802154_hwsim.c
@@ -1008,12 +1008,11 @@ 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();
 
-	kfree_rcu(pib, rcu);
-
 	ieee802154_unregister_hw(phy->hw);
+	pib = rcu_access_pointer(phy->pib);
+	kfree_rcu(pib, rcu);
 	ieee802154_free_hw(phy->hw);
 }
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH net v2 2/2] ieee802154: hwsim: free the current PIB on registration failure
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Roshan Kumar @ 2026-12-06  8:00 UTC (permalink / raw)
  To: linux-wpan, netdev, Miquel Raynal
  Cc: Alexander Aring, Stefan Schmidt, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Yousef Alhouseen,
	Sashiko

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;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-06  8:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH net v2 2/2] ieee802154: hwsim: free the current PIB on registration failure Roshan Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox