[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGXu5jJofYcisFUiNavprO3Si3n=VXvabNrNzQcN0pcy_XQZtA@mail.gmail.com>
Date: Fri, 15 Jun 2018 09:47:59 -0700
From: Kees Cook <keescook@...omium.org>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Zhouyang Jia <jiazhouyang09@...il.com>, devel@...verdev.osuosl.org,
LKML <linux-kernel@...r.kernel.org>,
Jia-Ju Bai <baijiaju1990@...il.com>,
Christophe JAILLET <christophe.jaillet@...adoo.fr>,
Shreeya Patel <shreeya.patel23498@...il.com>,
Colin Ian King <colin.king@...onical.com>
Subject: Re: [PATCH v2] staging: rtl8192u: add error handling for usb_alloc_urb
On Fri, Jun 15, 2018 at 9:47 AM, Kees Cook <keescook@...omium.org> wrote:
> On Fri, Jun 15, 2018 at 9:33 AM, Greg Kroah-Hartman
> <gregkh@...uxfoundation.org> wrote:
>> On Sat, Jun 16, 2018 at 12:25:23AM +0800, Zhouyang Jia wrote:
>>> When usb_alloc_urb fails, the lack of error-handling code may
>>> cause unexpected results.
>>>
>>> This patch adds error-handling code after calling usb_alloc_urb.
>>>
>>> Signed-off-by: Zhouyang Jia <jiazhouyang09@...il.com>
>>> ---
>>> v1->v2:
>>> - Fix memory leak.
>>> ---
>>> drivers/staging/rtl8192u/r8192U_core.c | 18 +++++++++++++++---
>>> 1 file changed, 15 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
>>> index 7a0dbc0..6afab4e 100644
>>> --- a/drivers/staging/rtl8192u/r8192U_core.c
>>> +++ b/drivers/staging/rtl8192u/r8192U_core.c
>>> @@ -1648,13 +1648,17 @@ static short rtl8192_usb_initendpoints(struct net_device *dev)
>>> #ifndef JACKSON_NEW_RX
>>> for (i = 0; i < (MAX_RX_URB + 1); i++) {
>>> priv->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
>>> - if (!priv->rx_urb[i])
>>> + if (!priv->rx_urb[i]) {
>>> + kfree(priv->rx_urb);
>
> You're freeing rx_urb, which holds all the pointers to allocated
> memory. You'll need to free each item of the array before freeing the
> array itself:
>
> for (i = 0; i < (MAX_RX_URB + 1); i++)
> kfree(priv->rx_urb[i]);
> kfree(priv->rx_urb);
>
> I think you need some kind of helper to do this, and you can call into
> it from your error paths...
(Though if you do this, rx_urb must be zero-initialized, so change the
kmalloc_array() to kcalloc()...)
-Kees
>
> -Kees
>
>> {sigh}
>>
>> No, you are still leaking memory on all of these changes that you just
>> made :(
>>
>> greg k-h
>
>
>
> --
> Kees Cook
> Pixel Security
--
Kees Cook
Pixel Security
Powered by blists - more mailing lists