Skip to contentSkip to conversation

hw/intc/arm_gic: Fix interrupt ID in GICD_SGIR register

PATCH Applied Philippe Mathieu-Daudé 5 participants 9 messages Jan 31, 2021 – Feb 3, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/intc/arm_gic: Fix interrupt ID in GICD_SGIR register

Per the ARM Generic Interrupt Controller Architecture specification (document "ARM IHI 0048B.b (ID072613)"), the SGIINTID field is 4 bit, not 10:

- 4.3 Distributor register descriptions
- 4.3.15 Software Generated Interrupt Register, GICD_SG

- Table 4-21 GICD_SGIR bit assignments

The Interrupt ID of the SGI to forward to the specified CPU interfaces. The value of this field is the Interrupt ID, in the range 0-15, for example a value of 0b0011 specifies Interrupt ID 3.

Correct the irq mask to fix an undefined behavior (which eventually lead to a heap-buffer-overflow, see [Buglink]):

   $ echo 'writel 0x8000f00 0xff4affb0' | qemu-system-aarch64 -M virt,accel=qtest -qtest stdio
   [I 1612088147.116987] OPENED
  [R +0.278293] writel 0x8000f00 0xff4affb0
  ../hw/intc/arm_gic.c:1498:13: runtime error: index 944 out of bounds for type 'uint8_t [16][8]'
  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../hw/intc/arm_gic.c:1498:13

---
Isnt it worth a CVE to help distributions track backports?

---
 hw/intc/arm_gic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/arm_gic.c +1 -1
index af41e2fb448..75316329516 100644
@@ -1476,7 +1476,7 @@ static void gic_dist_writel(void *opaque, hwaddr offset,
         int target_cpu;
 
         cpu = gic_get_current_cpu(s);
-        irq = value & 0x3ff;
+        irq = value & 0xf;
         switch ((value >> 24) & 3) {
         case 0:
             mask = (value >> 16) & ALL_CPU_MASK;
Signature · 1 line
2.26.2
#1 lore raw
Quoted 23 lines · Philippe Mathieu-Daudé

Per the ARM Generic Interrupt Controller Architecture specification (document "ARM IHI 0048B.b (ID072613)"), the SGIINTID field is 4 bit, not 10:

- 4.3 Distributor register descriptions
- 4.3.15 Software Generated Interrupt Register, GICD_SG

- Table 4-21 GICD_SGIR bit assignments

The Interrupt ID of the SGI to forward to the specified CPU interfaces. The value of this field is the Interrupt ID, in the range 0-15, for example a value of 0b0011 specifies Interrupt ID 3.

Correct the irq mask to fix an undefined behavior (which eventually lead to a heap-buffer-overflow, see [Buglink]):

   $ echo 'writel 0x8000f00 0xff4affb0' | qemu-system-aarch64 -M virt,accel=qtest -qtest stdio
   [I 1612088147.116987] OPENED
  [R +0.278293] writel 0x8000f00 0xff4affb0
  ../hw/intc/arm_gic.c:1498:13: runtime error: index 944 out of bounds for type 'uint8_t [16][8]'
  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../hw/intc/arm_gic.c:1498:13
Quoted 3 lines
Fixes 9ee6e8bb853 ("ARMv7 support.")

Also:

Quoted 22 lines

---
Isnt it worth a CVE to help distributions track backports?

---
 hw/intc/arm_gic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/intc/arm_gic.c +1 -1
index af41e2fb448..75316329516 100644
@@ -1476,7 +1476,7 @@ static void gic_dist_writel(void *opaque, hwaddr offset,
         int target_cpu;
 
         cpu = gic_get_current_cpu(s);
-        irq = value & 0x3ff;
+        irq = value & 0xf;
         switch ((value >> 24) & 3) {
         case 0:
             mask = (value >> 16) & ALL_CPU_MASK;
#2 lore raw
+-- On Sun, 31 Jan 2021, Philippe Mathieu-Daudé wrote --+
| On 1/31/21 11:34 AM, Philippe Mathieu-Daudé wrote:
| > Per the ARM Generic Interrupt Controller Architecture specification
| > (document "ARM IHI 0048B.b (ID072613)"), the SGIINTID field is 4 bit,
| > not 10:
| > 
| >     - Table 4-21 GICD_SGIR bit assignments
| > 
| >     The Interrupt ID of the SGI to forward to the specified CPU
| >     interfaces. The value of this field is the Interrupt ID, in
| >     the range 0-15, for example a value of 0b0011 specifies
| >     Interrupt ID 3.
| > 
| > diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
| > index af41e2fb448..75316329516 100644
| > --- a/hw/intc/arm_gic.c
| > +++ b/hw/intc/arm_gic.c
| > @@ -1476,7 +1476,7 @@ static void gic_dist_writel(void *opaque, hwaddr offset,
| >          int target_cpu;
| >  
| >          cpu = gic_get_current_cpu(s);
| > -        irq = value & 0x3ff;
| > +        irq = value & 0xf;
| >          switch ((value >> 24) & 3) {
| >          case 0:
| >              mask = (value >> 16) & ALL_CPU_MASK;
| > 

* Looks okay.

| > Correct the irq mask to fix an undefined behavior (which eventually
| > lead to a heap-buffer-overflow, see [Buglink]):
| > 
| >    $ echo 'writel 0x8000f00 0xff4affb0' | qemu-system-aarch64 -M virt,accel=qtest -qtest stdio
| >    [I 1612088147.116987] OPENED
| >   [R +0.278293] writel 0x8000f00 0xff4affb0
| >   ../hw/intc/arm_gic.c:1498:13: runtime error: index 944 out of bounds for type 'uint8_t [16][8]'
| >   SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../hw/intc/arm_gic.c:1498:13
| > 
| > Cc: [email protected]
| > Fixes: 9ee6e8bb853 ("ARMv7 support.")
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913916
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913917
| 
| > ---
| > Isnt it worth a CVE to help distributions track backports?
| > ---

* Please send such report(s) to 'qemu-security' list to be triaged as potential security ones.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
8685 545E B54C 486B C6EB 271E E285 8B5A F050 DE8D

#3 lore raw

Forwarding to qemu-security@ to see if this issue is worth a CVE.

Quoted 58 lines · P J P
+-- On Sun, 31 Jan 2021, Philippe Mathieu-Daudé wrote --+
| On 1/31/21 11:34 AM, Philippe Mathieu-Daudé wrote:
| > Per the ARM Generic Interrupt Controller Architecture specification
| > (document "ARM IHI 0048B.b (ID072613)"), the SGIINTID field is 4 bit,
| > not 10:
| > 
| >     - Table 4-21 GICD_SGIR bit assignments
| > 
| >     The Interrupt ID of the SGI to forward to the specified CPU
| >     interfaces. The value of this field is the Interrupt ID, in
| >     the range 0-15, for example a value of 0b0011 specifies
| >     Interrupt ID 3.
| > 
| > diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
| > index af41e2fb448..75316329516 100644
| > --- a/hw/intc/arm_gic.c
| > +++ b/hw/intc/arm_gic.c
| > @@ -1476,7 +1476,7 @@ static void gic_dist_writel(void *opaque, hwaddr offset,
| >          int target_cpu;
| >  
| >          cpu = gic_get_current_cpu(s);
| > -        irq = value & 0x3ff;
| > +        irq = value & 0xf;
| >          switch ((value >> 24) & 3) {
| >          case 0:
| >              mask = (value >> 16) & ALL_CPU_MASK;
| > 

* Looks okay.

| > Correct the irq mask to fix an undefined behavior (which eventually
| > lead to a heap-buffer-overflow, see [Buglink]):
| > 
| >    $ echo 'writel 0x8000f00 0xff4affb0' | qemu-system-aarch64 -M virt,accel=qtest -qtest stdio
| >    [I 1612088147.116987] OPENED
| >   [R +0.278293] writel 0x8000f00 0xff4affb0
| >   ../hw/intc/arm_gic.c:1498:13: runtime error: index 944 out of bounds for type 'uint8_t [16][8]'
| >   SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../hw/intc/arm_gic.c:1498:13
| > 
| > Cc: [email protected]
| > Fixes: 9ee6e8bb853 ("ARMv7 support.")
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913916
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913917
| 
| > ---
| > Isnt it worth a CVE to help distributions track backports?
| > ---

* Please send such report(s) to 'qemu-security' list to be triaged as potential security ones.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
8685 545E B54C 486B C6EB 271E E285 8B5A F050 DE8D

#4 lore raw
Quoted 22 lines · Philippe Mathieu-Daudé

Forwarding to qemu-security@ to see if this issue is worth a CVE.

| On 1/31/21 11:34 AM, Philippe Mathieu-Daudé wrote:
| > Per the ARM Generic Interrupt Controller Architecture specification
| > (document "ARM IHI 0048B.b (ID072613)"), the SGIINTID field is 4 bit,
| > not 10:
| > 
| >    - Table 4-21 GICD_SGIR bit assignments
| > 
| >    The Interrupt ID of the SGI to forward to the specified CPU
| >    interfaces. The value of this field is the Interrupt ID, in
| >    the range 0-15, for example a value of 0b0011 specifies
| >    Interrupt ID 3.
| > 
| > diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
| > index af41e2fb448..75316329516 100644
| > --- a/hw/intc/arm_gic.c
| > +++ b/hw/intc/arm_gic.c
| > @@ -1476,7 +1476,7 @@ static void gic_dist_writel(void *opaque, hwaddr offset,
| >          int target_cpu;
| >  
| >          cpu = gic_get_current_cpu(s);
Quoted 8 lines
| > -        irq = value & 0x3ff;
| > +        irq = value & 0xf;
| >          switch ((value >> 24) & 3) {
| >          case 0:
| >              mask = (value >> 16) & ALL_CPU_MASK;
| > 
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913916
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913917

* Does above patch address both these bugs? For BZ#1913917 'irq' is derived from 'offset' it seems.

        /* Interrupt Configuration.  */
        irq = (offset - 0xc00) * 4;

Quoted 7 lines
| > Correct the irq mask to fix an undefined behavior (which eventually
| > lead to a heap-buffer-overflow, see [Buglink]):
| > 
| >    $ echo 'writel 0x8000f00 0xff4affb0' | qemu-system-aarch64 -M virt,accel=qtest -qtest stdio
| >    [I 1612088147.116987] OPENED
| >  [R +0.278293] writel 0x8000f00 0xff4affb0
| >  ../hw/intc/arm_gic.c:1498:13: runtime error: index 944 out of bounds for type 'uint8_t [16][8]'
Quoted 8 lines
| >  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../hw/intc/arm_gic.c:1498:13
| > 
| > Cc: [email protected]
| > Fixes: 9ee6e8bb853 ("ARMv7 support.")
|
| > ---
| > Isnt it worth a CVE to help distributions track backports?
| > ---

Thank you for reporting this issue. Will process further.

Thank you.
---
  -P J P
http://feedmug.com

#5 lore raw
Quoted 32 lines · P J P
Quoted 22 lines · Philippe Mathieu-Daudé

Forwarding to qemu-security@ to see if this issue is worth a CVE.

| On 1/31/21 11:34 AM, Philippe Mathieu-Daudé wrote:
| > Per the ARM Generic Interrupt Controller Architecture specification
| > (document "ARM IHI 0048B.b (ID072613)"), the SGIINTID field is 4 bit,
| > not 10:
| > 
| >    - Table 4-21 GICD_SGIR bit assignments
| > 
| >    The Interrupt ID of the SGI to forward to the specified CPU
| >    interfaces. The value of this field is the Interrupt ID, in
| >    the range 0-15, for example a value of 0b0011 specifies
| >    Interrupt ID 3.
| > 
| > diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
| > index af41e2fb448..75316329516 100644
| > --- a/hw/intc/arm_gic.c
| > +++ b/hw/intc/arm_gic.c
| > @@ -1476,7 +1476,7 @@ static void gic_dist_writel(void *opaque, hwaddr offset,
| >          int target_cpu;
| >  
| >          cpu = gic_get_current_cpu(s);
Quoted 8 lines
| > -        irq = value & 0x3ff;
| > +        irq = value & 0xf;
| >          switch ((value >> 24) & 3) {
| >          case 0:
| >              mask = (value >> 16) & ALL_CPU_MASK;
| > 
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913916
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913917
Quoted 4 lines

* Does above patch address both these bugs? For BZ#1913917 'irq' is derived from 'offset' it seems.

        /* Interrupt Configuration.  */
        irq = (offset - 0xc00) * 4;

I haven't done a thorough analysis, simply tried to fixed this bug ASAP as it is public so many users are exposed.

I had the impression the first call (writel 0x8000f00 0x5affaf) break the heap, so the memory is inconsistent when the second call (write 0x8000eff 0x1 0x0) is done, but better have developers familiar with GIC and security auditing this again.

Quoted 16 lines
Quoted 7 lines
| > Correct the irq mask to fix an undefined behavior (which eventually
| > lead to a heap-buffer-overflow, see [Buglink]):
| > 
| >    $ echo 'writel 0x8000f00 0xff4affb0' | qemu-system-aarch64 -M virt,accel=qtest -qtest stdio
| >    [I 1612088147.116987] OPENED
| >  [R +0.278293] writel 0x8000f00 0xff4affb0
| >  ../hw/intc/arm_gic.c:1498:13: runtime error: index 944 out of bounds for type 'uint8_t [16][8]'
Quoted 8 lines
| >  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../hw/intc/arm_gic.c:1498:13
| > 
| > Cc: [email protected]
| > Fixes: 9ee6e8bb853 ("ARMv7 support.")
|
| > ---
| > Isnt it worth a CVE to help distributions track backports?
| > ---
Quoted 1 line

Thank you for reporting this issue. Will process further.

Thank for the quick processing.

Regards,

Phil.

#6 lore raw
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 11 lines · P J P
Quoted 5 lines · Philippe Mathieu-Daudé

Forwarding to qemu-security@ to see if this issue is worth a CVE.

| On 1/31/21 11:34 AM, Philippe Mathieu-Daudé wrote:
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913916
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913917

* Does above patch address both these bugs? For BZ#1913917 'irq' is derived from 'offset' it seems.

        /* Interrupt Configuration.  */
        irq = (offset - 0xc00) * 4;
Quoted 7 lines

I haven't done a thorough analysis, simply tried to fixed this bug ASAP as it is public so many users are exposed.

I had the impression the first call (writel 0x8000f00 0x5affaf) break the heap, so the memory is inconsistent when the second call (write 0x8000eff 0x1 0x0) is done, but better have developers familiar with GIC and security auditing this again.

Philippe is correct here. In both cases the overrun is on the first writel to 0x8000f00, but the fuzzer has for some reason not reported that but instead blundered on until it happens to trigger some other issue that resulted from the memory corruption it induced with the first write.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
| > Correct the irq mask to fix an undefined behavior (which eventually
| > lead to a heap-buffer-overflow, see [Buglink]):
| >
| >    $ echo 'writel 0x8000f00 0xff4affb0' | qemu-system-aarch64 -M virt,accel=qtest -qtest stdio
| >    [I 1612088147.116987] OPENED
| >  [R +0.278293] writel 0x8000f00 0xff4affb0
| >  ../hw/intc/arm_gic.c:1498:13: runtime error: index 944 out of bounds for type 'uint8_t [16][8]'
| >  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../hw/intc/arm_gic.c:1498:13
| >
| > Cc: [email protected]
| > Fixes: 9ee6e8bb853 ("ARMv7 support.")
|
| > ---
| > Isnt it worth a CVE to help distributions track backports?
| > ---
Quoted 1 line
Quoted 1 line

Thank you for reporting this issue. Will process further.

On the CVE:

Since this can affect systems using KVM, this is a security bug for us. However, it only affects an uncommon configuration:
you are only vulnerable if you are using "kernel-irqchip=off" (the default is 'on', and turning it off is an odd thing to do).

I've applied this patch to target-arm.next.

thanks
-- PMM

#7 lore raw
Quoted 23 lines · Peter Maydell
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 11 lines · P J P
Quoted 5 lines · Philippe Mathieu-Daudé

Forwarding to qemu-security@ to see if this issue is worth a CVE.

| On 1/31/21 11:34 AM, Philippe Mathieu-Daudé wrote:
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913916
| > Buglink: https://bugs.launchpad.net/qemu/+bug/1913917

* Does above patch address both these bugs? For BZ#1913917 'irq' is derived from 'offset' it seems.

        /* Interrupt Configuration.  */
        irq = (offset - 0xc00) * 4;
Quoted 7 lines

I haven't done a thorough analysis, simply tried to fixed this bug ASAP as it is public so many users are exposed.

I had the impression the first call (writel 0x8000f00 0x5affaf) break the heap, so the memory is inconsistent when the second call (write 0x8000eff 0x1 0x0) is done, but better have developers familiar with GIC and security auditing this again.

Quoted 6 lines

Philippe is correct here. In both cases the overrun is on the first writel to 0x8000f00, but the fuzzer has for some reason not reported that but instead blundered on until it happens to trigger some other issue that resulted from the memory corruption it induced with the first write.

It happens in the standalone reproducer build with ASAN/--enable-sanitizers, so it seems like an oversight/bug in the Sanitizers, rather than the fuzzer. It is strange that UBSan seemed to detect an OOB index, but proceeded as normal. I should start paying closer attention to those non-fatal UBSan errors.

Quoted 18 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
| > Correct the irq mask to fix an undefined behavior (which eventually
| > lead to a heap-buffer-overflow, see [Buglink]):
| >
| >    $ echo 'writel 0x8000f00 0xff4affb0' | qemu-system-aarch64 -M virt,accel=qtest -qtest stdio
| >    [I 1612088147.116987] OPENED
| >  [R +0.278293] writel 0x8000f00 0xff4affb0
| >  ../hw/intc/arm_gic.c:1498:13: runtime error: index 944 out of bounds for type 'uint8_t [16][8]'
| >  SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../hw/intc/arm_gic.c:1498:13
| >
| > Cc: [email protected]
| > Fixes: 9ee6e8bb853 ("ARMv7 support.")
|
| > ---
| > Isnt it worth a CVE to help distributions track backports?
| > ---
Quoted 1 line
Quoted 1 line

Thank you for reporting this issue. Will process further.

Quoted 9 lines

On the CVE:

Since this can affect systems using KVM, this is a security bug for us. However, it only affects an uncommon configuration:
you are only vulnerable if you are using "kernel-irqchip=off" (the default is 'on', and turning it off is an odd thing to do).

I've applied this patch to target-arm.next.

Ah I had a gut feeling there was a GIC in kvm. CVE or no CVE, --n_bugs -Alex

Quoted 2 lines

thanks
-- PMM

#8 lore raw
In reply to Peter Maydell
Quoted 7 lines · Peter Maydell

On the CVE:

Since this can affect systems using KVM, this is a security bug for us. However, it only affects an uncommon configuration:
you are only vulnerable if you are using "kernel-irqchip=off" (the default is 'on', and turning it off is an odd thing to do).

'CVE-2021-20221' assigned by Red Hat Inc.
  -> https://bugs.launchpad.net/qemu/+bug/1914353/comments/3

Thank you.
---
  -P J P
http://feedmug.com