Linux USB
 help / color / mirror / Atom feed
From: Tanuj Sharma <ertanuj96@gmail.com>
To: gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] usb: gadget: configfs: fix OOB read on ext_prop type toggle
Date: Tue,  1 Dec 2026 02:54:59 +0530	[thread overview]
Message-ID: <20261130212459.85640-1-ertanuj96@gmail.com> (raw)

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


                 reply	other threads:[~2026-11-30 21:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261130212459.85640-1-ertanuj96@gmail.com \
    --to=ertanuj96@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox