* Re: [syzbot] [usb?] memory leak in hidg_bind
2026-08-09 19:13 [syzbot] [usb?] memory leak in hidg_bind syzbot
@ 2026-08-10 1:24 ` Edward Adam Davis
2026-08-10 2:39 ` syzbot
2026-08-10 3:14 ` Edward Adam Davis
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Edward Adam Davis @ 2026-08-10 1:24 UTC (permalink / raw)
To: syzbot+60740c6a17a5b5eb1f5a; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 3c6b43d06a6d..0aa14b99d97e 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -1163,8 +1163,10 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
/* maybe allocate device-global string IDs, and patch descriptors */
us = usb_gstrings_attach(c->cdev, ct_func_strings,
ARRAY_SIZE(ct_func_string_defs));
- if (IS_ERR(us))
- return PTR_ERR(us);
+ if (IS_ERR(us)) {
+ status = PTR_ERR(us);
+ goto fail;
+ }
hidg_interface_desc.iInterface = us[CT_FUNC_HID_IDX].id;
/* allocate instance-specific interface IDs, and patch descriptors */
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [syzbot] [usb?] memory leak in hidg_bind
2026-08-10 1:24 ` Edward Adam Davis
@ 2026-08-10 2:39 ` syzbot
0 siblings, 0 replies; 10+ messages in thread
From: syzbot @ 2026-08-10 2:39 UTC (permalink / raw)
To: eadavis, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in hidg_bind
BUG: memory leak
unreferenced object 0xffff888111b4f000 (size 128):
comm "syz.0.17", pid 6585, jiffies 4294947509
hex dump (first 32 bytes):
00 f0 b4 11 81 88 ff ff 00 f0 b4 11 81 88 ff ff ................
30 20 3d 03 81 88 ff ff 00 00 00 00 00 00 00 00 0 =.............
backtrace (crc 76e5a94b):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4597 [inline]
slab_alloc_node mm/slub.c:4917 [inline]
__kmalloc_cache_noprof+0x356/0x440 mm/slub.c:5485
_kmalloc_noprof include/linux/slab.h:988 [inline]
_kzalloc_noprof include/linux/slab.h:1309 [inline]
dummy_alloc_request+0x65/0xf0 drivers/usb/gadget/udc/dummy_hcd.c:693
usb_ep_alloc_request+0x2e/0xd0 drivers/usb/gadget/udc/core.c:197
hidg_bind+0x2b/0x490 drivers/usb/gadget/function/f_hid.c:1154
usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1802
gadget_bind_driver+0xed/0x390 drivers/usb/gadget/udc/core.c:1662
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x12f/0x3a0 drivers/base/dd.c:706
__driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:868
driver_probe_device+0x28/0xf0 drivers/base/dd.c:898
__driver_attach drivers/base/dd.c:1292 [inline]
__driver_attach+0x10a/0x200 drivers/base/dd.c:1232
bus_for_each_dev+0xb8/0x120 drivers/base/bus.c:383
bus_add_driver+0x122/0x280 drivers/base/bus.c:763
driver_register+0xb1/0x140 drivers/base/driver.c:174
usb_gadget_register_driver_owner+0x69/0xe0 drivers/usb/gadget/udc/core.c:1752
gadget_dev_desc_UDC_store+0x153/0x1e0 drivers/usb/gadget/configfs.c:300
BUG: memory leak
unreferenced object 0xffff888125862700 (size 128):
comm "syz.0.18", pid 6591, jiffies 4294947513
hex dump (first 32 bytes):
00 27 86 25 81 88 ff ff 00 27 86 25 81 88 ff ff .'.%.....'.%....
30 20 3d 03 81 88 ff ff 00 00 00 00 00 00 00 00 0 =.............
backtrace (crc 3911a62a):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4597 [inline]
slab_alloc_node mm/slub.c:4917 [inline]
__kmalloc_cache_noprof+0x356/0x440 mm/slub.c:5485
_kmalloc_noprof include/linux/slab.h:988 [inline]
_kzalloc_noprof include/linux/slab.h:1309 [inline]
dummy_alloc_request+0x65/0xf0 drivers/usb/gadget/udc/dummy_hcd.c:693
usb_ep_alloc_request+0x2e/0xd0 drivers/usb/gadget/udc/core.c:197
hidg_bind+0x2b/0x490 drivers/usb/gadget/function/f_hid.c:1154
usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1802
gadget_bind_driver+0xed/0x390 drivers/usb/gadget/udc/core.c:1662
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x12f/0x3a0 drivers/base/dd.c:706
__driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:868
driver_probe_device+0x28/0xf0 drivers/base/dd.c:898
__driver_attach drivers/base/dd.c:1292 [inline]
__driver_attach+0x10a/0x200 drivers/base/dd.c:1232
bus_for_each_dev+0xb8/0x120 drivers/base/bus.c:383
bus_add_driver+0x122/0x280 drivers/base/bus.c:763
driver_register+0xb1/0x140 drivers/base/driver.c:174
usb_gadget_register_driver_owner+0x69/0xe0 drivers/usb/gadget/udc/core.c:1752
gadget_dev_desc_UDC_store+0x153/0x1e0 drivers/usb/gadget/configfs.c:300
BUG: memory leak
unreferenced object 0xffff888103a65600 (size 128):
comm "syz.0.19", pid 6596, jiffies 4294947515
hex dump (first 32 bytes):
00 56 a6 03 81 88 ff ff 00 56 a6 03 81 88 ff ff .V.......V......
30 20 3d 03 81 88 ff ff 00 00 00 00 00 00 00 00 0 =.............
backtrace (crc 1b6d465a):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4597 [inline]
slab_alloc_node mm/slub.c:4917 [inline]
__kmalloc_cache_noprof+0x356/0x440 mm/slub.c:5485
_kmalloc_noprof include/linux/slab.h:988 [inline]
_kzalloc_noprof include/linux/slab.h:1309 [inline]
dummy_alloc_request+0x65/0xf0 drivers/usb/gadget/udc/dummy_hcd.c:693
usb_ep_alloc_request+0x2e/0xd0 drivers/usb/gadget/udc/core.c:197
hidg_bind+0x2b/0x490 drivers/usb/gadget/function/f_hid.c:1154
usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1802
gadget_bind_driver+0xed/0x390 drivers/usb/gadget/udc/core.c:1662
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x12f/0x3a0 drivers/base/dd.c:706
__driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:868
driver_probe_device+0x28/0xf0 drivers/base/dd.c:898
__driver_attach drivers/base/dd.c:1292 [inline]
__driver_attach+0x10a/0x200 drivers/base/dd.c:1232
bus_for_each_dev+0xb8/0x120 drivers/base/bus.c:383
bus_add_driver+0x122/0x280 drivers/base/bus.c:763
driver_register+0xb1/0x140 drivers/base/driver.c:174
usb_gadget_register_driver_owner+0x69/0xe0 drivers/usb/gadget/udc/core.c:1752
gadget_dev_desc_UDC_store+0x153/0x1e0 drivers/usb/gadget/configfs.c:300
connection error: failed to recv *flatrpc.ExecutorMessageRawT: EOF
Tested on:
commit: db2ddb87 Linux 7.2-rc7
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17060079580000
kernel config: https://syzkaller.appspot.com/x/.config?x=6843f8fd2336602d
dashboard link: https://syzkaller.appspot.com/bug?extid=60740c6a17a5b5eb1f5a
compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
patch: https://syzkaller.appspot.com/x/patch.diff?x=169fa2c6580000
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [syzbot] [usb?] memory leak in hidg_bind
2026-08-09 19:13 [syzbot] [usb?] memory leak in hidg_bind syzbot
2026-08-10 1:24 ` Edward Adam Davis
@ 2026-08-10 3:14 ` Edward Adam Davis
2026-08-10 4:18 ` syzbot
2026-08-10 4:33 ` Edward Adam Davis
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Edward Adam Davis @ 2026-08-10 3:14 UTC (permalink / raw)
To: syzbot+60740c6a17a5b5eb1f5a; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 183a25f65ac8..ee7e250f8fd5 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -511,7 +511,6 @@ static void config_usb_cfg_unlink(
}
}
mutex_unlock(&gi->lock);
- WARN(1, "Unable to locate function to unbind\n");
}
static const struct configfs_item_operations gadget_config_item_ops = {
@@ -1593,12 +1592,7 @@ static void purge_configs_funcs(struct gadget_info *gi)
list_for_each_entry_safe_reverse(f, tmp, &c->functions, list) {
list_move(&f->list, &cfg->func_list);
- if (f->unbind) {
- dev_dbg(&gi->cdev.gadget->dev,
- "unbind function '%s'/%p\n",
- f->name, f);
- f->unbind(c, f);
- }
+ usb_remove_function(c, f);
}
c->next_interface_id = 0;
memset(c->interface, 0, sizeof(c->interface));
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 3c6b43d06a6d..0799220aeb13 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -1158,13 +1158,15 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
hidg->get_req->zero = 0;
hidg->get_req->complete = hidg_get_report_complete;
hidg->get_req->context = hidg;
- hidg->get_report_returned = true;
+ hidg->get_report_returned = false;
/* maybe allocate device-global string IDs, and patch descriptors */
us = usb_gstrings_attach(c->cdev, ct_func_strings,
ARRAY_SIZE(ct_func_string_defs));
- if (IS_ERR(us))
- return PTR_ERR(us);
+ if (IS_ERR(us)) {
+ status = PTR_ERR(us);
+ goto fail;
+ }
hidg_interface_desc.iInterface = us[CT_FUNC_HID_IDX].id;
/* allocate instance-specific interface IDs, and patch descriptors */
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [syzbot] [usb?] memory leak in hidg_bind
2026-08-10 3:14 ` Edward Adam Davis
@ 2026-08-10 4:18 ` syzbot
0 siblings, 0 replies; 10+ messages in thread
From: syzbot @ 2026-08-10 4:18 UTC (permalink / raw)
To: eadavis, linux-kernel, syzkaller-bugs
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in usb_get_function
2026/08/10 04:15:52 executed programs: 21
2026/08/10 04:15:58 executed programs: 23
2026/08/10 04:16:04 executed programs: 25
2026/08/10 04:16:09 executed programs: 27
BUG: memory leak
unreferenced object 0xffff888111f44000 (size 2048):
comm "syz.0.37", pid 6720, jiffies 4294950131
hex dump (first 32 bytes):
00 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 04 00 01 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc b745374a):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4597 [inline]
slab_alloc_node mm/slub.c:4917 [inline]
__kmalloc_cache_noprof+0x356/0x440 mm/slub.c:5485
_kmalloc_noprof include/linux/slab.h:988 [inline]
_kzalloc_noprof include/linux/slab.h:1309 [inline]
hidg_alloc+0x2c/0x270 drivers/usb/gadget/function/f_hid.c:1603
usb_get_function+0x21/0x60 drivers/usb/gadget/functions.c:61
config_usb_cfg_link+0x10d/0x190 drivers/usb/gadget/configfs.c:469
configfs_symlink+0x28c/0x860 fs/configfs/symlink.c:196
vfs_symlink fs/namei.c:5660 [inline]
vfs_symlink+0xd1/0x240 fs/namei.c:5639
filename_symlinkat+0x17e/0x2b0 fs/namei.c:5685
__do_sys_symlinkat fs/namei.c:5705 [inline]
__se_sys_symlinkat fs/namei.c:5700 [inline]
__x64_sys_symlinkat+0x47/0x70 fs/namei.c:5700
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xf8/0x610 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
BUG: memory leak
unreferenced object 0xffff888114b800f8 (size 8):
comm "syz.0.37", pid 6720, jiffies 4294950131
hex dump (first 8 bytes):
68 69 64 67 30 00 00 00 hidg0...
backtrace (crc 557cac88):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4597 [inline]
slab_alloc_node mm/slub.c:4917 [inline]
__do_kmalloc_node mm/slub.c:5333 [inline]
__kmalloc_node_track_caller_noprof+0x3d3/0x570 mm/slub.c:5471
kvasprintf+0x6e/0xf0 lib/kasprintf.c:25
kvasprintf_const+0x5c/0x110 lib/kasprintf.c:49
kobject_set_name_vargs+0x40/0xd0 lib/kobject.c:274
dev_set_name+0x6d/0x90 drivers/base/core.c:3560
hidg_alloc+0x132/0x270 drivers/usb/gadget/function/f_hid.c:1625
usb_get_function+0x21/0x60 drivers/usb/gadget/functions.c:61
config_usb_cfg_link+0x10d/0x190 drivers/usb/gadget/configfs.c:469
configfs_symlink+0x28c/0x860 fs/configfs/symlink.c:196
vfs_symlink fs/namei.c:5660 [inline]
vfs_symlink+0xd1/0x240 fs/namei.c:5639
filename_symlinkat+0x17e/0x2b0 fs/namei.c:5685
__do_sys_symlinkat fs/namei.c:5705 [inline]
__se_sys_symlinkat fs/namei.c:5700 [inline]
__x64_sys_symlinkat+0x47/0x70 fs/namei.c:5700
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xf8/0x610 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
BUG: memory leak
unreferenced object 0xffff888128bac500 (size 256):
comm "syz.0.37", pid 6720, jiffies 4294950131
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 08 c5 ba 28 81 88 ff ff ...........(....
08 c5 ba 28 81 88 ff ff 00 ce 4e 83 ff ff ff ff ...(......N.....
backtrace (crc 57fd964b):
kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
slab_post_alloc_hook mm/slub.c:4597 [inline]
slab_alloc_node mm/slub.c:4917 [inline]
__kmalloc_cache_noprof+0x356/0x440 mm/slub.c:5485
_kmalloc_noprof include/linux/slab.h:988 [inline]
_kzalloc_noprof include/linux/slab.h:1309 [inline]
device_private_init drivers/base/core.c:3602 [inline]
device_add+0x740/0xc80 drivers/base/core.c:3653
cdev_device_add+0x7e/0x100 fs/char_dev.c:553
hidg_bind+0x385/0x490 drivers/usb/gadget/function/f_hid.c:1289
usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1796
gadget_bind_driver+0xed/0x390 drivers/usb/gadget/udc/core.c:1662
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x12f/0x3a0 drivers/base/dd.c:706
__driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:868
driver_probe_device+0x28/0xf0 drivers/base/dd.c:898
__driver_attach drivers/base/dd.c:1292 [inline]
__driver_attach+0x10a/0x200 drivers/base/dd.c:1232
bus_for_each_dev+0xb8/0x120 drivers/base/bus.c:383
bus_add_driver+0x122/0x280 drivers/base/bus.c:763
driver_register+0xb1/0x140 drivers/base/driver.c:174
usb_gadget_register_driver_owner+0x69/0xe0 drivers/usb/gadget/udc/core.c:1752
gadget_dev_desc_UDC_store+0x153/0x1e0 drivers/usb/gadget/configfs.c:300
connection error: failed to recv *flatrpc.ExecutorMessageRawT: EOF
Tested on:
commit: db2ddb87 Linux 7.2-rc7
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=123da079580000
kernel config: https://syzkaller.appspot.com/x/.config?x=6843f8fd2336602d
dashboard link: https://syzkaller.appspot.com/bug?extid=60740c6a17a5b5eb1f5a
compiler: gcc (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44
patch: https://syzkaller.appspot.com/x/patch.diff?x=171462c6580000
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [syzbot] [usb?] memory leak in hidg_bind
2026-08-09 19:13 [syzbot] [usb?] memory leak in hidg_bind syzbot
2026-08-10 1:24 ` Edward Adam Davis
2026-08-10 3:14 ` Edward Adam Davis
@ 2026-08-10 4:33 ` Edward Adam Davis
2026-08-10 5:17 ` syzbot
2026-08-10 7:24 ` Edward Adam Davis
2026-08-10 10:25 ` [PATCH] USB: gadget: f_hid: Release get report req upon unsetup Edward Adam Davis
4 siblings, 1 reply; 10+ messages in thread
From: Edward Adam Davis @ 2026-08-10 4:33 UTC (permalink / raw)
To: syzbot+60740c6a17a5b5eb1f5a; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 183a25f65ac8..86c57c3aa8e0 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -1593,6 +1593,8 @@ static void purge_configs_funcs(struct gadget_info *gi)
list_for_each_entry_safe_reverse(f, tmp, &c->functions, list) {
list_move(&f->list, &cfg->func_list);
+ if (f->disable)
+ f->disable(f);
if (f->unbind) {
dev_dbg(&gi->cdev.gadget->dev,
"unbind function '%s'/%p\n",
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 3c6b43d06a6d..0799220aeb13 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -1158,13 +1158,15 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
hidg->get_req->zero = 0;
hidg->get_req->complete = hidg_get_report_complete;
hidg->get_req->context = hidg;
- hidg->get_report_returned = true;
+ hidg->get_report_returned = false;
/* maybe allocate device-global string IDs, and patch descriptors */
us = usb_gstrings_attach(c->cdev, ct_func_strings,
ARRAY_SIZE(ct_func_string_defs));
- if (IS_ERR(us))
- return PTR_ERR(us);
+ if (IS_ERR(us)) {
+ status = PTR_ERR(us);
+ goto fail;
+ }
hidg_interface_desc.iInterface = us[CT_FUNC_HID_IDX].id;
/* allocate instance-specific interface IDs, and patch descriptors */
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [syzbot] [usb?] memory leak in hidg_bind
2026-08-09 19:13 [syzbot] [usb?] memory leak in hidg_bind syzbot
` (2 preceding siblings ...)
2026-08-10 4:33 ` Edward Adam Davis
@ 2026-08-10 7:24 ` Edward Adam Davis
2026-08-10 8:31 ` syzbot
2026-08-10 10:25 ` [PATCH] USB: gadget: f_hid: Release get report req upon unsetup Edward Adam Davis
4 siblings, 1 reply; 10+ messages in thread
From: Edward Adam Davis @ 2026-08-10 7:24 UTC (permalink / raw)
To: syzbot+60740c6a17a5b5eb1f5a; +Cc: linux-kernel, syzkaller-bugs
#syz test
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 3c6b43d06a6d..8d739e052e68 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -1163,8 +1163,10 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
/* maybe allocate device-global string IDs, and patch descriptors */
us = usb_gstrings_attach(c->cdev, ct_func_strings,
ARRAY_SIZE(ct_func_string_defs));
- if (IS_ERR(us))
- return PTR_ERR(us);
+ if (IS_ERR(us)) {
+ status = PTR_ERR(us);
+ goto fail;
+ }
hidg_interface_desc.iInterface = us[CT_FUNC_HID_IDX].id;
/* allocate instance-specific interface IDs, and patch descriptors */
@@ -1585,10 +1587,18 @@ static void hidg_free(struct usb_function *f)
static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
{
struct f_hidg *hidg = func_to_hidg(f);
+ unsigned long flags;
cdev_device_del(hidg->cdev, &hidg->dev);
destroy_workqueue(hidg->workqueue);
usb_free_all_descriptors(f);
+
+ spin_lock_irqsave(&hidg->get_report_spinlock, flags);
+ if (hidg->get_req && !hidg->get_req->length) {
+ usb_ep_free_request(f->config->cdev->gadget->ep0, hidg->get_req);
+ hidg->get_req = NULL;
+ }
+ spin_unlock_irqrestore(&hidg->get_report_spinlock, flags);
}
static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH] USB: gadget: f_hid: Release get report req upon unsetup
2026-08-09 19:13 [syzbot] [usb?] memory leak in hidg_bind syzbot
` (3 preceding siblings ...)
2026-08-10 7:24 ` Edward Adam Davis
@ 2026-08-10 10:25 ` Edward Adam Davis
4 siblings, 0 replies; 10+ messages in thread
From: Edward Adam Davis @ 2026-08-10 10:25 UTC (permalink / raw)
To: syzbot+60740c6a17a5b5eb1f5a
Cc: gregkh, david.sands, chris.wulff, linux-kernel, linux-usb,
syzkaller-bugs
The GET_REPORT request instance (hidg->get_req) is freed only within
hidg_disable() after successful binding, and only if Condition [1] is met.
Since userspace does not execute the setup, get_report_workqueue_handler()
is never invoked; consequently, Condition [1] is never met, leading to the
memory leak reported in [2].
The solution is to add memory reclamation for get_req in hidg_unbind(),
using `get_req->length` to determine whether Condition [1] applies.
Additionally, a failure in usb_gstrings_attach() also triggers the issue
reported in [2], so this is fixed at the same time.
[1]
The report is not in the list or should not be sent immediately
[2]
BUG: memory leak
unreferenced object 0xffff888112450300 (size 128):
backtrace (crc 18381426):
usb_ep_alloc_request+0x2e/0xd0 drivers/usb/gadget/udc/core.c:197
hidg_bind+0x2b/0x490 drivers/usb/gadget/function/f_hid.c:1154
usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1802
gadget_bind_driver+0xed/0x390 drivers/usb/gadget/udc/core.c:1662
Fixes: a139c98f760e ("USB: gadget: f_hid: Add GET_REPORT via userspace IOCTL")
Reported-by: syzbot+60740c6a17a5b5eb1f5a@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=60740c6a17a5b5eb1f5a
Tested-by: syzbot+60740c6a17a5b5eb1f5a@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
drivers/usb/gadget/function/f_hid.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 3c6b43d06a6d..8d739e052e68 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -1163,8 +1163,10 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
/* maybe allocate device-global string IDs, and patch descriptors */
us = usb_gstrings_attach(c->cdev, ct_func_strings,
ARRAY_SIZE(ct_func_string_defs));
- if (IS_ERR(us))
- return PTR_ERR(us);
+ if (IS_ERR(us)) {
+ status = PTR_ERR(us);
+ goto fail;
+ }
hidg_interface_desc.iInterface = us[CT_FUNC_HID_IDX].id;
/* allocate instance-specific interface IDs, and patch descriptors */
@@ -1585,10 +1587,18 @@ static void hidg_free(struct usb_function *f)
static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
{
struct f_hidg *hidg = func_to_hidg(f);
+ unsigned long flags;
cdev_device_del(hidg->cdev, &hidg->dev);
destroy_workqueue(hidg->workqueue);
usb_free_all_descriptors(f);
+
+ spin_lock_irqsave(&hidg->get_report_spinlock, flags);
+ if (hidg->get_req && !hidg->get_req->length) {
+ usb_ep_free_request(f->config->cdev->gadget->ep0, hidg->get_req);
+ hidg->get_req = NULL;
+ }
+ spin_unlock_irqrestore(&hidg->get_report_spinlock, flags);
}
static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread