* [PATCH] usb: gadget: f_fs: fix use-after-free in ffs_func_unbind
@ 2026-08-15 1:38 Shuangpeng Bai
2026-11-20 10:21 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: Shuangpeng Bai @ 2026-08-15 1:38 UTC (permalink / raw)
To: gregkh
Cc: viro, r.baldyga, balbi, linux-usb, linux-kernel, Shuangpeng Bai,
stable
ffs_func_unbind() continues to access ffs after calling
functionfs_unbind(), including taking ffs->eps_lock for endpoint cleanup.
However, functionfs_unbind() drops the binding reference to ffs.
A concurrent FunctionFS unmount can drop the independent superblock
reference. Either put can then release the final reference and free ffs
before ffs_func_unbind() finishes its endpoint cleanup.
Take a temporary ffs reference for the duration of ffs_func_unbind() and
drop it only after all post-unbind cleanup is complete.
Fixes: a3058a5d82e2 ("usb: gadget: f_fs: remove redundant ffs_data_get()")
Cc: stable@vger.kernel.org
Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
---
drivers/usb/gadget/function/f_fs.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 44218be1e676..8acad4564b6c 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -4089,6 +4089,9 @@ static void ffs_func_unbind(struct usb_configuration *c,
unsigned count = ffs->eps_count;
unsigned long flags;
+ /* Keep ffs alive until all post-unbind cleanup is complete. */
+ ffs_data_get(ffs);
+
if (ffs->func == func) {
ffs_func_eps_disable(func);
ffs->func = NULL;
@@ -4122,6 +4125,7 @@ static void ffs_func_unbind(struct usb_configuration *c,
func->function.ssp_descriptors = NULL;
func->interfaces_nums = NULL;
+ ffs_data_put(ffs);
}
static struct usb_function *ffs_alloc(struct usb_function_instance *fi)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: gadget: f_fs: fix use-after-free in ffs_func_unbind
2026-08-15 1:38 [PATCH] usb: gadget: f_fs: fix use-after-free in ffs_func_unbind Shuangpeng Bai
@ 2026-11-20 10:21 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-11-20 10:21 UTC (permalink / raw)
To: Shuangpeng Bai; +Cc: viro, r.baldyga, balbi, linux-usb, linux-kernel, stable
On Fri, Aug 14, 2026 at 09:38:18PM -0400, Shuangpeng Bai wrote:
> ffs_func_unbind() continues to access ffs after calling
> functionfs_unbind(), including taking ffs->eps_lock for endpoint cleanup.
> However, functionfs_unbind() drops the binding reference to ffs.
>
> A concurrent FunctionFS unmount can drop the independent superblock
> reference. Either put can then release the final reference and free ffs
> before ffs_func_unbind() finishes its endpoint cleanup.
>
> Take a temporary ffs reference for the duration of ffs_func_unbind() and
> drop it only after all post-unbind cleanup is complete.
>
> Fixes: a3058a5d82e2 ("usb: gadget: f_fs: remove redundant ffs_data_get()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
> ---
> drivers/usb/gadget/function/f_fs.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 44218be1e676..8acad4564b6c 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -4089,6 +4089,9 @@ static void ffs_func_unbind(struct usb_configuration *c,
> unsigned count = ffs->eps_count;
> unsigned long flags;
>
> + /* Keep ffs alive until all post-unbind cleanup is complete. */
> + ffs_data_get(ffs);
Are you sure this is ok? This means you now have a double reference.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-20 10:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-15 1:38 [PATCH] usb: gadget: f_fs: fix use-after-free in ffs_func_unbind Shuangpeng Bai
2026-11-20 10:21 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox