From: sashiko-bot@kernel.org
To: "Shuangpeng Bai" <shuangpeng.kernel@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2] usb: gadget: f_fs: fix use-after-free in ffs_func_unbind
Date: Fri, 20 Nov 2026 21:12:53 +0000 [thread overview]
Message-ID: <sashiko-outbox-226143@kernel.org> (raw)
In-Reply-To: <20261120210616.2293426-1-shuangpeng.kernel@gmail.com>
> ffs_func_unbind() calls functionfs_unbind(), which drops the reference
> to ffs taken in functionfs_bind(). It then keeps using ffs: it takes
> ffs->eps_lock to free the endpoint requests.
>
> The superblock holds a separate reference, dropped when FunctionFS is
> unmounted. If the gadget is unbound (for example by writing an empty
> string to the configfs UDC attribute) while FunctionFS is being
> unmounted, ffs_fs_kill_sb() can see FFS_FL_BOUND already cleared, skip
> unregister_gadget_item(), and drop its reference. Whichever put comes
> last frees ffs, and if that happens before ffs_func_unbind() is done,
> the eps_lock access is a use-after-free. KASAN reports it as a
> slab-use-after-free in _raw_spin_lock_irqsave() called from
> ffs_func_unbind().
>
> Before commit a3058a5d82e2 ("usb: gadget: f_fs: remove redundant
> ffs_data_get()"), bind took two references and unbind dropped only one,
> so ffs was never freed and the late access was harmless.
>
> Do the endpoint cleanup first and call functionfs_unbind() last, so ffs
> is not touched after the reference is dropped.
>
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120210616.2293426-1-shuangpeng.kernel@gmail.com?part=1
prev parent reply other threads:[~2026-11-20 21:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 21:06 [PATCH v2] usb: gadget: f_fs: fix use-after-free in ffs_func_unbind Shuangpeng Bai
2026-11-20 21:12 ` sashiko-bot [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=sashiko-outbox-226143@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shuangpeng.kernel@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.