Skip to contentSkip to conversation

dma: rc4030: limit interval timer reload value

PATCH In review P J P 6 participants 10 messages Oct 12, 2016 – Mar 14, 2017

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 dma: rc4030: limit interval timer reload value

From: Prasad J Pandit <[email protected]>

The JAZZ RC4030 chipset emulator has a periodic timer and associated interval reload register. The reload value is used as divider when computing timer's next tick value. If reload value is large, it could lead to divide by zero error. Limit the interval reload value to avoid it.

---
 hw/dma/rc4030.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/dma/rc4030.c +1 -1
index 2f2576f..c1b4997 100644
@@ -460,7 +460,7 @@ static void rc4030_write(void *opaque, hwaddr addr, uint64_t data,
         break;
     /* Interval timer reload */
     case 0x0228:
-        s->itr = val;
+        s->itr = val & 0x01FF;
         qemu_irq_lower(s->timer_irq);
         set_next_tick(s);
         break;
Signature · 1 line
2.5.5
#1 lore raw

Any ideas about this fix?

Regards,
-Gonglei

Quoted 40 lines

-----Original Message-----
From: Qemu-devel [mailto:[email protected]] On Behalf Of P J P
Sent: Wednesday, October 12, 2016 8:38 PM
To: Qemu Developers
Cc: Paolo Bonzini; Huawei PSIRT; Prasad J Pandit; Michael S. Tsirkin
Subject: [Qemu-devel] [PATCH] dma: rc4030: limit interval timer reload value

From: Prasad J Pandit <[email protected]>

The JAZZ RC4030 chipset emulator has a periodic timer and associated interval reload register. The reload value is used as divider when computing timer's next tick value. If reload value is large, it could lead to divide by zero error. Limit the interval reload value to avoid it.

---
 hw/dma/rc4030.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/dma/rc4030.c +1 -1
index 2f2576f..c1b4997 100644
@@ -460,7 +460,7 @@ static void rc4030_write(void *opaque, hwaddr addr,
 uint64_t data,
         break;
     /* Interval timer reload */
     case 0x0228:
-        s->itr = val;
+        s->itr = val & 0x01FF;
         qemu_irq_lower(s->timer_irq);
         set_next_tick(s);
         break;

--
2.5.5

#2 lore raw
Quoted 1 line · Gonglei (Arei)

Any ideas about this fix?

It seems sensible, but perhaps the field is even smaller. Let's CC Hervé and Aurelien as I don't have a datasheet for this device.

Also, s->itr is used here:

    tm_hz = 1000 / (s->itr + 1);

    timer_mod(s->periodic_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
                   NANOSECONDS_PER_SECOND / tm_hz);

and this is the same as

    timer_mod(s->periodic_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
              NANOSECONDS_PER_SECOND / 1000 * (s->itr + 1));

so perhaps it's better to do it like that.

Paolo

Quoted 43 lines
Quoted 40 lines

-----Original Message-----
From: Qemu-devel [mailto:[email protected]] On Behalf Of P J P
Sent: Wednesday, October 12, 2016 8:38 PM
To: Qemu Developers
Cc: Paolo Bonzini; Huawei PSIRT; Prasad J Pandit; Michael S. Tsirkin
Subject: [Qemu-devel] [PATCH] dma: rc4030: limit interval timer reload value

From: Prasad J Pandit <[email protected]>

The JAZZ RC4030 chipset emulator has a periodic timer and associated interval reload register. The reload value is used as divider when computing timer's next tick value. If reload value is large, it could lead to divide by zero error. Limit the interval reload value to avoid it.

---
 hw/dma/rc4030.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/dma/rc4030.c +1 -1
index 2f2576f..c1b4997 100644
@@ -460,7 +460,7 @@ static void rc4030_write(void *opaque, hwaddr addr,
 uint64_t data,
         break;
     /* Interval timer reload */
     case 0x0228:
-        s->itr = val;
+        s->itr = val & 0x01FF;
         qemu_irq_lower(s->timer_irq);
         set_next_tick(s);
         break;

--
2.5.5

#3 lore raw

Hi,

Quoted 7 lines · Paolo Bonzini
Quoted 1 line · Gonglei (Arei)

Any ideas about this fix?

It seems sensible, but perhaps the field is even smaller. Let's CC Hervé and Aurelien as I don't have a datasheet for this device.

Sorry for the delay...

I don't have any datasheet for this device either, so I tested with real programs. Those initialize itr field to either 0 or to 9, so your mask doesn't change anything.

Quoted 61 lines

Also, s->itr is used here:

    tm_hz = 1000 / (s->itr + 1);

    timer_mod(s->periodic_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
                   NANOSECONDS_PER_SECOND / tm_hz);

and this is the same as

    timer_mod(s->periodic_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
              NANOSECONDS_PER_SECOND / 1000 * (s->itr + 1));

so perhaps it's better to do it like that.

Paolo

Quoted 43 lines
Quoted 40 lines

-----Original Message-----
From: Qemu-devel [mailto:[email protected]] On Behalf Of P J P
Sent: Wednesday, October 12, 2016 8:38 PM
To: Qemu Developers
Cc: Paolo Bonzini; Huawei PSIRT; Prasad J Pandit; Michael S. Tsirkin
Subject: [Qemu-devel] [PATCH] dma: rc4030: limit interval timer reload value

From: Prasad J Pandit <[email protected]>

The JAZZ RC4030 chipset emulator has a periodic timer and associated interval reload register. The reload value is used as divider when computing timer's next tick value. If reload value is large, it could lead to divide by zero error. Limit the interval reload value to avoid it.

---
 hw/dma/rc4030.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/dma/rc4030.c +1 -1
index 2f2576f..c1b4997 100644
@@ -460,7 +460,7 @@ static void rc4030_write(void *opaque, hwaddr addr,
 uint64_t data,
         break;
     /* Interval timer reload */
     case 0x0228:
-        s->itr = val;
+        s->itr = val & 0x01FF;
         qemu_irq_lower(s->timer_irq);
         set_next_tick(s);
         break;

--
2.5.5

#4 lore raw
Quoted 14 lines

Subject: Re: [Qemu-devel] [PATCH] dma: rc4030: limit interval timer reload value

Hi,

Quoted 7 lines · Paolo Bonzini
Quoted 1 line · Gonglei (Arei)

Any ideas about this fix?

It seems sensible, but perhaps the field is even smaller. Let's CC Hervé and Aurelien as I don't have a datasheet for this device.

Quoted 9 lines

Sorry for the delay...

I don't have any datasheet for this device either, so I tested with real programs.
Those initialize itr field to either 0 or to 9, so your mask doesn't change anything.

Thanks for your feedback. Paolo, maybe you can post a formal patch :)

Regards,
-Gonglei

Quoted 66 lines
Quoted 6 lines

Also, s->itr is used here:

    tm_hz = 1000 / (s->itr + 1);

    timer_mod(s->periodic_timer,

qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +

Quoted 5 lines
                   NANOSECONDS_PER_SECOND / tm_hz);

and this is the same as

    timer_mod(s->periodic_timer,

qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +

Quoted 14 lines
              NANOSECONDS_PER_SECOND / 1000 * (s->itr + 1));

so perhaps it's better to do it like that.

Paolo

Quoted 8 lines
Quoted 8 lines

-----Original Message-----
From: Qemu-devel [mailto:[email protected]] On Behalf Of P J P
Sent: Wednesday, October 12, 2016 8:38 PM
To: Qemu Developers
Cc: Paolo Bonzini; Huawei PSIRT; Prasad J Pandit; Michael S. Tsirkin
Subject: [Qemu-devel] [PATCH] dma: rc4030: limit interval timer reload

value

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

From: Prasad J Pandit <[email protected]>

The JAZZ RC4030 chipset emulator has a periodic timer and associated interval reload register. The reload value is used as divider when computing timer's next tick value. If reload value is large, it could lead to divide by zero error. Limit the interval reload value to avoid it.

---
 hw/dma/rc4030.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 5 lines
Quoted 5 lines

hw/dma/rc4030.c static void rc4030_write(void *opaque, hwaddr

Quoted 5 lines
hw/dma/rc4030.c +0 -0
index 2f2576f..c1b4997 100644
@@ -460,7 +460,7 @@ static void rc4030_write(void *opaque, hwaddr

addr,

Quoted 16 lines
Quoted 15 lines
Quoted 12 lines
hw/dma/rc4030.c +1 -1
 uint64_t data,
         break;
     /* Interval timer reload */
     case 0x0228:
-        s->itr = val;
+        s->itr = val & 0x01FF;
         qemu_irq_lower(s->timer_irq);
         set_next_tick(s);
         break;

--
2.5.5

author
#5 lore raw
In reply to Hervé Poussineau
+-- On Wed, 16 Nov 2016, Hervé Poussineau wrote --+
| I don't have any datasheet for this device either, so I tested with real 
| programs. Those initialize itr field to either 0 or to 9, so your mask 
| doesn't change anything.
| 
| Tested-by: Hervé Poussineau <[email protected]>

Thank you so much. To confirm, do we need to update the mask to maybe
0x000F?

| > > >      case 0x0228:
| > > > -        s->itr = val;
| > > > +        s->itr = val & 0x01FF;
| > > >          qemu_irq_lower(s->timer_irq);

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#6 lore raw
Quoted 9 lines · P J P
+-- On Wed, 16 Nov 2016, Hervé Poussineau wrote --+
| I don't have any datasheet for this device either, so I tested with real
| programs. Those initialize itr field to either 0 or to 9, so your mask
| doesn't change anything.
|
| Tested-by: Hervé Poussineau <[email protected]>

Thank you so much. To confirm, do we need to update the mask to maybe
0x000F?

No, I think that 0x1ff is fine.
0xf mask means timers between 10ms to 1000ms
0x1ff mask means timers between 2ms to 1000ms, which seem also acceptable to me.

Hervé

Quoted 11 lines
| > > >      case 0x0228:
| > > > -        s->itr = val;
| > > > +        s->itr = val & 0x01FF;
| > > >          qemu_irq_lower(s->timer_irq);

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#7 lore raw
In reply to P J P
Quoted 9 lines · P J P
+-- On Wed, 16 Nov 2016, Hervé Poussineau wrote --+
| I don't have any datasheet for this device either, so I tested with real 
| programs. Those initialize itr field to either 0 or to 9, so your mask 
| doesn't change anything.
| 
| Tested-by: Hervé Poussineau <[email protected]>

Thank you so much. To confirm, do we need to update the mask to maybe
0x000F?

It's not needed if you change it as suggested elsewhere in the thread.

    timer_mod(s->periodic_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
              NANOSECONDS_PER_SECOND / 1000 * (s->itr + 1));

Thanks,

Paolo

Quoted 4 lines
| > > >      case 0x0228:
| > > > -        s->itr = val;
| > > > +        s->itr = val & 0x01FF;
| > > >          qemu_irq_lower(s->timer_irq);
#8 lore raw
In reply to Hervé Poussineau
Quoted 11 lines · Hervé Poussineau

Hi,

Quoted 7 lines · Paolo Bonzini
Quoted 1 line · Gonglei (Arei)

Any ideas about this fix?

It seems sensible, but perhaps the field is even smaller. Let's CC Hervé and Aurelien as I don't have a datasheet for this device.

Quoted 9 lines

Sorry for the delay...

I don't have any datasheet for this device either, so I tested with real programs.
Those initialize itr field to either 0 or to 9, so your mask doesn't change anything.

I'm coming to this thread from the Fedora bug for this CVE,
https://bugzilla.redhat.com/show_bug.cgi?id=1384876

I don't see this patch in qemu.git yet, can someone pick it up for a pull request?

Thanks,
Cole

#9 lore raw
Quoted 2 lines · Cole Robinson

I'm coming to this thread from the Fedora bug for this CVE,
https://bugzilla.redhat.com/show_bug.cgi?id=1384876

FWIW this isn't a CVE issue from the point of view of upstream QEMU, because it only affects the MIPS Jazz board, which (if I'm reading the source correctly) you can't use with KVM.

Still, we should fix the bug...

Quoted 2 lines

I don't see this patch in qemu.git yet, can someone pick it up for a pull request?

Ccing the MIPS maintainer may help in achieving this :-)

thanks
-- PMM