Skip to contentSkip to conversation

ieee802154: hwsim: Fix possible memory leak in hwsim_subscribe_all_others

PATCH In review Dongliang Mu 3 participants 4 messages Jun 11, 2021 – Jun 14, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ieee802154: hwsim: Fix possible memory leak in hwsim_subscribe_all_others

In hwsim_subscribe_all_others, the error handling code performs incorrectly if the second hwsim_alloc_edge fails. When this issue occurs, it goes to sub_fail, without cleaning the edges allocated before.

Fixes f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
---
 drivers/net/ieee802154/mac802154_hwsim.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ieee802154/mac802154_hwsim.c +2 -2
index da9135231c07..366eaae3550a 100644
@@ -715,6 +715,8 @@ static int hwsim_subscribe_all_others(struct hwsim_phy *phy)
 
 	return 0;
 
+sub_fail:
+	hwsim_edge_unsubscribe_me(phy);
 me_fail:
 	rcu_read_lock();
 	list_for_each_entry_rcu(e, &phy->edges, list) {
@@ -722,8 +724,6 @@ static int hwsim_subscribe_all_others(struct hwsim_phy *phy)
 		hwsim_free_edge(e);
 	}
 	rcu_read_unlock();
-sub_fail:
-	hwsim_edge_unsubscribe_me(phy);
 	return -ENOMEM;
 }
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi,

Quoted 25 lines · Dongliang Mu

In hwsim_subscribe_all_others, the error handling code performs incorrectly if the second hwsim_alloc_edge fails. When this issue occurs, it goes to sub_fail, without cleaning the edges allocated before.

Fixes f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
---
 drivers/net/ieee802154/mac802154_hwsim.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ieee802154/mac802154_hwsim.c +2 -0
index da9135231c07..366eaae3550a 100644
@@ -715,6 +715,8 @@ static int hwsim_subscribe_all_others(struct hwsim_phy *phy)
 
        return 0;
 
+sub_fail:
+       hwsim_edge_unsubscribe_me(phy);
 me_fail:
        rcu_read_lock();
        list_for_each_entry_rcu(e, &phy->edges, list) {

drivers/net/ieee802154/mac802154_hwsim.c static int hwsim_subscribe_all_others(struct hwsim_phy *phy) · line 725

Quoted 4 lines
drivers/net/ieee802154/mac802154_hwsim.c +0 -1
@@ -722,8 +724,6 @@ static int hwsim_subscribe_all_others(struct hwsim_phy *phy)
                hwsim_free_edge(e);
        }
        rcu_read_unlock();
-sub_fail:

this goto needs to be removed and all goto cases need to end in me_fail (better named to be fail only).
In an error case both loops need to be iterated again to cleanup.

- Alex

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Dongliang Mu

Hi,

Quoted 7 lines · Dongliang Mu

In hwsim_subscribe_all_others, the error handling code performs incorrectly if the second hwsim_alloc_edge fails. When this issue occurs, it goes to sub_fail, without cleaning the edges allocated before.

Fixes f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")

sorry, it is a correct fix. Thanks.

- Alex

maintainer
#3 lore raw

Hello.

Quoted 8 lines · Alexander Aring

Hi,

Quoted 5 lines · Dongliang Mu

In hwsim_subscribe_all_others, the error handling code performs incorrectly if the second hwsim_alloc_edge fails. When this issue occurs, it goes to sub_fail, without cleaning the edges allocated before.

Quoted 6 lines
Quoted 2 lines
Fixes f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")

sorry, it is a correct fix. Thanks.

This patch has been applied to the wpan tree and will be part of the next pull request to net. Thanks!

regards
Stefan Schmidt