All of lore.kernel.org
 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 v4] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl
Date: Fri, 04 Dec 2026 11:52:05 +0000	[thread overview]
Message-ID: <sashiko-outbox-249733@kernel.org> (raw)
In-Reply-To: <179638424483.1056529.4365760725322283852@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 2afecf326e3fa3f1963a2c2a9789edfb44ab44a9
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 lookup and
ffs_func_revmap_intf() walk in ffs_ep0_ioctl(), and around clearing
ffs->func to NULL in ffs_func_unbind().

> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 59afa7f2bce45..c3919f60cac7e 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -689,8 +689,12 @@ 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;
> +		struct ffs_function *func;
> +
> +		scoped_guard(spinlock_irqsave, &ffs->eps_lock) {
> +			func = ffs->func;
> +			ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
> +		}
>  	} else if (gadget && gadget->ops->ioctl) {
>  		ret = gadget->ops->ioctl(gadget, code, value);
>  	} else {

[Severity: Medium]
Does ffs->func still race with ffs_func_set_alt() and ffs_func_disable()
here?

Only ffs_func_unbind() takes ffs->eps_lock when updating ffs->func.  Both
ffs_func_set_alt() and ffs_func_disable() still perform unlocked plain
writes to ffs->func immediately after releasing ffs->eps_lock, leaving an
unmarked data race (reportable by KCSAN) against this plain load.

Because ffs_func_revmap_intf() is a small static helper in the same file,
the compiler can inline it and reload ffs->func after the NULL check while
a concurrent disconnect or reset clears it:

CPU0                            CPU1
ffs_ep0_ioctl()                 ffs_func_disable()
  lock(&ffs->eps_lock)            lock(&ffs->eps_lock)
  func = ffs->func;               ...
  if (func)                       unlock(&ffs->eps_lock)
                                  ffs->func = NULL;
    ffs_func_revmap_intf(...)
      /* reload ffs->func */
      func->interfaces_nums     <-- NULL pointer dereference

Moving the ffs->func assignments in ffs_func_set_alt() and
ffs_func_disable() into their existing ffs->eps_lock critical sections
(while keeping ffs_event_add() outside the lock) would close the race.

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

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

Thread overview: 8+ 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
2026-11-26  7:43 ` 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
2026-12-04 11:37       ` [PATCH v4] " Jaegyun Lee
2026-12-04 11:52         ` 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-249733@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 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.