From: Yiyuan Guo <yguoaz@gmail.com>
To: gregkh@linuxfoundation.org, dan.scally@ideasonboard.com,
andriy.shevchenko@linux.intel.com
Cc: frank.li@nxp.com, christophe.jaillet@wanadoo.fr,
jgilab@gmail.com, chanh@os.amperecomputing.com,
linux-usb@vger.kernel.org, yguoaz@gmail.com
Subject: [PATCH] usb: gadget: configfs: Prevent buffer overrun in usb_string_copy
Date: Fri, 30 Jun 2023 19:04:01 +0800 [thread overview]
Message-ID: <20230630110401.2360746-1-yguoaz@gmail.com> (raw)
In usb_string_copy(), when `strlen(s) == 0`, `str[ret - 1]` accesses at
index -1. Add a check to prevent buffer overrun when `s` is empty.
Signed-off-by: Yiyuan Guo <yguoaz@gmail.com>
---
drivers/usb/gadget/configfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 4c639e9ddedc..457dbc267964 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -127,7 +127,7 @@ static int usb_string_copy(const char *s, char **s_copy)
return -ENOMEM;
}
strcpy(str, s);
- if (str[ret - 1] == '\n')
+ if (ret && str[ret - 1] == '\n')
str[ret - 1] = '\0';
*s_copy = str;
return 0;
--
2.25.1
next reply other threads:[~2023-06-30 11:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-30 11:04 Yiyuan Guo [this message]
2023-06-30 12:17 ` [PATCH] usb: gadget: configfs: Prevent buffer overrun in usb_string_copy Greg KH
2023-06-30 13:13 ` yguoaz
2023-06-30 19:48 ` Greg KH
2023-07-01 3:48 ` yguoaz
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=20230630110401.2360746-1-yguoaz@gmail.com \
--to=yguoaz@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=chanh@os.amperecomputing.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dan.scally@ideasonboard.com \
--cc=frank.li@nxp.com \
--cc=gregkh@linuxfoundation.org \
--cc=jgilab@gmail.com \
--cc=linux-usb@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