From: Alan Stern <stern@rowland.harvard.edu>
To: yanfei.xu@windriver.com
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] USB: core: limit access to rawdescriptors which were not allocated
Date: Tue, 25 Aug 2020 14:00:26 -0400 [thread overview]
Message-ID: <20200825180026.GA375466@rowland.harvard.edu> (raw)
In-Reply-To: <20200825161659.19008-1-yanfei.xu@windriver.com>
On Wed, Aug 26, 2020 at 12:16:59AM +0800, yanfei.xu@windriver.com wrote:
> From: Yanfei Xu <yanfei.xu@windriver.com>
>
> When using systemcall to read the rawdescriptors, make sure we won't
> access to the rawdescriptors never allocated, which are number
> exceed the USB_MAXCONFIG.
>
> Reported-by: syzbot+256e56ddde8b8957eabd@syzkaller.appspotmail.com
> Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
> ---
> drivers/usb/core/sysfs.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
> index a2ca38e25e0c..1a7a625e5f55 100644
> --- a/drivers/usb/core/sysfs.c
> +++ b/drivers/usb/core/sysfs.c
> @@ -895,7 +895,8 @@ read_descriptors(struct file *filp, struct kobject *kobj,
> * configurations (config plus subsidiary descriptors).
> */
> for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations &&
> - nleft > 0; ++cfgno) {
> + nleft > 0 &&
> + cfgno < USB_MAXCONFIG; ++cfgno) {
> if (cfgno < 0) {
> src = &udev->descriptor;
> srclen = sizeof(struct usb_device_descriptor);
This is not the right way to fix the problem.
Instead, we should make sure that udev->descriptor.bNumConfigurations is
always <= USB_MAXCONFIG. That's what this code in
usb_get_configuration() is supposed to do:
int ncfg = dev->descriptor.bNumConfigurations;
...
if (ncfg > USB_MAXCONFIG) {
dev_warn(ddev, "too many configurations: %d, "
"using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
}
If you want to fix the bug, you need to figure out why this isn't
working.
Alan Stern
next prev parent reply other threads:[~2020-08-25 18:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-25 16:16 yanfei.xu
2020-08-25 17:56 ` kernel test robot
2020-08-25 18:00 ` Alan Stern [this message]
2020-08-26 6:56 ` Xu, Yanfei
2020-08-25 21:35 ` kernel test robot
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=20200825180026.GA375466@rowland.harvard.edu \
--to=stern@rowland.harvard.edu \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=yanfei.xu@windriver.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
all inboxes | Powered by JetHome®