Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 1/2] usb: gadget: configfs: free ext_prop data on property removal
@ 2026-11-29 13:25 Jaegyun Lee
  2026-11-29 13:25 ` [PATCH 2/2] usb: gadget: configfs: fix ext_prop race with composite_setup() Jaegyun Lee
  0 siblings, 1 reply; 2+ messages in thread
From: Jaegyun Lee @ 2026-11-29 13:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Neill Kapron
  Cc: Jaegyun Lee, linux-usb, linux-kernel, stable

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@vger.kernel.org
Assisted-by: ZCode:GLM-5.4
Signed-off-by: Jaegyun Lee <dreams200260@gmail.com>
---
 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);

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29 13:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 13:25 [PATCH 1/2] usb: gadget: configfs: free ext_prop data on property removal Jaegyun Lee
2026-11-29 13:25 ` [PATCH 2/2] usb: gadget: configfs: fix ext_prop race with composite_setup() Jaegyun Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox