* [PATH wpan v3] ieee802154: hwsim: Fix possible memory leaks
@ 2023-04-09 2:20 Chen Aotian
2023-04-09 2:23 ` kernel test robot
2023-04-12 19:48 ` Stefan Schmidt
0 siblings, 2 replies; 3+ messages in thread
From: Chen Aotian @ 2023-04-09 2:20 UTC (permalink / raw)
To: alex.aring
Cc: stefan, miquel.raynal, davem, edumazet, kuba, pabeni, linux-wpan,
netdev, linux-kernel, stable, Chen Aotian, Alexander Aring
After replacing e->info, it is necessary to free the old einfo.
Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Alexander Aring <aahringo@redhat.com>
Signed-off-by: Chen Aotian <chenaotian2@163.com>
---
V2 -> V3:
* lock_is_held() => lockdep_is_held().(thanks for Alexander)
V1 -> V2:
* Using rcu_replace_pointer() is better then rcu_dereference()
and rcu_assign_pointer().
drivers/net/ieee802154/mac802154_hwsim.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
index 8445c2189..31cba9aa7 100644
--- a/drivers/net/ieee802154/mac802154_hwsim.c
+++ b/drivers/net/ieee802154/mac802154_hwsim.c
@@ -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;
- rcu_assign_pointer(e->info, einfo);
+ einfo_old = rcu_replace_pointer(e->info, einfo,
+ lockdep_is_held(&hwsim_phys_lock));
rcu_read_unlock();
+ kfree_rcu(einfo_old, rcu);
mutex_unlock(&hwsim_phys_lock);
return 0;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATH wpan v3] ieee802154: hwsim: Fix possible memory leaks
2023-04-09 2:20 [PATH wpan v3] ieee802154: hwsim: Fix possible memory leaks Chen Aotian
@ 2023-04-09 2:23 ` kernel test robot
2023-04-12 19:48 ` Stefan Schmidt
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2023-04-09 2:23 UTC (permalink / raw)
To: Chen Aotian; +Cc: stable, oe-kbuild-all
Hi,
Thanks for your patch.
FYI: kernel test robot notices the stable kernel rule is not satisfied.
Rule: 'Cc: stable@vger.kernel.org' or 'commit <sha1> upstream.'
Subject: [PATH wpan v3] ieee802154: hwsim: Fix possible memory leaks
Link: https://lore.kernel.org/stable/20230409022048.61223-1-chenaotian2%40163.com
The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATH wpan v3] ieee802154: hwsim: Fix possible memory leaks
2023-04-09 2:20 [PATH wpan v3] ieee802154: hwsim: Fix possible memory leaks Chen Aotian
2023-04-09 2:23 ` kernel test robot
@ 2023-04-12 19:48 ` Stefan Schmidt
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Schmidt @ 2023-04-12 19:48 UTC (permalink / raw)
To: Chen Aotian, alex.aring
Cc: miquel.raynal, davem, edumazet, kuba, pabeni, linux-wpan, netdev,
linux-kernel, stable, Alexander Aring
Hello.
On 09.04.23 04:20, Chen Aotian wrote:
> After replacing e->info, it is necessary to free the old einfo.
>
> Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
> Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
> Reviewed-by: Alexander Aring <aahringo@redhat.com>
> Signed-off-by: Chen Aotian <chenaotian2@163.com>
> ---
>
> V2 -> V3:
> * lock_is_held() => lockdep_is_held().(thanks for Alexander)
>
> V1 -> V2:
> * Using rcu_replace_pointer() is better then rcu_dereference()
> and rcu_assign_pointer().
>
> drivers/net/ieee802154/mac802154_hwsim.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
> index 8445c2189..31cba9aa7 100644
> --- a/drivers/net/ieee802154/mac802154_hwsim.c
> +++ b/drivers/net/ieee802154/mac802154_hwsim.c
> @@ -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;
> - rcu_assign_pointer(e->info, einfo);
> + einfo_old = rcu_replace_pointer(e->info, einfo,
> + lockdep_is_held(&hwsim_phys_lock));
> rcu_read_unlock();
> + kfree_rcu(einfo_old, rcu);
> mutex_unlock(&hwsim_phys_lock);
> return 0;
> }
This patch has been applied to the wpan tree and will be
part of the next pull request to net. Thanks!
regards
Stefan Schmidt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-12 19:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-09 2:20 [PATH wpan v3] ieee802154: hwsim: Fix possible memory leaks Chen Aotian
2023-04-09 2:23 ` kernel test robot
2023-04-12 19:48 ` Stefan Schmidt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).