* [PATCH] staging: rtl8192e: rtllib_module: Fix memory leak in alloc_rtllib
@ 2019-12-14 23:05 Navid Emamdoost
2019-12-15 13:23 ` Johan Hovold
0 siblings, 1 reply; 4+ messages in thread
From: Navid Emamdoost @ 2019-12-14 23:05 UTC (permalink / raw)
To: Greg Kroah-Hartman, Sandhya Bankar, Navid Emamdoost,
Hildo Guillardi Júnior, Hariprasad Kelam, devel,
linux-kernel
Cc: emamd001
In the implementation of alloc_rtllib() the allocated dev is leaked in
case of ieee->pHTInfo allocation failure. Release via free_netdev(dev).
Fixes: 6869a11bff1d ("Staging: rtl8192e: Use !x instead of x == NULL")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
drivers/staging/rtl8192e/rtllib_module.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
index 64d9feee1f39..18d898714c5c 100644
--- a/drivers/staging/rtl8192e/rtllib_module.c
+++ b/drivers/staging/rtl8192e/rtllib_module.c
@@ -125,7 +125,7 @@ struct net_device *alloc_rtllib(int sizeof_priv)
ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL);
if (!ieee->pHTInfo)
- return NULL;
+ goto failed;
HTUpdateDefaultSetting(ieee);
HTInitializeHTInfo(ieee);
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: rtl8192e: rtllib_module: Fix memory leak in alloc_rtllib
2019-12-14 23:05 [PATCH] staging: rtl8192e: rtllib_module: Fix memory leak in alloc_rtllib Navid Emamdoost
@ 2019-12-15 13:23 ` Johan Hovold
2019-12-16 2:42 ` Navid Emamdoost
0 siblings, 1 reply; 4+ messages in thread
From: Johan Hovold @ 2019-12-15 13:23 UTC (permalink / raw)
To: Navid Emamdoost
Cc: Greg Kroah-Hartman, Sandhya Bankar, Hildo Guillardi Júnior,
Hariprasad Kelam, devel, linux-kernel, emamd001
On Sat, Dec 14, 2019 at 05:05:58PM -0600, Navid Emamdoost wrote:
> In the implementation of alloc_rtllib() the allocated dev is leaked in
> case of ieee->pHTInfo allocation failure. Release via free_netdev(dev).
>
> Fixes: 6869a11bff1d ("Staging: rtl8192e: Use !x instead of x == NULL")
This is not the commit that introduced this issue.
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
> drivers/staging/rtl8192e/rtllib_module.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
> index 64d9feee1f39..18d898714c5c 100644
> --- a/drivers/staging/rtl8192e/rtllib_module.c
> +++ b/drivers/staging/rtl8192e/rtllib_module.c
> @@ -125,7 +125,7 @@ struct net_device *alloc_rtllib(int sizeof_priv)
>
> ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL);
> if (!ieee->pHTInfo)
> - return NULL;
> + goto failed;
And you're still leaking ieee->networks and possibly a bunch of other
allocations here. You need to call at least rtllib_networks_free() in
the error path.
>
> HTUpdateDefaultSetting(ieee);
> HTInitializeHTInfo(ieee);
Johan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: rtl8192e: rtllib_module: Fix memory leak in alloc_rtllib
2019-12-15 13:23 ` Johan Hovold
@ 2019-12-16 2:42 ` Navid Emamdoost
2019-12-16 14:43 ` Johan Hovold
0 siblings, 1 reply; 4+ messages in thread
From: Navid Emamdoost @ 2019-12-16 2:42 UTC (permalink / raw)
To: Johan Hovold
Cc: Greg Kroah-Hartman, Sandhya Bankar, Hildo Guillardi Júnior,
Hariprasad Kelam, devel, LKML, Navid Emamdoost
Hi Johan,
On Sun, Dec 15, 2019 at 7:23 AM Johan Hovold <johan@kernel.org> wrote:
>
> On Sat, Dec 14, 2019 at 05:05:58PM -0600, Navid Emamdoost wrote:
> > In the implementation of alloc_rtllib() the allocated dev is leaked in
> > case of ieee->pHTInfo allocation failure. Release via free_netdev(dev).
> >
> > Fixes: 6869a11bff1d ("Staging: rtl8192e: Use !x instead of x == NULL")
>
> This is not the commit that introduced this issue.
Oops! That should be 94a799425eee8
>
> > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> > ---
> > drivers/staging/rtl8192e/rtllib_module.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
> > index 64d9feee1f39..18d898714c5c 100644
> > --- a/drivers/staging/rtl8192e/rtllib_module.c
> > +++ b/drivers/staging/rtl8192e/rtllib_module.c
> > @@ -125,7 +125,7 @@ struct net_device *alloc_rtllib(int sizeof_priv)
> >
> > ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL);
> > if (!ieee->pHTInfo)
> > - return NULL;
> > + goto failed;
>
> And you're still leaking ieee->networks and possibly a bunch of other
> allocations here. You need to call at least rtllib_networks_free() in
> the error path.
I'm not familiar with this code, but based on your hint I believe
there should be something like free_rtllib() here, right?
More specifically, rtllib_softmac_free() and
lib80211_crypt_info_free() are needed along with
rtllib_networks_free(). If you confirm that it works I can go ahead to
prepare patch v2 with these releases.
>
> >
> > HTUpdateDefaultSetting(ieee);
> > HTInitializeHTInfo(ieee);
>
> Johan
--
Navid.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: rtl8192e: rtllib_module: Fix memory leak in alloc_rtllib
2019-12-16 2:42 ` Navid Emamdoost
@ 2019-12-16 14:43 ` Johan Hovold
0 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2019-12-16 14:43 UTC (permalink / raw)
To: Navid Emamdoost
Cc: Johan Hovold, Greg Kroah-Hartman, Sandhya Bankar,
Hildo Guillardi Júnior, Hariprasad Kelam, devel, LKML,
Navid Emamdoost
On Sun, Dec 15, 2019 at 08:42:47PM -0600, Navid Emamdoost wrote:
> Hi Johan,
>
> On Sun, Dec 15, 2019 at 7:23 AM Johan Hovold <johan@kernel.org> wrote:
> >
> > On Sat, Dec 14, 2019 at 05:05:58PM -0600, Navid Emamdoost wrote:
> > > In the implementation of alloc_rtllib() the allocated dev is leaked in
> > > case of ieee->pHTInfo allocation failure. Release via free_netdev(dev).
> > >
> > > Fixes: 6869a11bff1d ("Staging: rtl8192e: Use !x instead of x == NULL")
> >
> > This is not the commit that introduced this issue.
> Oops! That should be 94a799425eee8
>
> >
> > > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> > > ---
> > > drivers/staging/rtl8192e/rtllib_module.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/staging/rtl8192e/rtllib_module.c b/drivers/staging/rtl8192e/rtllib_module.c
> > > index 64d9feee1f39..18d898714c5c 100644
> > > --- a/drivers/staging/rtl8192e/rtllib_module.c
> > > +++ b/drivers/staging/rtl8192e/rtllib_module.c
> > > @@ -125,7 +125,7 @@ struct net_device *alloc_rtllib(int sizeof_priv)
> > >
> > > ieee->pHTInfo = kzalloc(sizeof(struct rt_hi_throughput), GFP_KERNEL);
> > > if (!ieee->pHTInfo)
> > > - return NULL;
> > > + goto failed;
> >
> > And you're still leaking ieee->networks and possibly a bunch of other
> > allocations here. You need to call at least rtllib_networks_free() in
> > the error path.
> I'm not familiar with this code, but based on your hint I believe
> there should be something like free_rtllib() here, right?
Right.
> More specifically, rtllib_softmac_free() and
> lib80211_crypt_info_free() are needed along with
> rtllib_networks_free(). If you confirm that it works I can go ahead to
> prepare patch v2 with these releases.
I can't confirm anything, that's your job. ;)
You need to trace the calls and allocations made in in alloc_rtllib()
and make sure everything is released on errors. For a well-designed
subsystem and driver this should end up looking a lot like the release
function (free_rtllib()), but that's unfortunately not always the case.
Judging from a quick look at least rtllib_softmac_free() is also needed
besides rtllib_networks_free(). And you probably want
lib80211_crypt_info_free() as well for consistency even if the
corresponding init functions doesn't seem to do any allocations
currently.
Johan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-12-16 14:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-14 23:05 [PATCH] staging: rtl8192e: rtllib_module: Fix memory leak in alloc_rtllib Navid Emamdoost
2019-12-15 13:23 ` Johan Hovold
2019-12-16 2:42 ` Navid Emamdoost
2019-12-16 14:43 ` Johan Hovold
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).