Commit 45e7a91
usb: cdns3: gadget: Use-after-free during failed initialization and exit of cdnsp gadget
[ Upstream commit 87c5ff5 ]
In the __cdnsp_gadget_init() and cdnsp_gadget_exit() functions, the gadget
structure (pdev->gadget) was freed before its endpoints.
The endpoints are linked via the ep_list in the gadget structure.
Freeing the gadget first leaves dangling pointers in the endpoint list.
When the endpoints are subsequently freed, this results in a use-after-free.
Fix:
By separating the usb_del_gadget_udc() operation into distinct "del" and
"put" steps, cdnsp_gadget_free_endpoints() can be executed prior to the
final release of the gadget structure with usb_put_gadget().
A patch similar to bb9c74a("usb: dwc3: gadget: Free gadget structure
only after freeing endpoints").
Signed-off-by: Chen Yufeng <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
(cherry picked from commit ea37884097a0931abb8e11e40eacfb25e9fdb5e9)
Signed-off-by: Wentao Guan <[email protected]>1 parent f15d443 commit 45e7a91
1 file changed
+6
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1975 | 1975 | | |
1976 | 1976 | | |
1977 | 1977 | | |
1978 | | - | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
1979 | 1982 | | |
1980 | 1983 | | |
1981 | 1984 | | |
| |||
1997 | 2000 | | |
1998 | 2001 | | |
1999 | 2002 | | |
2000 | | - | |
| 2003 | + | |
2001 | 2004 | | |
| 2005 | + | |
2002 | 2006 | | |
2003 | 2007 | | |
2004 | 2008 | | |
| |||
0 commit comments