From: Zhang Shurong <zhang_shurong@foxmail.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: jgross@suse.com, xen-devel@lists.xenproject.org,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] xen: fix potential shift out-of-bounds in xenhcd_hub_control()
Date: Sat, 01 Jul 2023 23:51:43 +0800 [thread overview]
Message-ID: <tencent_62EE5604188B87B14220EA91C4CD8D4C2D06@qq.com> (raw)
In-Reply-To: <2023062628-shame-ebook-56f2@gregkh>
在 2023年6月26日星期一 CST 下午1:52:02,您写道:
> On Mon, Jun 26, 2023 at 07:48:05AM +0200, Jan Beulich wrote:
> > On 25.06.2023 18:42, Zhang Shurong wrote:
> > > --- a/drivers/usb/host/xen-hcd.c
> > > +++ b/drivers/usb/host/xen-hcd.c
> > > @@ -456,6 +456,8 @@ static int xenhcd_hub_control(struct usb_hcd *hcd,
> > > __u16 typeReq, __u16 wValue,> >
> > > info->ports[wIndex - 1].c_connection =
false;
> > > fallthrough;
> > >
> > > default:
> > > + if (wValue >= 32)
> > > + goto error;
> > >
> > > info->ports[wIndex - 1].status &= ~(1
<< wValue);
> >
> > Even 31 is out of bounds (as in: UB) as long as it's 1 here rather
> > than 1u.
>
> Why isn't the caller fixed so this type of value could never be passed
> to the hub_control callback?
>
> thanks,
>
> greg k-h
Although I'm not knowledgeable about the USB subsystem, I've observed that not
all driver code that implements hub_control callback performs a shift
operation on wValue, and not all shift operations among them cause problems.
Therefore, I've decided to fix this issue within each driver itself.
For example, in r8a66597_hub_control, it will first check whether wValue is
valid (always < 31) before the shift operation. In case of an invalid number,
the code would execute the error branch instead of the shift operation.
switch (wValue) {
case USB_PORT_FEAT_ENABLE:
rh->port &= ~USB_PORT_STAT_POWER;
break;
case USB_PORT_FEAT_SUSPEND:
break;
case USB_PORT_FEAT_POWER:
r8a66597_port_power(r8a66597, port, 0);
break;
case USB_PORT_FEAT_C_ENABLE:
case USB_PORT_FEAT_C_SUSPEND:
case USB_PORT_FEAT_C_CONNECTION:
case USB_PORT_FEAT_C_OVER_CURRENT:
case USB_PORT_FEAT_C_RESET:
break;
default:
goto error;
}
rh->port &= ~(1 << wValue);
next prev parent reply other threads:[~2023-07-01 15:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-25 16:42 [PATCH] xen: fix potential shift out-of-bounds in xenhcd_hub_control() Zhang Shurong
2023-06-26 5:48 ` Jan Beulich
2023-06-26 5:52 ` Greg KH
2023-07-01 15:51 ` Zhang Shurong [this message]
[not found] ` <4825193.GXAFRqVoOG@localhost.localdomain>
2023-08-06 14:11 ` Zhang Shurong
2023-08-06 14:27 ` Greg KH
2023-08-06 15:15 ` Alan Stern
2023-08-08 8:26 ` Greg KH
2023-08-08 15:05 ` Alan Stern
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=tencent_62EE5604188B87B14220EA91C4CD8D4C2D06@qq.com \
--to=zhang_shurong@foxmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=xen-devel@lists.xenproject.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