* [PATCH] ieee802154: hwsim: Fix possible memory leaks
@ 2023-04-07 1:26 Chen Aotian
2023-04-07 8:01 ` Miquel Raynal
0 siblings, 1 reply; 7+ messages in thread
From: Chen Aotian @ 2023-04-07 1:26 UTC (permalink / raw)
To: alex.aring
Cc: stefan, miquel.raynal, davem, edumazet, kuba, pabeni, linux-wpan,
netdev, linux-kernel, Chen Aotian
After replacing e->info, it is necessary to free the old einfo.
Signed-off-by: Chen Aotian <chenaotian2@163.com>
---
drivers/net/ieee802154/mac802154_hwsim.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
index 8445c2189..6e7e10b17 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;
+ 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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ieee802154: hwsim: Fix possible memory leaks
2023-04-07 1:26 [PATCH] ieee802154: hwsim: Fix possible memory leaks Chen Aotian
@ 2023-04-07 8:01 ` Miquel Raynal
2023-04-07 9:48 ` Chen Aotian
0 siblings, 1 reply; 7+ messages in thread
From: Miquel Raynal @ 2023-04-07 8:01 UTC (permalink / raw)
To: Chen Aotian
Cc: alex.aring, stefan, davem, edumazet, kuba, pabeni, linux-wpan,
netdev, linux-kernel
Hi Chen,
chenaotian2@163.com 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 <chenaotian2@163.com>
> ---
> drivers/net/ieee802154/mac802154_hwsim.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
> index 8445c2189..6e7e10b17 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;
> + 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.
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
What about adding:
Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
Cc: stable@vger.kernelorg
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ieee802154: hwsim: Fix possible memory leaks
2023-04-07 8:01 ` Miquel Raynal
@ 2023-04-07 9:48 ` Chen Aotian
0 siblings, 0 replies; 7+ messages in thread
From: Chen Aotian @ 2023-04-07 9:48 UTC (permalink / raw)
To: miquel.raynal
Cc: alex.aring, chenaotian2, davem, edumazet, kuba, linux-kernel,
linux-wpan, netdev, pabeni, stefan
> miquel.raynal@bootlin.com wrote on Date: Fri, 7 Apr 2023 10:01:48 +0200:
> > chenaotian2@163.com 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 <chenaotian2@163.com>
> > ---
> > drivers/net/ieee802154/mac802154_hwsim.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
> > index 8445c2189..6e7e10b17 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;
> > + 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:
> Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
> Cc: stable@vger.kernelorg
Sure, I will resend this patch soon with adding those
Thanks,
Chen
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] ieee802154: hwsim: Fix possible memory leaks
@ 2023-04-07 9:53 Chen Aotian
2023-04-07 13:46 ` Miquel Raynal
2023-04-07 22:20 ` Alexander Aring
0 siblings, 2 replies; 7+ messages in thread
From: Chen Aotian @ 2023-04-07 9:53 UTC (permalink / raw)
To: alex.aring
Cc: stefan, miquel.raynal, davem, edumazet, kuba, pabeni, linux-wpan,
netdev, linux-kernel, stable, Chen Aotian
After replacing e->info, it is necessary to free the old einfo.
Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
Signed-off-by: Chen Aotian <chenaotian2@163.com>
---
drivers/net/ieee802154/mac802154_hwsim.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
index 8445c2189..6e7e10b17 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;
+ 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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ieee802154: hwsim: Fix possible memory leaks
2023-04-07 9:53 Chen Aotian
@ 2023-04-07 13:46 ` Miquel Raynal
2023-04-07 22:20 ` Alexander Aring
1 sibling, 0 replies; 7+ messages in thread
From: Miquel Raynal @ 2023-04-07 13:46 UTC (permalink / raw)
To: Chen Aotian
Cc: alex.aring, stefan, davem, edumazet, kuba, pabeni, linux-wpan,
netdev, linux-kernel
Hi Chen,
(resending my answer since apparently the first time it failed)
chenaotian2@163.com wrote on Fri, 7 Apr 2023 17:53:01 +0800:
> After replacing e->info, it is necessary to free the old einfo.
The title should contain:
- wpan (that's the tree you target, use --subject-prefix="PATCH wpan"
of git-format-patch)
- v2 (because that's a new version, use the -v2 option of
git-format-patch)
Apparently I mis-wrote the stable address, just add this line to the
commit:
Cc: stable@vger.kernel.org
(right now you sent it to stable@vger.kernelorg which is incorrect,
sorry for the typo)
> Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
And please carry the tags:
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
> Signed-off-by: Chen Aotian <chenaotian2@163.com>
> ---
> drivers/net/ieee802154/mac802154_hwsim.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
> index 8445c2189..6e7e10b17 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;
> + 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;
> }
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ieee802154: hwsim: Fix possible memory leaks
2023-04-07 9:53 Chen Aotian
2023-04-07 13:46 ` Miquel Raynal
@ 2023-04-07 22:20 ` Alexander Aring
2023-04-08 6:43 ` Chen Aotian
1 sibling, 1 reply; 7+ messages in thread
From: Alexander Aring @ 2023-04-07 22:20 UTC (permalink / raw)
To: Chen Aotian
Cc: alex.aring, stefan, miquel.raynal, davem, edumazet, kuba, pabeni,
linux-wpan, netdev, linux-kernel, stable
Hi,
On Fri, Apr 7, 2023 at 5:55 AM Chen Aotian <chenaotian2@163.com> wrote:
>
> After replacing e->info, it is necessary to free the old einfo.
>
> Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
> Signed-off-by: Chen Aotian <chenaotian2@163.com>
> ---
> drivers/net/ieee802154/mac802154_hwsim.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
> index 8445c2189..6e7e10b17 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;
> + einfo_old = rcu_dereference(e->info);
> rcu_assign_pointer(e->info, einfo);
nitpick rcu_replace_pointer() can be used here.*
- Alex
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ieee802154: hwsim: Fix possible memory leaks
2023-04-07 22:20 ` Alexander Aring
@ 2023-04-08 6:43 ` Chen Aotian
0 siblings, 0 replies; 7+ messages in thread
From: Chen Aotian @ 2023-04-08 6:43 UTC (permalink / raw)
To: aahringo, miquel.raynal
Cc: alex.aring, chenaotian2, davem, edumazet, kuba, linux-kernel,
linux-wpan, netdev, pabeni, stable, stefan
Fri, 7 Apr 2023 18:20:32 -0400 Alexander Aring <aahringo@redhat.com> wrote:
>
> On Fri, Apr 7, 2023 at 5:55 AM Chen Aotian <chenaotian2@163.com> wrote:
> >
> > After replacing e->info, it is necessary to free the old einfo.
> >
> > Fixes: f25da51fdc38 ("ieee802154: hwsim: add replacement for fakelb")
> > Signed-off-by: Chen Aotian <chenaotian2@163.com>
> > ---
> > drivers/net/ieee802154/mac802154_hwsim.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ieee802154/mac802154_hwsim.c b/drivers/net/ieee802154/mac802154_hwsim.c
> > index 8445c2189..6e7e10b17 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;
> > + einfo_old = rcu_dereference(e->info);
> > rcu_assign_pointer(e->info, einfo);
>
> nitpick rcu_replace_pointer() can be used here.*
Thank you for your suggestion, Alex. BTW, thanks for Miquèl's patient
guidance too, I just started trying to submit patches to the kernel,
I will do batter.
Thanks,
Chen
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-04-08 6:45 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-07 1:26 [PATCH] ieee802154: hwsim: Fix possible memory leaks Chen Aotian
2023-04-07 8:01 ` Miquel Raynal
2023-04-07 9:48 ` Chen Aotian
-- strict thread matches above, loose matches on Subject: below --
2023-04-07 9:53 Chen Aotian
2023-04-07 13:46 ` Miquel Raynal
2023-04-07 22:20 ` Alexander Aring
2023-04-08 6:43 ` Chen Aotian
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).