Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: configfs: fix OOB read on ext_prop type toggle
@ 2026-11-30 21:24 Tanuj Sharma
  2026-11-30 21:44 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Tanuj Sharma @ 2026-11-30 21:24 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, stable

In ext_prop_type_store(), toggling the property type from BINARY to
UNICODE doubles data_len without reallocating the data buffer. When
ext_prop_data_show() subsequently reads data_len bytes from the
original buffer, it reads past the allocation into adjacent slab data,
leaking kernel heap contents to userspace via the configfs attribute
read interface.

Fix this by reallocating the data buffer with krealloc when the type
change requires a larger buffer. Zero-fill the newly allocated space to
prevent information leaks. The halving path (UNICODE to BINARY) is safe
as it reads fewer bytes than allocated.

Fixes: 7419485f197c ("usb: gadget: configfs: OS Extended Properties descriptors support")
Cc: stable@vger.kernel.org
Signed-off-by: Tanuj Sharma <ertanuj96@gmail.com>
---
 drivers/usb/gadget/configfs.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 51df6d1..1fcc010 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -1311,9 +1311,24 @@ static ssize_t ext_prop_type_store(struct config_item *item,
 	    ext_prop->type == USB_EXT_PROP_BE32) &&
 	    (type == USB_EXT_PROP_UNICODE ||
 	    type == USB_EXT_PROP_UNICODE_ENV ||
-	    type == USB_EXT_PROP_UNICODE_LINK))
+	    type == USB_EXT_PROP_UNICODE_LINK)) {
+		if (ext_prop->data) {
+			char *new_data;
+			size_t new_len = ext_prop->data_len << 1;
+
+			new_data = krealloc(ext_prop->data, new_len,
+					    GFP_KERNEL);
+			if (!new_data) {
+				if (desc->opts_mutex)
+					mutex_unlock(desc->opts_mutex);
+				return -ENOMEM;
+			}
+			memset(new_data + ext_prop->data_len, 0,
+			       ext_prop->data_len);
+			ext_prop->data = new_data;
+		}
 		ext_prop->data_len <<= 1;
-	else if ((ext_prop->type == USB_EXT_PROP_UNICODE ||
+	} else if ((ext_prop->type == USB_EXT_PROP_UNICODE ||
 		   ext_prop->type == USB_EXT_PROP_UNICODE_ENV ||
 		   ext_prop->type == USB_EXT_PROP_UNICODE_LINK) &&
 		   (type == USB_EXT_PROP_BINARY ||
-- 
2.43.0


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

end of thread, other threads:[~2026-11-30 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 21:24 [PATCH] usb: gadget: configfs: fix OOB read on ext_prop type toggle Tanuj Sharma
2026-11-30 21:44 ` sashiko-bot

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