mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
Cc: viro@zeniv.linux.org.uk, r.baldyga@samsung.com, balbi@ti.com,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: f_fs: fix use-after-free in ffs_func_unbind
Date: Fri, 20 Nov 2026 11:21:17 +0100	[thread overview]
Message-ID: <2026112053-skating-swimsuit-9c33@gregkh> (raw)
In-Reply-To: <20260815013818.39466-1-shuangpeng.kernel@gmail.com>

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

      reply	other threads:[~2026-11-20 10:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-15  1:38 Shuangpeng Bai
2026-11-20 10:21 ` Greg KH [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2026112053-skating-swimsuit-9c33@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=balbi@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=r.baldyga@samsung.com \
    --cc=shuangpeng.kernel@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®