usb: gadget: composite: Fix use-after-free in usb_composite_overwrite_options
authorAndrew Gabbasov <andrew_gabbasov@mentor.com>
Sat, 30 Sep 2017 15:55:55 +0000 (08:55 -0700)
committerDanny Wood <danwood76@gmail.com>
Tue, 29 Jan 2019 13:18:39 +0000 (13:18 +0000)
commitf700b1dabe6fec54fc98c9e39382b5be7f318f6a
tree92ba72d098a8ba55ce59d6f4cb1eba18887b4cf5
parentff73955e30b8e8dea918801a249f53b58565d8ba
usb: gadget: composite: Fix use-after-free in usb_composite_overwrite_options

commit aec17e1e249567e82b26dafbb86de7d07fde8729 upstream.

KASAN enabled configuration reports an error

    BUG: KASAN: use-after-free in usb_composite_overwrite_options+...
                [libcomposite] at addr ...
    Read of size 1 by task ...

when some driver is un-bound and then bound again.
For example, this happens with FunctionFS driver when "ffs-test"
test application is run several times in a row.

If the driver has empty manufacturer ID string in initial static data,
it is then replaced with generated string. After driver unbinding
the generated string is freed, but the driver data still keep that
pointer. And if the driver is then bound again, that pointer
is re-used for string emptiness check.

The fix is to clean up the driver string data upon its unbinding
to drop the pointer to freed memory.

Fixes: cc2683c318a5 ("usb: gadget: Provide a default implementation of default manufacturer string")
Cc: stable@vger.kernel.org
Signed-off-by: Andrew Gabbasov <andrew_gabbasov@mentor.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/usb/gadget/composite.c