Commit 6a19da1
usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait
While performing fast composition switch, there is a possibility that the
process of ffs_ep0_write/ffs_ep0_read get into a race condition
due to ep0req being freed up from functionfs_unbind.
Consider the scenario that the ffs_ep0_write calls the ffs_ep0_queue_wait
by taking a lock &ffs->ev.waitq.lock. However, the functionfs_unbind isn't
bounded so it can go ahead and mark the ep0req to NULL, and since there
is no NULL check in ffs_ep0_queue_wait we will end up in use-after-free.
Fix this by making a serialized execution between the two functions using
a mutex_lock(ffs->mutex).
Fixes: ddf8abd ("USB: f_fs: the FunctionFS driver")
Signed-off-by: Udipto Goswami <[email protected]>
Tested-by: Krishna Kurapati <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>1 parent cde3788 commit 6a19da1
1 file changed
+5
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
282 | 285 | | |
283 | 286 | | |
284 | 287 | | |
| |||
1892 | 1895 | | |
1893 | 1896 | | |
1894 | 1897 | | |
| 1898 | + | |
1895 | 1899 | | |
1896 | 1900 | | |
1897 | 1901 | | |
1898 | 1902 | | |
| 1903 | + | |
1899 | 1904 | | |
1900 | 1905 | | |
1901 | 1906 | | |
| |||
0 commit comments