ieee802154: hwsim: Fix possible memory leaks
Subsystems (3)
PATCH 1/1 ieee802154: hwsim: Fix possible memory leaks
After replacing e->info, it is necessary to free the old einfo.
--- drivers/net/ieee802154/mac802154_hwsim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ieee802154/mac802154_hwsim.c +3 -1
@@ -685,7 +685,7 @@ static int hwsim_del_edge_nl(struct sk_buff *msg, struct genl_info *info)static int hwsim_set_edge_lqi (struct sk_buff *msg,struct genl_info *info) {struct nlattr *edge_attrs[MAC802154_HWSIM_EDGE_ATTR_MAX +1 ]; -struct hwsim_edge_info *einfo; +struct hwsim_edge_info *einfo, *einfo_old;struct hwsim_phy *phy_v0;struct hwsim_edge *e;u32 v0, v1;
@@ -723,8 +723,10 @@ static int hwsim_set_edge_lqi(struct sk_buff *msg, struct genl_info *info)list_for_each_entry_rcu (e, &phy_v0->edges, list) {if (e->endpoint->idx == v1) { einfo->lqi = lqi; + einfo_old =rcu_dereference (e->info);rcu_assign_pointer (e->info, einfo);rcu_read_unlock (); +kfree_rcu (einfo_old, rcu);mutex_unlock (&hwsim_phys_lock);return 0 ; }
Signature · 1 line
2.25.1
Hi Chen,
[email protected] wrote on Fri, 7 Apr 2023 09:26:26 +0800:
Quoted 21 lines
After replacing
e->info, it is necessary to free the old einfo.Signed-off-by Chen Aotian <[email protected]>--- drivers/net/ieee802154/mac802154_hwsim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/net/ieee802154/mac802154_hwsim.c +1
-1@@ -685,7 +685,7 @@ static int hwsim_del_edge_nl(struct sk_buff *msg, struct genl_info *info)static int hwsim_set_edge_lqi (struct sk_buff *msg,struct genl_info *info) {struct nlattr *edge_attrs[MAC802154_HWSIM_EDGE_ATTR_MAX +1 ]; -struct hwsim_edge_info *einfo; +struct hwsim_edge_info *einfo, *einfo_old;struct hwsim_phy *phy_v0;struct hwsim_edge *e;u32 v0, v1;
drivers/net/ieee802154/mac802154_hwsim.c static int hwsim_set_edge_lqi(struct sk_buff *msg, struct genl_info *info) · line 732
Quoted 10 lines
drivers/net/ieee802154/mac802154_hwsim.c +2
-0@@ -723,8 +723,10 @@ static int hwsim_set_edge_lqi(struct sk_buff *msg, struct genl_info *info)list_for_each_entry_rcu (e, &phy_v0->edges, list) {if (e->endpoint->idx == v1) { einfo->lqi = lqi; + einfo_old =rcu_dereference (e->info);rcu_assign_pointer (e->info, einfo);rcu_read_unlock (); +kfree_rcu (einfo_old, rcu);mutex_unlock (&hwsim_phys_lock);return 0 ; }
I'm not an RCU expert but the fix LGTM.
What about adding:
Thanks,
Miquèl
Quoted 37 lines
[email protected] wrote on Date: Fri, 7 Apr 2023 10:01:48 +0200:
Quoted 23 lines
[email protected] wrote on Fri, 7 Apr 2023 09:26:26 +0800:
After replacing
e->info, it is necessary to free the old einfo.Signed-off-by Chen Aotian <[email protected]>--- drivers/net/ieee802154/mac802154_hwsim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/net/ieee802154/mac802154_hwsim.c +1
-1@@ -685,7 +685,7 @@ static int hwsim_del_edge_nl(struct sk_buff *msg, struct genl_info *info)static int hwsim_set_edge_lqi (struct sk_buff *msg,struct genl_info *info) {struct nlattr *edge_attrs[MAC802154_HWSIM_EDGE_ATTR_MAX +1 ]; -struct hwsim_edge_info *einfo; +struct hwsim_edge_info *einfo, *einfo_old;struct hwsim_phy *phy_v0;struct hwsim_edge *e;u32 v0, v1;drivers/net/ieee802154/mac802154_hwsim.c static int hwsim_set_edge_lqi(struct sk_buff *msg, struct genl_info *info) · line 732
Quoted 10 lines
drivers/net/ieee802154/mac802154_hwsim.c +2
-0@@ -723,8 +723,10 @@ static int hwsim_set_edge_lqi(struct sk_buff *msg, struct genl_info *info)list_for_each_entry_rcu (e, &phy_v0->edges, list) {if (e->endpoint->idx == v1) { einfo->lqi = lqi; + einfo_old =rcu_dereference (e->info);rcu_assign_pointer (e->info, einfo);rcu_read_unlock (); +kfree_rcu (einfo_old, rcu);mutex_unlock (&hwsim_phys_lock);return 0 ; }I'm not an RCU expert but the fix LGTM.
Quoted 4 lines
What about adding:
Fixes f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
Sure, I will resend this patch soon with adding those
Thanks,
Chen