diff mbox

usb-ehci: Ensure frindex writes leave a valid frindex value

Message ID 1333455707-3534-1-git-send-email-hdegoede@redhat.com
State New
Headers show

Commit Message

Hans de Goede April 3, 2012, 12:21 p.m. UTC
frindex is a 14 bits counter, so bits 31-14 should always be 0, and
after the commit titled "usb-ehci: frindex always is a 14 bits counter"
we rely on frindex always being a multiple of 8. I've not seen this in
practice, but theoretically a guest can write a value >= 0x4000 or a value
which is not a multiple of 8 value to frindex, this patch ensures that
things will still work when that happens.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 hw/usb/hcd-ehci.c |    4 ++++
 1 file changed, 4 insertions(+)

Comments

Alon Levy April 3, 2012, 1:16 p.m. UTC | #1
On Tue, Apr 03, 2012 at 02:21:47PM +0200, Hans de Goede wrote:
> frindex is a 14 bits counter, so bits 31-14 should always be 0, and
> after the commit titled "usb-ehci: frindex always is a 14 bits counter"
> we rely on frindex always being a multiple of 8. I've not seen this in
> practice, but theoretically a guest can write a value >= 0x4000 or a value
> which is not a multiple of 8 value to frindex, this patch ensures that
> things will still work when that happens.

Acked-by: Alon Levy <alevy@redhat.com>

> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  hw/usb/hcd-ehci.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
> index 64b58e3..8865b4e 100644
> --- a/hw/usb/hcd-ehci.c
> +++ b/hw/usb/hcd-ehci.c
> @@ -1102,6 +1102,10 @@ static void ehci_mem_writel(void *ptr, target_phys_addr_t addr, uint32_t val)
>          val &= USBINTR_MASK;
>          break;
>  
> +    case FRINDEX:
> +        val &= 0x00003ff8; /* frindex is 14bits and always a multiple of 8 */
> +        break;
> +
>      case CONFIGFLAG:
>          val &= 0x1;
>          if (val) {
> -- 
> 1.7.9.3
> 
>
Alon Levy April 3, 2012, 1:33 p.m. UTC | #2
On Tue, Apr 03, 2012 at 04:16:02PM +0300, Alon Levy wrote:
> On Tue, Apr 03, 2012 at 02:21:47PM +0200, Hans de Goede wrote:
> > frindex is a 14 bits counter, so bits 31-14 should always be 0, and
> > after the commit titled "usb-ehci: frindex always is a 14 bits counter"
> > we rely on frindex always being a multiple of 8. I've not seen this in
> > practice, but theoretically a guest can write a value >= 0x4000 or a value
> > which is not a multiple of 8 value to frindex, this patch ensures that
> > things will still work when that happens.
> 
> Acked-by: Alon Levy <alevy@redhat.com>
I meant:
Reviewed-by: Alon Levy <alevy@redhat.com>

> 
> > 
> > Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> > ---
> >  hw/usb/hcd-ehci.c |    4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
> > index 64b58e3..8865b4e 100644
> > --- a/hw/usb/hcd-ehci.c
> > +++ b/hw/usb/hcd-ehci.c
> > @@ -1102,6 +1102,10 @@ static void ehci_mem_writel(void *ptr, target_phys_addr_t addr, uint32_t val)
> >          val &= USBINTR_MASK;
> >          break;
> >  
> > +    case FRINDEX:
> > +        val &= 0x00003ff8; /* frindex is 14bits and always a multiple of 8 */
> > +        break;
> > +
> >      case CONFIGFLAG:
> >          val &= 0x1;
> >          if (val) {
> > -- 
> > 1.7.9.3
> > 
> > 
>
Gerd Hoffmann April 19, 2012, 12:14 p.m. UTC | #3
On 04/03/12 14:21, Hans de Goede wrote:
> frindex is a 14 bits counter, so bits 31-14 should always be 0, and
> after the commit titled "usb-ehci: frindex always is a 14 bits counter"
> we rely on frindex always being a multiple of 8. I've not seen this in
> practice, but theoretically a guest can write a value >= 0x4000 or a value
> which is not a multiple of 8 value to frindex, this patch ensures that
> things will still work when that happens.

Patch added to usb patch queue.

thanks,
  Gerd
diff mbox

Patch

diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c
index 64b58e3..8865b4e 100644
--- a/hw/usb/hcd-ehci.c
+++ b/hw/usb/hcd-ehci.c
@@ -1102,6 +1102,10 @@  static void ehci_mem_writel(void *ptr, target_phys_addr_t addr, uint32_t val)
         val &= USBINTR_MASK;
         break;
 
+    case FRINDEX:
+        val &= 0x00003ff8; /* frindex is 14bits and always a multiple of 8 */
+        break;
+
     case CONFIGFLAG:
         val &= 0x1;
         if (val) {