From: sashiko-bot@kernel.org
To: "Palla Raghunath" <raghunathpalla.0209@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH RESEND v2] usb: gadget: f_fs: fix use-after-free of ffs_dev in ffs_free_inst()
Date: Fri, 04 Dec 2026 06:05:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-249181@kernel.org> (raw)
In-Reply-To: <20261204055346.42890-1-raghunathpalla.0209@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: gadget: f_fs: __must_hold() fails without ffs_dev_lock()
annotations
--
commit 6c427f29e02317dd1e9434249fd97f907aa55e3c
Author: Palla Raghunath <raghunathpalla.0209@gmail.com>
usb: gadget: f_fs: fix use-after-free of ffs_dev in ffs_free_inst()
This commit splits ffs_release_dev() into a lockless _ffs_release_dev()
helper annotated with __must_hold(&ffs_lock) so ffs_free_inst() can release
and free opts->dev under a single ffs_dev_lock() critical section.
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 59afa7f2bce45..87befbca7af51 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
[ ... ]
> @@ -4372,10 +4374,12 @@ static int ffs_acquire_dev(const char *dev_name, struct ffs_data *ffs_data)
> return ret;
> }
>
> -static void ffs_release_dev(struct ffs_dev *ffs_dev)
> +/*
> + * Same as ffs_release_dev(), for callers that already hold ffs_lock.
> + */
> +static void _ffs_release_dev(struct ffs_dev *ffs_dev)
> + __must_hold(&ffs_lock)
> {
> - ffs_dev_lock();
> -
> if (ffs_dev && ffs_dev->mounted) {
> ffs_dev->mounted = false;
> if (ffs_dev->ffs_data) {
> @@ -4386,7 +4390,12 @@ static void ffs_release_dev(struct ffs_dev *ffs_dev)
> if (ffs_dev->ffs_release_dev_callback)
> ffs_dev->ffs_release_dev_callback(ffs_dev);
> }
> +}
>
> +static void ffs_release_dev(struct ffs_dev *ffs_dev)
> +{
> + ffs_dev_lock();
> + _ffs_release_dev(ffs_dev);
> ffs_dev_unlock();
> }
[Severity: Low]
As reported by Greg Kroah-Hartman on v1 [1], does __must_hold(&ffs_lock) on
_ffs_release_dev() work with the unannotated ffs_dev_lock() wrapper?
Both ffs_free_inst() and ffs_release_dev() acquire ffs_lock via
ffs_dev_lock() and ffs_dev_unlock() in drivers/usb/gadget/function/u_fs.h,
which lack __acquires(&ffs_lock) and __releases(&ffs_lock).
Clang context analysis does not infer locks across inline functions, so
CONFIG_WARN_CONTEXT_ANALYSIS_ALL=y triggers -Wthread-safety-analysis
warnings (or errors under CONFIG_WERROR=y) at both call sites and in the
wrappers. Annotating ffs_dev_lock() and ffs_dev_unlock() would fix this.
[1] https://lore.kernel.org/r/2026112029-depletion-small-f290@gregkh
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204055346.42890-1-raghunathpalla.0209@gmail.com?part=1
prev parent reply other threads:[~2026-12-04 6:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 5:53 [PATCH RESEND v2] usb: gadget: f_fs: fix use-after-free of ffs_dev in ffs_free_inst() Palla Raghunath
2026-12-04 6:05 ` 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-249181@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=raghunathpalla.0209@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/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.