memory leak in build_fu_desc

Status: upstream: reported C repro on 2026/12/03 09:16
Subsystems: usb
Labels: prio:normal
[Documentation on labels]
Reported-by: syzbot+da5ce3f4a00c8cbe0d4e@syzkaller.appspotmail.com
First crash: 2h53m, last: 2h53m
✨ AI cause bisection: introduced by (AI job) :
commit eaf6cbe0992052a46d93047dc122fad5126aa3bd
Author: Ruslan Bilovol <ruslan.bilovol@gmail.com>
Date: Mon Jul 12 12:55:28 2021 +0000

  usb: gadget: f_uac2: add volume and mute support

✨ AI-generated root cause summary:

In drivers/usb/gadget/function/f_uac2.c, in_feature_unit_desc and out_feature_unit_desc are stored as global static pointers rather than per-instance fields of struct f_uac2. When multiple uac2 function instances are bound (such as two uac2 functions in one USB gadget configuration or across multiple gadgets), subsequent calls to afunc_bind() allocate new descriptors via build_fu_desc() and overwrite these global pointers without freeing the previous allocations. As a result, the earlier instances' uac2_feature_unit_descriptor objects become unreferenced and are leaked when afunc_unbind() later frees only the most recently stored pointers. Additionally, sharing these unsynchronized global pointers across instances allows interleaved or concurrent bind/unbind operations across gadgets to trigger NULL-pointer dereferences, use-after-free, or double-free errors.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 3f963696da44:

Root Cause Analysis

The memory leak is caused by storing dynamically allocated USB Audio Class 2.0 feature unit descriptors in global static pointers rather than per-instance state in drivers/usb/gadget/function/f_uac2.c.

Involved Definitions and State

Trigger Mechanism and Lifecycle Violation

  1. In the reproducer, two uac2 function instances (uac2.0 and uac2.usb0) are created and linked into the same gadget configuration (configs/c.1), and the gadget is bound by writing a UDC name to UDC.
  2. gadget_dev_desc_UDC_store() -> usb_gadget_register_driver_owner() -> gadget_bind_driver() -> configfs_composite_bind() (drivers/usb/gadget/configfs.c:1801-1808) iterates over cfg->func_list and calls usb_add_function(c, f) -> afunc_bind() for each uac2 function:
    • First afunc_bind() (uac2.0):
      • Calls build_fu_desc(uac2_opts->c_chmask) (drivers/usb/gadget/function/f_uac2.c:1062), allocating a 32-byte uac2_feature_unit_descriptor via kzalloc() (f_uac2.c:773) and storing it in the global out_feature_unit_desc.
      • Calls build_fu_desc(uac2_opts->p_chmask) (drivers/usb/gadget/function/f_uac2.c:1067), allocating a second 32-byte uac2_feature_unit_descriptor and storing it in the global in_feature_unit_desc.
      • afunc_bind() completes initialization (bUnitID, bSourceID, bmaControls, iFeature — all visible in the kmemleak hex dumps: 12 24 06 05 01 0f ... 0c and 12 24 06 06 02 0f ... 0b) and returns 0.
    • Second afunc_bind() (uac2.usb0):
      • Calls build_fu_desc() at lines 1062 and 1067 again and unconditionally overwrites the global out_feature_unit_desc and in_feature_unit_desc pointers with the new allocations.
      • The descriptor pointers allocated during the first afunc_bind() are overwritten without being freed, leaving them completely unreferenced.
  3. When the gadget is subsequently unbound (by writing "\n" to UDC, or on err_purge_funcs if binding fails), afunc_unbind() (drivers/usb/gadget/function/f_uac2.c:2266-2279) frees out_feature_unit_desc and in_feature_unit_desc and sets both to NULL. Only the latest instance's descriptors are freed; the earlier instance's allocations remain leaked (BUG: memory leak).

Related Defects in the Same Mechanism

  • Error path leak in afunc_bind(): Lines 1206-1246 return ret directly if set_ep_max_packet_size_bint() fails, bypassing goto err_free_fu; (f_uac2.c:1349-1354) and leaking both descriptors.
  • Cross-gadget shared global state: Because gadget_dev_desc_UDC_store() only acquires the per-gadget gi->lock (drivers/usb/gadget/configfs.c:287), and USB control requests (afunc_setup() -> in_rq_cur(), in_rq_range(), out_rq_cur(), out_rq_cur_complete()) run asynchronously without holding gi->lock, binding/unbinding multiple f_uac2 instances across separate gadgets/UDCs can also cause afunc_unbind() / err_free_fu to free and NULL the global pointers while another instance is still binding or handling control requests (USB_IN_FU_ID / USB_OUT_FU_ID), or race on kfree() before setting the globals to NULL.
▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
77983444 bisect-cause IsRelease: ❌ ❓ memory leak in build_fu_desc 2026/12/03 09:09 2026/12/03 09:09 2026/12/03 09:45 35891725
90cb5067 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ✅ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ memory leak in build_fu_desc 2026/12/03 08:43 2026/12/03 08:43 2026/12/03 09:16 35891725
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [usb?] memory leak in build_fu_desc 0 (1) 2026/12/03 09:16

Sample crash report:
BUG: memory leak
unreferenced object 0xffff888111d43640 (size 32):
  comm "syz.0.18", pid 5970, jiffies 4294944041
  hex dump (first 32 bytes):
    12 24 06 05 01 0f 00 00 00 00 00 00 00 00 00 00  .$..............
    00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc f0b3e9e9):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4733 [inline]
    slab_alloc_node mm/slub.c:5033 [inline]
    __do_kmalloc_node mm/slub.c:5530 [inline]
    __kmalloc_noprof+0x3ce/0x510 mm/slub.c:5556
    _kmalloc_noprof include/linux/slab.h:995 [inline]
    _kzalloc_noprof include/linux/slab.h:1312 [inline]
    build_fu_desc+0x3f/0x70 drivers/usb/gadget/function/f_uac2.c:773
    afunc_bind+0x1414/0x16a0 drivers/usb/gadget/function/f_uac2.c:1062
    usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
    configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1803
    gadget_bind_driver+0xed/0x3a0 drivers/usb/gadget/udc/core.c:1671
    call_driver_probe drivers/base/dd.c:629 [inline]
    really_probe+0x12f/0x3a0 drivers/base/dd.c:707
    __driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:869
    driver_probe_device+0x28/0xf0 drivers/base/dd.c:899
    __driver_attach drivers/base/dd.c:1300 [inline]
    __driver_attach+0x10e/0x210 drivers/base/dd.c:1240
    bus_for_each_dev+0xb8/0x120 drivers/base/bus.c:383
    bus_add_driver+0x24c/0x2b0 drivers/base/bus.c:782
    driver_register+0xb1/0x140 drivers/base/driver.c:174
    usb_gadget_register_driver_owner+0x69/0xe0 drivers/usb/gadget/udc/core.c:1761
    gadget_dev_desc_UDC_store+0x153/0x1e0 drivers/usb/gadget/configfs.c:300
    flush_write_buffer fs/configfs/file.c:207 [inline]
    configfs_write_iter+0x10d/0x1a0 fs/configfs/file.c:229

BUG: memory leak
unreferenced object 0xffff888111d43da0 (size 32):
  comm "syz.0.18", pid 5970, jiffies 4294944041
  hex dump (first 32 bytes):
    12 24 06 06 02 0f 00 00 00 00 00 00 00 00 00 00  .$..............
    00 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc cc648ab8):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4733 [inline]
    slab_alloc_node mm/slub.c:5033 [inline]
    __do_kmalloc_node mm/slub.c:5530 [inline]
    __kmalloc_noprof+0x3ce/0x510 mm/slub.c:5556
    _kmalloc_noprof include/linux/slab.h:995 [inline]
    _kzalloc_noprof include/linux/slab.h:1312 [inline]
    build_fu_desc+0x3f/0x70 drivers/usb/gadget/function/f_uac2.c:773
    afunc_bind+0x143b/0x16a0 drivers/usb/gadget/function/f_uac2.c:1067
    usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
    configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1803
    gadget_bind_driver+0xed/0x3a0 drivers/usb/gadget/udc/core.c:1671
    call_driver_probe drivers/base/dd.c:629 [inline]
    really_probe+0x12f/0x3a0 drivers/base/dd.c:707
    __driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:869
    driver_probe_device+0x28/0xf0 drivers/base/dd.c:899
    __driver_attach drivers/base/dd.c:1300 [inline]
    __driver_attach+0x10e/0x210 drivers/base/dd.c:1240
    bus_for_each_dev+0xb8/0x120 drivers/base/bus.c:383
    bus_add_driver+0x24c/0x2b0 drivers/base/bus.c:782
    driver_register+0xb1/0x140 drivers/base/driver.c:174
    usb_gadget_register_driver_owner+0x69/0xe0 drivers/usb/gadget/udc/core.c:1761
    gadget_dev_desc_UDC_store+0x153/0x1e0 drivers/usb/gadget/configfs.c:300
    flush_write_buffer fs/configfs/file.c:207 [inline]
    configfs_write_iter+0x10d/0x1a0 fs/configfs/file.c:229

BUG: memory leak
unreferenced object 0xffff888111d43800 (size 32):
  comm "syz.0.19", pid 5981, jiffies 4294944049
  hex dump (first 32 bytes):
    12 24 06 05 01 0f 00 00 00 00 00 00 00 00 00 00  .$..............
    00 0c 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc f0b3e9e9):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4733 [inline]
    slab_alloc_node mm/slub.c:5033 [inline]
    __do_kmalloc_node mm/slub.c:5530 [inline]
    __kmalloc_noprof+0x3ce/0x510 mm/slub.c:5556
    _kmalloc_noprof include/linux/slab.h:995 [inline]
    _kzalloc_noprof include/linux/slab.h:1312 [inline]
    build_fu_desc+0x3f/0x70 drivers/usb/gadget/function/f_uac2.c:773
    afunc_bind+0x1414/0x16a0 drivers/usb/gadget/function/f_uac2.c:1062
    usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
    configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1803
    gadget_bind_driver+0xed/0x3a0 drivers/usb/gadget/udc/core.c:1671
    call_driver_probe drivers/base/dd.c:629 [inline]
    really_probe+0x12f/0x3a0 drivers/base/dd.c:707
    __driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:869
    driver_probe_device+0x28/0xf0 drivers/base/dd.c:899
    __driver_attach drivers/base/dd.c:1300 [inline]
    __driver_attach+0x10e/0x210 drivers/base/dd.c:1240
    bus_for_each_dev+0xb8/0x120 drivers/base/bus.c:383
    bus_add_driver+0x24c/0x2b0 drivers/base/bus.c:782
    driver_register+0xb1/0x140 drivers/base/driver.c:174
    usb_gadget_register_driver_owner+0x69/0xe0 drivers/usb/gadget/udc/core.c:1761
    gadget_dev_desc_UDC_store+0x153/0x1e0 drivers/usb/gadget/configfs.c:300
    flush_write_buffer fs/configfs/file.c:207 [inline]
    configfs_write_iter+0x10d/0x1a0 fs/configfs/file.c:229

BUG: memory leak
unreferenced object 0xffff888111d43820 (size 32):
  comm "syz.0.19", pid 5981, jiffies 4294944049
  hex dump (first 32 bytes):
    12 24 06 06 02 0f 00 00 00 00 00 00 00 00 00 00  .$..............
    00 0b 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc cc648ab8):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4733 [inline]
    slab_alloc_node mm/slub.c:5033 [inline]
    __do_kmalloc_node mm/slub.c:5530 [inline]
    __kmalloc_noprof+0x3ce/0x510 mm/slub.c:5556
    _kmalloc_noprof include/linux/slab.h:995 [inline]
    _kzalloc_noprof include/linux/slab.h:1312 [inline]
    build_fu_desc+0x3f/0x70 drivers/usb/gadget/function/f_uac2.c:773
    afunc_bind+0x143b/0x16a0 drivers/usb/gadget/function/f_uac2.c:1067
    usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
    configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1803
    gadget_bind_driver+0xed/0x3a0 drivers/usb/gadget/udc/core.c:1671
    call_driver_probe drivers/base/dd.c:629 [inline]
    really_probe+0x12f/0x3a0 drivers/base/dd.c:707
    __driver_probe_device+0xe9/0x1a0 drivers/base/dd.c:869
    driver_probe_device+0x28/0xf0 drivers/base/dd.c:899
    __driver_attach drivers/base/dd.c:1300 [inline]
    __driver_attach+0x10e/0x210 drivers/base/dd.c:1240
    bus_for_each_dev+0xb8/0x120 drivers/base/bus.c:383
    bus_add_driver+0x24c/0x2b0 drivers/base/bus.c:782
    driver_register+0xb1/0x140 drivers/base/driver.c:174
    usb_gadget_register_driver_owner+0x69/0xe0 drivers/usb/gadget/udc/core.c:1761
    gadget_dev_desc_UDC_store+0x153/0x1e0 drivers/usb/gadget/configfs.c:300
    flush_write_buffer fs/configfs/file.c:207 [inline]
    configfs_write_iter+0x10d/0x1a0 fs/configfs/file.c:229

connection error: failed to recv *flatrpc.ExecutorMessageRawT: EOF

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/12/03 08:43 upstream 3f963696da44 35891725 .config console log report syz / log C [disk image] [vmlinux] [kernel image] ci-upstream-gce-leak memory leak in build_fu_desc
* Struck through repros no longer work on HEAD.