Skip to contentSkip to conversation

ieee802154: hwsim: fix edge allocation leak and netlink attribute validation

PATCH In review Hui Peng 2 participants 3 messages Sep 19 – Nov 17

Subsystems (3)
lore
Share & tools
lore

Hui Peng

author
#0 lore raw

PATCH 1/1 ieee802154: hwsim: fix edge allocation leak and netlink attribute validation

In drivers/net/ieee802154/mac802154_hwsim.c, clean up allocated edges and phys on error paths and validate netlink attribute bounds.

Fixes f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
Assisted-by LLM

---

drivers/net/ieee802154/mac802154_hwsim.c +4 -1
index a9bd1555d2dc..1b325d665177 100644
@@ -987,6 +987,8 @@ static int hwsim_add_one(struct genl_info *info, struct device *dev,
 
 err_subscribe:
 	ieee802154_unregister_hw(phy->hw);
+	kfree_rcu(rcu_dereference_protected(phy->pib, 1), rcu);
+	goto err_pib;
 err_reg:
 	kfree(pib);
 err_pib:
@@ -1003,6 +1005,8 @@ static void hwsim_del(struct hwsim_phy *phy)
 
 	list_del(&phy->list);
 
+	ieee802154_unregister_hw(phy->hw);
+
 	rcu_read_lock();
 	list_for_each_entry_rcu(e, &phy->edges, list) {
 		list_del_rcu(&e->list);
@@ -1013,7 +1017,6 @@ static void hwsim_del(struct hwsim_phy *phy)
 
 	kfree_rcu(pib, rcu);
 
-	ieee802154_unregister_hw(phy->hw);
 	ieee802154_free_hw(phy->hw);
 }
 
maintainer
#2 lore raw
Quoted 10 lines · Miquel Raynal
Quoted 6 lines · Hui Peng

In drivers/net/ieee802154/mac802154_hwsim.c, clean up allocated edges and phys on error paths and validate netlink attribute bounds.

Fixes f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
Assisted-by LLM

The commit message is incoherent, I would like to withdraw my tag.

Also, this is the fourth time we receive a similar fix. I already reviewed this one:
https://lore.kernel.org/all/[email protected]/
For which I wait for a v2 which never comes. You can take the feedback sent there into account (still applies).

Thanks,
Miquèl