[PATCH 1/2] usb: gadget: configfs: free ext_prop data on property removal
From: Jaegyun Lee
Date: Sun Nov 29 2026 - 08:25:51 EST
ext_prop_data_store() allocates the property value with kmemdup() and
stores it in ext_prop->data (freeing the previous value), but
ext_prop_drop() only frees ext_prop->name:
list_del(&ext_prop->entry);
--desc->ext_prop_count;
kfree(ext_prop->name);
and usb_os_desc_ext_prop_release() frees only the item itself. So every
rmdir of an OS descriptor extended property that has been given a value
leaks that value.
Reproduced by creating an ncm function and repeatedly doing mkdir
functions/ncm.usb0/os_desc/interface.ncm/p, writing type 3 and a value,
and rmdir. kmemleak:
unreferenced object 0xffff88804b79e000 (size 1024):
comm "bash", pid 9567, jiffies 4294950045
hex dump (first 32 bytes):
41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 AAAAAAAAAAAAAAAA
backtrace (crc 2fcade99):
__kmalloc_node_track_caller_noprof+0x4cd/0x880
kmemdup_noprof+0x2b/0x60
ext_prop_data_store+0xb4/0x300
configfs_write_iter+0x307/0x500
vfs_write+0xc11/0x1140
ksys_write+0x121/0x240
do_syscall_64+0x132/0x7c0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Free ext_prop->data together with ext_prop->name.
Fixes: 7419485f197c ("usb: gadget: configfs: OS Extended Properties descriptors support")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: ZCode:GLM-5.4
Signed-off-by: Jaegyun Lee <dreams200260@xxxxxxxxx>
---
drivers/usb/gadget/configfs.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 51df6d1d1487a..46a2f1c6308c1 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -1450,6 +1450,7 @@ static void ext_prop_drop(struct config_group *group, struct config_item *item)
list_del(&ext_prop->entry);
--desc->ext_prop_count;
kfree(ext_prop->name);
+ kfree(ext_prop->data);
desc->ext_prop_len -= (ext_prop->name_len + ext_prop->data_len + 14);
if (desc->opts_mutex)
mutex_unlock(desc->opts_mutex);