linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc()
@ 2022-09-09 11:44 xkernel.wang
  2022-09-09 17:31 ` Philipp Hortmann
  0 siblings, 1 reply; 3+ messages in thread
From: xkernel.wang @ 2022-09-09 11:44 UTC (permalink / raw)
  To: Larry.Finger, phil, gregkh; +Cc: linux-staging, linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

In rtw_os_xmit_resource_alloc(), if usb_alloc_urb() fails, then the
memory `pxmitbuf_pallocated_buf` which is allocated by kzalloc() is not
properly released before returning.

So this patch add kfree() on the above error path to release it. As there
is no proper device to test with, no runtime testing was performed.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
ChangeLog:
v1->v2 update the description.
v2->v3 rebase.
v3->v4 update the description.
 drivers/staging/r8188eu/os_dep/xmit_linux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/r8188eu/os_dep/xmit_linux.c b/drivers/staging/r8188eu/os_dep/xmit_linux.c
index 89a598a..f25099d 100644
--- a/drivers/staging/r8188eu/os_dep/xmit_linux.c
+++ b/drivers/staging/r8188eu/os_dep/xmit_linux.c
@@ -75,8 +75,10 @@ int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitb
 	pxmitbuf->dma_transfer_addr = 0;
 
 	pxmitbuf->pxmit_urb = usb_alloc_urb(0, GFP_KERNEL);
-	if (!pxmitbuf->pxmit_urb)
+	if (!pxmitbuf->pxmit_urb) {
+		kfree(pxmitbuf->pallocated_buf);
 		return _FAIL;
+	}
 
 	return _SUCCESS;
 }
-- 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc()
  2022-09-09 11:44 [PATCH v4] staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc() xkernel.wang
@ 2022-09-09 17:31 ` Philipp Hortmann
  2022-09-10  0:06   ` Xiaoke Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Philipp Hortmann @ 2022-09-09 17:31 UTC (permalink / raw)
  To: xkernel.wang, Larry.Finger, phil, gregkh; +Cc: linux-staging, linux-kernel

On 9/9/22 13:44, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
> 
> In rtw_os_xmit_resource_alloc(), if usb_alloc_urb() fails, then the
> memory `pxmitbuf_pallocated_buf` which is allocated by kzalloc() is not
> properly released before returning.
> 
> So this patch add kfree() on the above error path to release it. As there
> is no proper device to test with, no runtime testing was performed.
> 
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
> ChangeLog:
> v1->v2 update the description.
> v2->v3 rebase.
> v3->v4 update the description.
>   drivers/staging/r8188eu/os_dep/xmit_linux.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/r8188eu/os_dep/xmit_linux.c b/drivers/staging/r8188eu/os_dep/xmit_linux.c
> index 89a598a..f25099d 100644
> --- a/drivers/staging/r8188eu/os_dep/xmit_linux.c
> +++ b/drivers/staging/r8188eu/os_dep/xmit_linux.c
> @@ -75,8 +75,10 @@ int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitb
>   	pxmitbuf->dma_transfer_addr = 0;
>   
>   	pxmitbuf->pxmit_urb = usb_alloc_urb(0, GFP_KERNEL);
> -	if (!pxmitbuf->pxmit_urb)
> +	if (!pxmitbuf->pxmit_urb) {
> +		kfree(pxmitbuf->pallocated_buf);
>   		return _FAIL;
> +	}
>   
>   	return _SUCCESS;
>   }

Hi,

I cannot apply your patch:

kernel@matrix-ESPRIMO-P710:~/Documents/git/kernels/staging$ cat 
~/Downloads/\[PATCH\ v4\]\ staging\ r8188eu\ fix\ potential\ memory\ 
leak\ in\ rtw_os_xmit_resource_alloc\(\).eml | git am
Applying: staging: r8188eu: fix potential memory leak in 
rtw_os_xmit_resource_alloc()
error: drivers/staging/r8188eu/os_dep/xmit_linux.c: does not exist in index
Patch failed at 0001 staging: r8188eu: fix potential memory leak in 
rtw_os_xmit_resource_alloc()

branch: staging-next
repository: git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git

Sorry

Bye Philipp

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc()
  2022-09-09 17:31 ` Philipp Hortmann
@ 2022-09-10  0:06   ` Xiaoke Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Xiaoke Wang @ 2022-09-10  0:06 UTC (permalink / raw)
  To: Philipp Hortmann
  Cc: xkernel.wang, Larry.Finger, phil, gregkh, linux-staging, linux-kernel

On Sat, Sep 10, 2022 01:31 AM, philipp.g.hortmann@gmail.com wrote:
&gt; Hi,
&gt; 
&gt; I cannot apply your patch:
&gt; 
&gt; kernel@matrix-ESPRIMO-P710:~/Documents/git/kernels/staging$ cat
&gt; ~/Downloads/\[PATCH\ v4\]\ staging\ r8188eu\ fix\ potential\ memory\
&gt; leak\ in\ rtw_os_xmit_resource_alloc\(\).eml | git am
&gt; Applying: staging: r8188eu: fix potential memory leak in
&gt; rtw_os_xmit_resource_alloc()
&gt; error: drivers/staging/r8188eu/os_dep/xmit_linux.c: does not exist in index
&gt; Patch failed at 0001 staging: r8188eu: fix potential memory leak in
&gt; rtw_os_xmit_resource_alloc()
&gt; 
&gt; branch: staging-next
&gt; repository: git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git

Oh, sorry. I rebased according to the main branch.
I noticed that in staging-next, the original code has been moved to
"drivers/staging/r8188eu/core/rtw_xmit.c".
Later I will rebase and resend it.

Regards,
Xiaoke Wang

&gt; 
&gt; Sorry
&gt; 
&gt; Bye Philipp

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-10  0:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 11:44 [PATCH v4] staging: r8188eu: fix potential memory leak in rtw_os_xmit_resource_alloc() xkernel.wang
2022-09-09 17:31 ` Philipp Hortmann
2022-09-10  0:06   ` Xiaoke Wang

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).