All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegyun Lee <dreams200260@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Neill Kapron <nkapron@google.com>
Cc: Jaegyun Lee <dreams200260@gmail.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: [PATCH 1/2] usb: gadget: configfs: free ext_prop data on property removal
Date: Sun, 29 Nov 2026 22:25:07 +0900	[thread overview]
Message-ID: <20261129132508.387095-1-dreams200260@gmail.com> (raw)

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);

             reply	other threads:[~2026-11-29 13:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 13:25 Jaegyun Lee [this message]
2026-11-29 13:25 ` [PATCH 2/2] usb: gadget: configfs: fix ext_prop race with composite_setup() Jaegyun Lee
2026-11-29 13:30 ` [PATCH 1/2] usb: gadget: configfs: free ext_prop data on property removal sashiko-bot
2026-11-29 13:34 ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129132508.387095-1-dreams200260@gmail.com \
    --to=dreams200260@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nkapron@google.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.