public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Sergey Shtylyov <sergei.shtylyov@gmail.com>
To: Xinyu Liu <1171169449@qq.com>, gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	katieeliu@tencent.com, security@tencent.com
Subject: Re: [PATCH] usb: gadget: configfs: Fix OOB read on empty string write
Date: Wed, 9 Jul 2025 11:48:32 +0300	[thread overview]
Message-ID: <e1ef050c-9679-4571-a4dc-581bf005dab7@gmail.com> (raw)
In-Reply-To: <tencent_B1C9481688D0E95E7362AB2E999DE8048207@qq.com>

On 7/9/25 6:55 AM, Xinyu Liu wrote:

> When writing an empty string to either 'qw_sign' or 'landingPage'
> sysfs attributes, the store functions attempt to access page[l - 1]
> before validating that the length 'l' is greater than zero.
> 
> This patch fixes the vulnerability by adding a check at the beginning
> of os_desc_qw_sign_store() and webusb_landingPage_store() to handle
> the zero-length input case gracefully by returning immediately.
> 
> Signed-off-by: Xinyu Liu <katieeliu@tencent.com>
> ---
>  drivers/usb/gadget/configfs.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
> index fba2a56dae97..1bb32d6be9b3 100644
> --- a/drivers/usb/gadget/configfs.c
> +++ b/drivers/usb/gadget/configfs.c
> @@ -1064,7 +1064,8 @@ static ssize_t webusb_landingPage_store(struct config_item *item, const char *pa
>  	struct gadget_info *gi = webusb_item_to_gadget_info(item);
>  	unsigned int bytes_to_strip = 0;
>  	int l = len;
> -

   Why are you removing empty line here?

> +	if (!len)
> +		return len;
>  	if (page[l - 1] == '\n') {
>  		--l;
>  		++bytes_to_strip;
> @@ -1187,7 +1188,8 @@ static ssize_t os_desc_qw_sign_store(struct config_item *item, const char *page,
>  {
>  	struct gadget_info *gi = os_desc_item_to_gadget_info(item);
>  	int res, l;
> -

   And here?

> +	if (!len)
> +		return len;
>  	l = min_t(int, len, OS_STRING_QW_SIGN_LEN >> 1);
>  	if (page[l - 1] == '\n')
>  		--l;

MBR, Sergey


  reply	other threads:[~2025-07-09  8:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09  3:55 [PATCH] usb: gadget: configfs: Fix OOB read on empty string write Xinyu Liu
2025-07-09  8:48 ` Sergey Shtylyov [this message]
2025-07-09 10:22   ` Xinyu Liu
2025-07-09 19:02     ` Sergey Shtylyov

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=e1ef050c-9679-4571-a4dc-581bf005dab7@gmail.com \
    --to=sergei.shtylyov@gmail.com \
    --cc=1171169449@qq.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=katieeliu@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=security@tencent.com \
    /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