lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20200226101212.GX32540@localhost>
Date:   Wed, 26 Feb 2020 11:12:12 +0100
From:   Johan Hovold <johan@...nel.org>
To:     Tiezhu Yang <yangtiezhu@...ngson.cn>
Cc:     Johan Hovold <johan@...nel.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org,
        Xuefeng Li <lixuefeng@...ngson.cn>
Subject: Re: [PATCH 2/2] USB: core: Fix potential memory leak in
 usb_get_configuration()

On Wed, Feb 26, 2020 at 04:42:55PM +0800, Tiezhu Yang wrote:
> On 02/26/2020 04:09 PM, Johan Hovold wrote:
> > On Wed, Feb 26, 2020 at 02:15:23PM +0800, Tiezhu Yang wrote:
> >> Make sure to free all the allocated memory before exiting from the function
> >> usb_get_configuration() when an error is encountered.
> > There's no leak in this function as far as I can tell. Any allocated
> > memory is released in usb_destroy_configuration() when the last
> > reference to the struct usb_device is dropped.
> 
> Yes, you are right, the allocated memory in usb_get_configuration()
> will be released in usb_destroy_configuration().
> 
> By the way, is it better to release the allocated memory as early as 
> possible
> in usb_get_configuration()? Just like this:
> 
> diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
> index bb63ee0..dd4ebeb 100644
> --- a/drivers/usb/core/config.c
> +++ b/drivers/usb/core/config.c
> @@ -885,12 +885,17 @@ int usb_get_configuration(struct usb_device *dev)
> 
>          length = ncfg * sizeof(char *);
>          dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
> -       if (!dev->rawdescriptors)
> +       if (!dev->rawdescriptors) {
> +               kfree(dev->config);
>                  return -ENOMEM;
> +       }

No, there's no point in that. And just like your original proposal, this
would also introduce a double free.

Johan

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ