Re: [PATCH v2] usb: gadget: f_fs: fix use-after-free of ffs_dev in ffs_free_inst()

From: Palla Raghunath

Date: Fri Dec 04 2026 - 00:51:10 EST


On Thu, Dec 03, 2026 at 11:16:58PM +0100, Greg Kroah-Hartman wrote:
> Isn't this fixed cleaner by:
> https://lore.kernel.org/r/20261120210616.2293426-1-shuangpeng.kernel@xxxxxxxxx
>
> If not, please resend and explain why that commit does not fix this
> issue.

I don't think it does. They are two different bugs on two different
objects.

Shuangpeng's patch is about struct ffs_data. ffs_func_unbind() drops
its reference with functionfs_unbind() and then still takes
ffs->eps_lock, so the patch moves functionfs_unbind() to the end. It
only changes ffs_func_unbind().

This one is about struct ffs_dev. In the syzbot report the freed object
was allocated in ffs_alloc_inst() and freed from ffs_free_inst():

Freed by task 17408:
_ffs_free_dev drivers/usb/gadget/function/f_fs.c:4336 [inline]
ffs_free_inst+0x233/0x2c0 drivers/usb/gadget/function/f_fs.c:4152

ffs_free_inst() drops ffs_dev_lock between ffs_release_dev() and
_ffs_free_dev(), and the dev is still on ffs_devices in that window. A
mount with the same name can pick it up through ffs_acquire_dev(), and
the umount later writes to the freed dev in ffs_closed().

No gadget bind or unbind is involved. ffs_func_unbind() isn't in the
syzbot report, and my reproducer only races configfs mkdir/rmdir of
the function against mount/umount of functionfs, without ever binding
a UDC. Shuangpeng's patch doesn't touch ffs_free_inst(), so that window
is still there with it applied.

I'll resend v2 with this explanation below the --- line.

thanks,
Raghunath