* [PATCH v2] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl
@ 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
0 siblings, 2 replies; 7+ messages in thread
From: Jaegyun Lee via B4 Relay @ 2026-11-26 7:43 UTC (permalink / raw)
To: Greg Kroah-Hartman, Neill Kapron
Cc: linux-usb, linux-kernel, stable, Jaegyun Lee
From: Jaegyun Lee <dreams200260@g.skku.edu>
ffs_ep0_ioctl() snapshots ffs->func without any lock or reference:
struct ffs_function *func = ffs->func;
ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
ffs_func_revmap_intf() then walks func->interfaces_nums for
interfaces_count iterations. ffs_func_unbind() first sets
ffs->func = NULL, then after drain_workqueue() kfrees func->eps --
the allocation chunk that also holds interfaces_nums -- and later
still writes func->interfaces_nums = NULL.
An ioctl that read ffs->func before the NULL write can therefore be
inside the revmap walk while the chunk is freed.
John Keeping noted this in 2021:
https://lkml.rescloud.iu.edu/2112.0/00724.html
The following is the KASAN log:
BUG: KASAN: slab-use-after-free in ffs_ep0_ioctl+0x29b/0x300
Read of size 2 at addr ffff888051b4925a by task park/9666
CPU: 1 UID: 0 PID: 9666 Comm: park Not tainted 7.4.0-rc3-g666539eecdf4 #1 PREEMPT(full)
Call Trace:
ffs_ep0_ioctl+0x29b/0x300
__x64_sys_ioctl+0x18f/0x210
do_syscall_64+0x132/0x7c0
Allocated by task 9675:
__kmalloc_noprof+0x357/0x810
ffs_func_bind+0xbd1/0x1b00
usb_add_function+0x219/0x8a0
configfs_composite_bind+0xcd5/0x17f0
gadget_bind_driver+0x288/0xc80
Freed by task 9675:
kfree+0x2ca/0x6e0
ffs_func_unbind+0x2f2/0x570
purge_configs_funcs+0x283/0x520
configfs_composite_unbind+0xae/0x210
gadget_unbind_driver+0x211/0x520
...
gadget_dev_desc_UDC_store+0x18a/0x2f0
The buggy address is located 602 bytes inside of
freed 2048-byte region (kmalloc-2k)
Take ffs->eps_lock around the REVMAP snapshot and walk, and do the
ffs->func = NULL store in ffs_func_unbind() under the same lock. A walk
that started before the store finishes before it, and every later
ioctl sees NULL, so the walk can no longer overlap the free of the eps
chunk.
Reproduced and tested in QEMU (dummy_hcd) only, not on real UDC
hardware.
Fixes: ddf8abd25994 ("USB: f_fs: the FunctionFS driver")
Cc: stable@vger.kernel.org
Assisted-by: ZCode:GLM-5.4
Signed-off-by: Jaegyun Lee <dreams200260@g.skku.edu>
---
Changes in v2:
- Keep clearing ffs->func in its original place in ffs_func_unbind(),
before functionfs_unbind(), and only do that store under eps_lock;
leave the eps free path unchanged (Sashiko review).
- Link to v1: https://patch.msgid.link/20261126-ffs-revmap-v1-1-e1322f6fa290@g.skku.edu
---
drivers/usb/gadget/function/f_fs.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index c64a268e98a43..df55c2cba6101 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -687,8 +687,13 @@ 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;
+ struct ffs_function *func;
+ unsigned long flags;
+
+ spin_lock_irqsave(&ffs->eps_lock, flags);
+ func = ffs->func;
ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
+ spin_unlock_irqrestore(&ffs->eps_lock, flags);
} else if (gadget && gadget->ops->ioctl) {
ret = gadget->ops->ioctl(gadget, code, value);
} else {
@@ -4205,7 +4210,9 @@ static void ffs_func_unbind(struct usb_configuration *c,
if (ffs->func == func) {
ffs_func_eps_disable(func);
+ spin_lock_irqsave(&ffs->eps_lock, flags);
ffs->func = NULL;
+ spin_unlock_irqrestore(&ffs->eps_lock, flags);
}
/* Drain any pending AIO completions */
---
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
change-id: 20261126-ffs-revmap-78010561eb60
Best regards,
--
Jaegyun Lee <dreams200260@g.skku.edu>
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl
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
1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-26 7:52 UTC (permalink / raw)
To: Jaegyun Lee; +Cc: linux-usb
> From: Jaegyun Lee <dreams200260@g.skku.edu>
>
> ffs_ep0_ioctl() snapshots ffs->func without any lock or reference:
>
> struct ffs_function *func = ffs->func;
> ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
>
> ffs_func_revmap_intf() then walks func->interfaces_nums for
> interfaces_count iterations. ffs_func_unbind() first sets
> ffs->func = NULL, then after drain_workqueue() kfrees func->eps --
> the allocation chunk that also holds interfaces_nums -- and later
> still writes func->interfaces_nums = NULL.
>
> An ioctl that read ffs->func before the NULL write can therefore be
> inside the revmap walk while the chunk is freed.
> [ ... ]
>
> Fixes: ddf8abd25994 ("USB: f_fs: the FunctionFS driver")
> Cc: stable@vger.kernel.org
> Assisted-by: ZCode:GLM-5.4
> Signed-off-by: Jaegyun Lee <dreams200260@g.skku.edu>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-ffs-revmap-v2-1-445e86b561dc@g.skku.edu?part=1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl
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
1 sibling, 1 reply; 7+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 22:17 UTC (permalink / raw)
To: dreams200260; +Cc: Neill Kapron, linux-usb, linux-kernel, stable
On Thu, Nov 26, 2026 at 04:43:40PM +0900, Jaegyun Lee via B4 Relay wrote:
> From: Jaegyun Lee <dreams200260@g.skku.edu>
>
> ffs_ep0_ioctl() snapshots ffs->func without any lock or reference:
>
> struct ffs_function *func = ffs->func;
> ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
>
> ffs_func_revmap_intf() then walks func->interfaces_nums for
> interfaces_count iterations. ffs_func_unbind() first sets
> ffs->func = NULL, then after drain_workqueue() kfrees func->eps --
> the allocation chunk that also holds interfaces_nums -- and later
> still writes func->interfaces_nums = NULL.
>
> An ioctl that read ffs->func before the NULL write can therefore be
> inside the revmap walk while the chunk is freed.
> John Keeping noted this in 2021:
> https://lkml.rescloud.iu.edu/2112.0/00724.html
>
> The following is the KASAN log:
>
> BUG: KASAN: slab-use-after-free in ffs_ep0_ioctl+0x29b/0x300
> Read of size 2 at addr ffff888051b4925a by task park/9666
> CPU: 1 UID: 0 PID: 9666 Comm: park Not tainted 7.4.0-rc3-g666539eecdf4 #1 PREEMPT(full)
> Call Trace:
> ffs_ep0_ioctl+0x29b/0x300
> __x64_sys_ioctl+0x18f/0x210
> do_syscall_64+0x132/0x7c0
> Allocated by task 9675:
> __kmalloc_noprof+0x357/0x810
> ffs_func_bind+0xbd1/0x1b00
> usb_add_function+0x219/0x8a0
> configfs_composite_bind+0xcd5/0x17f0
> gadget_bind_driver+0x288/0xc80
> Freed by task 9675:
> kfree+0x2ca/0x6e0
> ffs_func_unbind+0x2f2/0x570
> purge_configs_funcs+0x283/0x520
> configfs_composite_unbind+0xae/0x210
> gadget_unbind_driver+0x211/0x520
> ...
> gadget_dev_desc_UDC_store+0x18a/0x2f0
> The buggy address is located 602 bytes inside of
> freed 2048-byte region (kmalloc-2k)
>
> Take ffs->eps_lock around the REVMAP snapshot and walk, and do the
> ffs->func = NULL store in ffs_func_unbind() under the same lock. A walk
> that started before the store finishes before it, and every later
> ioctl sees NULL, so the walk can no longer overlap the free of the eps
> chunk.
>
> Reproduced and tested in QEMU (dummy_hcd) only, not on real UDC
> hardware.
>
> Fixes: ddf8abd25994 ("USB: f_fs: the FunctionFS driver")
> Cc: stable@vger.kernel.org
> Assisted-by: ZCode:GLM-5.4
> Signed-off-by: Jaegyun Lee <dreams200260@g.skku.edu>
> ---
> Changes in v2:
> - Keep clearing ffs->func in its original place in ffs_func_unbind(),
> before functionfs_unbind(), and only do that store under eps_lock;
> leave the eps free path unchanged (Sashiko review).
> - Link to v1: https://patch.msgid.link/20261126-ffs-revmap-v1-1-e1322f6fa290@g.skku.edu
> ---
> drivers/usb/gadget/function/f_fs.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index c64a268e98a43..df55c2cba6101 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -687,8 +687,13 @@ 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;
> + struct ffs_function *func;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&ffs->eps_lock, flags);
guard() please
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl
2026-12-03 22:17 ` Greg Kroah-Hartman
@ 2026-12-04 11:13 ` Jaegyun Lee
2026-12-04 11:27 ` sashiko-bot
0 siblings, 1 reply; 7+ messages in thread
From: Jaegyun Lee @ 2026-12-04 11:13 UTC (permalink / raw)
To: gregkh; +Cc: Jaegyun Lee, nkapron, linux-usb, linux-kernel, stable
ffs_ep0_ioctl() snapshots ffs->func without any lock or reference:
struct ffs_function *func = ffs->func;
ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
ffs_func_revmap_intf() then walks func->interfaces_nums for
interfaces_count iterations. ffs_func_unbind() first sets
ffs->func = NULL, then after drain_workqueue() kfrees func->eps --
the allocation chunk that also holds interfaces_nums -- and later
still writes func->interfaces_nums = NULL.
An ioctl that read ffs->func before the NULL write can therefore be
inside the revmap wa₩lk while the chunk is freed.
John Keeping noted this in 2021:
https://lkml.rescloud.iu.edu/2112.0/00724.html
The following is the KASAN log:
BUG: KASAN: slab-use-after-free in ffs_ep0_ioctl+0x29b/0x300
Read of size 2 at addr ffff888051b4925a by task park/9666
CPU: 1 UID: 0 PID: 9666 Comm: park Not tainted 7.4.0-rc3-g666539eecdf4 #1 PREEMPT(full)
Call Trace:
ffs_ep0_ioctl+0x29b/0x300
__x64_sys_ioctl+0x18f/0x210
do_syscall_64+0x132/0x7c0
Allocated by task 9675:
__kmalloc_noprof+0x357/0x810
ffs_func_bind+0xbd1/0x1b00
usb_add_function+0x219/0x8a0
configfs_composite_bind+0xcd5/0x17f0
gadget_bind_driver+0x288/0xc80
Freed by task 9675:
kfree+0x2ca/0x6e0
ffs_func_unbind+0x2f2/0x570
purge_configs_funcs+0x283/0x520
configfs_composite_unbind+0xae/0x210
gadget_unbind_driver+0x211/0x520
...
gadget_dev_desc_UDC_store+0x18a/0x2f0
The buggy address is located 602 bytes inside of
freed 2048-byte region (kmalloc-2k)
Take ffs->eps_lock around the REVMAP snapshot and walk, and do the
ffs->func = NULL store in ffs_func_unbind() under the same lock. A walk
that started before the store finishes before it, and every later
ioctl sees NULL, so the walk can no longer overlap the free of the eps
chunk.
Reproduced and tested in QEMU (dummy_hcd) only, not on real UDC
hardware.
Sending from a different address than the earlier versions.
Fixes: ddf8abd25994 ("USB: f_fs: the FunctionFS driver")
Cc: stable@vger.kernel.org
Assisted-by: ZCode:GLM-5.4
Signed-off-by: Jaegyun Lee <dreams200260@gmail.com>
---
Changes in v3:
- Use guard() and scoped_guard().
- Link to v2: https://patch.msgid.link/20261126-ffs-revmap-v2-1-445e86b561dc@g.skku.edu
diff --git a/drivers/usb/gadget/function/f_fs.c
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -688,8 +688,8 @@
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 {
@@ -4221,7 +4221,8 @@
if (ffs->func == func) {
ffs_func_eps_disable(func);
- ffs->func = NULL;
+ scoped_guard(spinlock_irqsave, &ffs->eps_lock)
+ ffs->func = NULL;
}
/* Drain any pending AIO completions */
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl
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
0 siblings, 1 reply; 7+ messages in thread
From: sashiko-bot @ 2026-12-04 11:27 UTC (permalink / raw)
To: Jaegyun Lee; +Cc: linux-usb
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl
2026-12-04 11:27 ` sashiko-bot
@ 2026-12-04 11:37 ` Jaegyun Lee
2026-12-04 11:52 ` sashiko-bot
0 siblings, 1 reply; 7+ messages in thread
From: Jaegyun Lee @ 2026-12-04 11:37 UTC (permalink / raw)
To: gregkh; +Cc: Jaegyun Lee, nkapron, linux-usb, linux-kernel, stable
ffs_ep0_ioctl() snapshots ffs->func without any lock or reference:
struct ffs_function *func = ffs->func;
ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
ffs_func_revmap_intf() then walks func->interfaces_nums for
interfaces_count iterations. ffs_func_unbind() first sets
ffs->func = NULL, then after drain_workqueue() kfrees func->eps --
the allocation chunk that also holds interfaces_nums -- and later
still writes func->interfaces_nums = NULL.
An ioctl that read ffs->func before the NULL write can therefore be
inside the revmap walk while the chunk is freed.
John Keeping noted this in 2021:
https://lkml.rescloud.iu.edu/2112.0/00724.html
The following is the KASAN log:
BUG: KASAN: slab-use-after-free in ffs_ep0_ioctl+0x29b/0x300
Read of size 2 at addr ffff888051b4925a by task park/9666
CPU: 1 UID: 0 PID: 9666 Comm: park Not tainted 7.4.0-rc3-g666539eecdf4 #1 PREEMPT(full)
Call Trace:
ffs_ep0_ioctl+0x29b/0x300
__x64_sys_ioctl+0x18f/0x210
do_syscall_64+0x132/0x7c0
Allocated by task 9675:
__kmalloc_noprof+0x357/0x810
ffs_func_bind+0xbd1/0x1b00
usb_add_function+0x219/0x8a0
configfs_composite_bind+0xcd5/0x17f0
gadget_bind_driver+0x288/0xc80
Freed by task 9675:
kfree+0x2ca/0x6e0
ffs_func_unbind+0x2f2/0x570
purge_configs_funcs+0x283/0x520
configfs_composite_unbind+0xae/0x210
gadget_unbind_driver+0x211/0x520
...
gadget_dev_desc_UDC_store+0x18a/0x2f0
The buggy address is located 602 bytes inside of
freed 2048-byte region (kmalloc-2k)
Take ffs->eps_lock around the REVMAP snapshot and walk, and do the
ffs->func = NULL store in ffs_func_unbind() under the same lock. A walk
that started before the store finishes before it, and every later
ioctl sees NULL, so the walk can no longer overlap the free of the eps
chunk.
Reproduced and tested in QEMU (dummy_hcd) only, not on real UDC
hardware.
Fixes: ddf8abd25994 ("USB: f_fs: the FunctionFS driver")
Cc: stable@vger.kernel.org
Assisted-by: ZCode:GLM-5.4
Signed-off-by: Jaegyun Lee <dreams200260@gmail.com>
---
Changes in v4:
- Read ffs->func once into a local under the lock. v3 read it twice, and the unlocked NULL store of ffs_func_disable() or ffs_func_set_alt() could land between the two reads (sashiko-bot).
- Link to v3: https://patch.msgid.link/179638268904.917654.4905537541576241323@gmail.com
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -688,8 +688,12 @@
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 {
@@ -4221,7 +4225,8 @@
if (ffs->func == func) {
ffs_func_eps_disable(func);
- ffs->func = NULL;
+ scoped_guard(spinlock_irqsave, &ffs->eps_lock)
+ ffs->func = NULL;
}
/* Drain any pending AIO completions */
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4] usb: gadget: f_fs: fix UAF read in INTERFACE_REVMAP ioctl
2026-12-04 11:37 ` [PATCH v4] " Jaegyun Lee
@ 2026-12-04 11:52 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-04 11:52 UTC (permalink / raw)
To: Jaegyun Lee; +Cc: linux-usb
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-04 11:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-12-04 11:37 ` [PATCH v4] " Jaegyun Lee
2026-12-04 11:52 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox