]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commit
usb: gadget: configfs: Fix memory leak of interface directory data
authorAndrew Gabbasov <andrew_gabbasov@mentor.com>
Sat, 30 Sep 2017 15:54:52 +0000 (08:54 -0700)
committerSeth Forshee <seth.forshee@canonical.com>
Thu, 19 Oct 2017 14:49:38 +0000 (09:49 -0500)
commit50b132a659a39fbbcaafccc89f7ad84106ae179a
tree50083415763a9e6f83406ebb6132d741b058263a
parent63dcad5da97f4a2db28c6428a56852dd615c794a
usb: gadget: configfs: Fix memory leak of interface directory data

BugLink: http://bugs.launchpad.net/bugs/1724669
commit ff74745e6d3d97a865eda8c1f3fd29c13b79f0cc upstream.

Kmemleak checking configuration reports a memory leak in
usb_os_desc_prepare_interf_dir function when rndis function
instance is freed and then allocated again. For example, this
happens with FunctionFS driver with RNDIS function enabled
when "ffs-test" test application is run several times in a row.

The data for intermediate "os_desc" group for interface directories
is allocated as a single VLA chunk and (after a change of default
groups handling) is not ever freed and actually not stored anywhere
besides inside a list of default groups of a parent group.

The fix is to make usb_os_desc_prepare_interf_dir function return
a pointer to allocated data (as a pointer to the first VLA item)
instead of (an unused) integer and to make the caller component
(currently the only one is RNDIS function) responsible for storing
the pointer and freeing the memory when appropriate.

Fixes: 1ae1602de028 ("configfs: switch ->default groups to a linked list")
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
drivers/usb/gadget/configfs.c
drivers/usb/gadget/configfs.h
drivers/usb/gadget/function/f_rndis.c
drivers/usb/gadget/function/u_rndis.h