Skip to content

Commit cdafb6d

Browse files
agabbasovgregkh
authored andcommitted
usb: gadget: f_fs: Fix use-after-free in ffs_free_inst
KASAN enabled configuration reports an error BUG: KASAN: use-after-free in ffs_free_inst+... [usb_f_fs] at addr ... Write of size 8 by task ... This is observed after "ffs-test" is run and interrupted. If after that functionfs is unmounted and g_ffs module is unloaded, that use-after-free occurs during g_ffs module removal. Although the report indicates ffs_free_inst() function, the actual use-after-free condition occurs in _ffs_free_dev() function, which is probably inlined into ffs_free_inst(). This happens due to keeping the ffs_data reference in device structure during functionfs unmounting, while ffs_data itself is freed as no longer needed. The fix is to clear that reference in ffs_closed() function, which is a counterpart of ffs_ready(), where the reference is stored. Fixes: 3262ad8 ("usb: gadget: f_fs: Stop ffs_closed NULL pointer dereference") Cc: [email protected] Signed-off-by: Andrew Gabbasov <[email protected]> Acked-by: Felipe Balbi <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2ef4700 commit cdafb6d

File tree

1 file changed

+1
-0
lines changed
  • drivers/usb/gadget/function

1 file changed

+1
-0
lines changed

drivers/usb/gadget/function/f_fs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3673,6 +3673,7 @@ static void ffs_closed(struct ffs_data *ffs)
36733673
goto done;
36743674

36753675
ffs_obj->desc_ready = false;
3676+
ffs_obj->ffs_data = NULL;
36763677

36773678
if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags) &&
36783679
ffs_obj->ffs_closed_callback)

0 commit comments

Comments
 (0)