usb: gadget: tegra-xudc: Fix possible use-after-free in tegra_xudc_remove()
authorYang Yingliang <yangyingliang@huawei.com>
Wed, 7 Apr 2021 09:29:47 +0000 (17:29 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 May 2021 12:47:20 +0000 (14:47 +0200)
commit015f3f25213ea69d4106f488559b088dcc67b3f4
tree4da5706f886d89ec746c958176cfa6c75d624416
parent0e73535a496c6c52e56137a61e2476368d7aec52
usb: gadget: tegra-xudc: Fix possible use-after-free in tegra_xudc_remove()

[ Upstream commit a932ee40c276767cd55fadec9e38829bf441db41 ]

This driver's remove path calls cancel_delayed_work(). However, that
function does not wait until the work function finishes. This means
that the callback function may still be running after the driver's
remove function has finished, which would result in a use-after-free.

Fix by calling cancel_delayed_work_sync(), which ensures that
the work is properly cancelled, no longer running, and unable
to re-schedule itself.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20210407092947.3271507-1-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/gadget/udc/tegra-xudc.c