Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jaegyun Lee" <dreams200260@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v3] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl
Date: Fri, 04 Dec 2026 11:27:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-249675@kernel.org> (raw)
In-Reply-To: <179638268904.917654.4905537541576241323@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: gadget: f_fs: unlocked ffs->func writes race with
  ffs_ep0_ioctl()
--

commit 749233c5ed0afea8fa48c7272c8471cf26bafee9
Author: Jaegyun Lee <dreams200260@gmail.com>

usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl

This commit takes ffs->eps_lock around the ffs->func check and
ffs_func_revmap_intf() walk in ffs_ep0_ioctl(), and protects the
ffs->func = NULL store in ffs_func_unbind() with the same lock.

> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 59afa7f2bce45..8bb49407c728b 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -689,8 +689,8 @@ static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
>  	long ret;
>  
>  	if (code == FUNCTIONFS_INTERFACE_REVMAP) {
> -		struct ffs_function *func = ffs->func;
> -		ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
> +		guard(spinlock_irqsave)(&ffs->eps_lock);
> +		ret = ffs->func ? ffs_func_revmap_intf(ffs->func, value) : -ENODEV;
>  	} else if (gadget && gadget->ops->ioctl) {
>  		ret = gadget->ops->ioctl(gadget, code, value);
>  	} else {

[Severity: Medium]
Can unlocked writes to ffs->func in ffs_func_disable() and
ffs_func_set_alt() still race with ffs_ep0_ioctl() and cause a NULL
pointer dereference?

Removing the local func snapshot causes ffs->func to be evaluated twice
under ffs->eps_lock, assuming that lock excludes all writers.  However,
only ffs_func_unbind() was updated to hold ffs->eps_lock; both
ffs_func_disable() and ffs_func_set_alt() still write ffs->func right
after dropping ffs->eps_lock.

During a USB disconnect or bus reset, ffs_func_disable() can clear
ffs->func concurrently with an ioctl(FUNCTIONFS_INTERFACE_REVMAP):

CPU0                              CPU1
ffs_ep0_ioctl()
  guard(spinlock_irqsave)(&ffs->eps_lock)
  ffs->func != NULL
                                  ffs_func_disable()
                                    spin_unlock_irqrestore(&ffs->eps_lock)
                                    ffs->func = NULL
  ffs_func_revmap_intf(ffs->func, ...)
    func->interfaces_nums         <-- NULL pointer dereference

If the compiler reloads ffs->func for the call to ffs_func_revmap_intf()
(or inside an inlined copy), dereferencing func->interfaces_nums crashes
with a NULL pointer dereference.  ffs_func_set_alt() has the same data
race on ffs->func during configuration or altsetting changes.

Updating ffs->func while ffs->eps_lock is already held in
ffs_func_disable() and ffs_func_set_alt() would close both races.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179638268904.917654.4905537541576241323@gmail.com?part=1

  reply	other threads:[~2026-12-04 11:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  7:43 [PATCH v2] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl Jaegyun Lee via B4 Relay
2026-11-26  7:52 ` sashiko-bot
2026-12-03 22:17 ` Greg Kroah-Hartman
2026-12-04 11:13   ` [PATCH v3] " Jaegyun Lee
2026-12-04 11:27     ` sashiko-bot [this message]
2026-12-04 11:37       ` [PATCH v4] " Jaegyun Lee
2026-12-04 11:52         ` sashiko-bot

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-249675@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dreams200260@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox