USB: UDC core: fix double-free in usb_add_gadget_udc_release
authorAlan Stern <stern@rowland.harvard.edu>
Wed, 3 Jan 2018 17:51:51 +0000 (12:51 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Jan 2018 08:45:26 +0000 (09:45 +0100)
commit2817c4c8fc1feab053b2e21f15bc040c3828d304
tree1a293f2e734e513525d8a85cee054f206baeb8c0
parent204d8fb1b417732359338ec0eae6eb16ff854bcc
USB: UDC core: fix double-free in usb_add_gadget_udc_release

commit 7ae2c3c280db183ca9ada2675c34ec2f7378abfa upstream.

The error-handling pathways in usb_add_gadget_udc_release() are messed
up.  Aside from the uninformative statement labels, they can deallocate
the udc structure after calling put_device(), which is a double-free.
This was observed by KASAN in automatic testing.

This patch cleans up the routine.  It preserves the requirement that
when any failure occurs, we call put_device(&gadget->dev).

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Reviewed-by: Peter Chen <peter.chen@nxp.com>
Acked-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/udc/core.c