Skip to contentSkip to conversation

As reported in qemu-project/qemu#3324

PATCH In review Zexiang Zhang 3 participants 4 messages Mar 26 – Apr 22

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 As reported in qemu-project/qemu#3324

From: kiki <[email protected]>

A malformed IVE value can result in an invalid server field being passed to icp_irq(). The function assumes the server id is valid and may access invalid state otherwise, potentially leading to a crash.

Fix this by validating the server id before using it and ignoring invalid values.

---
 hw/intc/xics.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/intc/xics.c +7 -0
index 1d40c4386d..25c7b0c8a5 100644
@@ -222,6 +222,13 @@ void icp_irq(ICSState *ics, int server, int nr, uint8_t priority)
 
     trace_xics_icp_irq(server, nr, priority);
 
+    if (!icp) {
+        qemu_log_mask(LOG_GUEST_ERROR, "XICS: invalid server %d for IRQ 0x%x\n",
+                      server, nr);
+        ics_reject(ics, nr);
+        return;
+    }
+
     if ((priority >= CPPR(icp))
         || (XISR(icp) && (icp->pending_priority <= priority))) {
         ics_reject(ics, nr);
Signature · 1 line
2.34.1
#1 lore raw

Hello Zexiang,

Quoted 11 lines · Zexiang Zhang

From: kiki <[email protected]>

A malformed IVE value can result in an invalid server field being passed to icp_irq(). The function assumes the server id is valid and may access invalid state otherwise, potentially leading to a crash.

Fix this by validating the server id before using it and ignoring invalid values.

About subject, can you change the subject to decribe the fix, something like 'ppc/pnv: Fix Null Pointer Deref in PHB3', what do you say ?

There's a build error:

../hw/intc/xics.c: In function ‘icp_irq’:
../hw/intc/xics.c:226:9: error: implicit declaration of function ‘qemu_log_mask’; did you mean ‘qemu_log’? [-Wimplicit-function-declaration]
226 | qemu_log_mask(LOG_GUEST_ERROR, "XICS: invalid server %d for IRQ 0x%x\n",
| ^~~~~~~~~~~~~
| qemu_log
../hw/intc/xics.c:226:9: error: nested extern declaration of ‘qemu_log_mask’ [-Werror=nested-externs] ../hw/intc/xics.c:226:23: error: ‘LOG_GUEST_ERROR’ undeclared (first use in this function); did you mean ‘MOD_ESTERROR’?
226 | qemu_log_mask(LOG_GUEST_ERROR, "XICS: invalid server %d for IRQ 0x%x\n",
| ^~~~~~~~~~~~~~~
| MOD_ESTERROR
../hw/intc/xics.c:226:23: note: each undeclared identifier is reported only once for each function it appears in
cc1: all warnings being treated as errors

Add '#include "qemu/log.h", maybe after osdep.h include, to fix above error.

Also, I will recommend running 'make check-functional-ppc64 -j4' to test the patch before post.

Quoted 12 lines
---
 hw/intc/xics.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/intc/xics.c +0 -0
index 1d40c4386d..25c7b0c8a5 100644
@@ -222,6 +222,13 @@ void icp_irq(ICSState *ics, int server, int nr, uint8_t priority)
 
     trace_xics_icp_irq(server, nr, priority);
 

hw/intc/xics.c void icp_irq(ICSState *ics, int server, int nr, uint8_t priority) · line 234

Quoted 10 lines
hw/intc/xics.c +7 -0
+    if (!icp) {
+        qemu_log_mask(LOG_GUEST_ERROR, "XICS: invalid server %d for IRQ 0x%x\n",
+                      server, nr);
+        ics_reject(ics, nr);
+        return;
+    }
+
     if ((priority >= CPPR(icp))
         || (XISR(icp) && (icp->pending_priority <= priority))) {
         ics_reject(ics, nr);

The change looks good to me. Can you post a v2 with the subject and build fixed ?

Thanks,
- Aditya G

#2 lore raw
Quoted 51 lines · Aditya Gupta

Hello Zexiang,

Quoted 11 lines · Zexiang Zhang

From: kiki <[email protected]>

A malformed IVE value can result in an invalid server field being passed to icp_irq(). The function assumes the server id is valid and may access invalid state otherwise, potentially leading to a crash.

Fix this by validating the server id before using it and ignoring invalid values.

About subject, can you change the subject to decribe the fix, something like 'ppc/pnv: Fix Null Pointer Deref in PHB3', what do you say ?

There's a build error:

../hw/intc/xics.c: In function ‘icp_irq’:
../hw/intc/xics.c:226:9: error: implicit declaration of function ‘qemu_log_mask’; did you mean ‘qemu_log’? [-Wimplicit-function-declaration]
226 | qemu_log_mask(LOG_GUEST_ERROR, "XICS: invalid server %d for IRQ 0x%x\n",
| ^~~~~~~~~~~~~
| qemu_log
../hw/intc/xics.c:226:9: error: nested extern declaration of ‘qemu_log_mask’ [-Werror=nested-externs] ../hw/intc/xics.c:226:23: error: ‘LOG_GUEST_ERROR’ undeclared (first use in this function); did you mean ‘MOD_ESTERROR’?
226 | qemu_log_mask(LOG_GUEST_ERROR, "XICS: invalid server %d for IRQ 0x%x\n",
| ^~~~~~~~~~~~~~~
| MOD_ESTERROR
../hw/intc/xics.c:226:23: note: each undeclared identifier is reported only once for each function it appears in
cc1: all warnings being treated as errors

Add '#include "qemu/log.h", maybe after osdep.h include, to fix above error.

Also, I will recommend running 'make check-functional-ppc64 -j4' to test the patch before post.

Quoted 12 lines
---
 hw/intc/xics.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/intc/xics.c +0 -0
index 1d40c4386d..25c7b0c8a5 100644
@@ -222,6 +222,13 @@ void icp_irq(ICSState *ics, int server, int nr, uint8_t priority)
 
     trace_xics_icp_irq(server, nr, priority);
 
Quoted 13 lines

hw/intc/xics.c void icp_irq(ICSState *ics, int server, int nr, uint8_t priority) · line 234

Quoted 10 lines
hw/intc/xics.c +7 -0
+    if (!icp) {
+        qemu_log_mask(LOG_GUEST_ERROR, "XICS: invalid server %d for IRQ 0x%x\n",
+                      server, nr);
+        ics_reject(ics, nr);
+        return;
+    }
+
     if ((priority >= CPPR(icp))
         || (XISR(icp) && (icp->pending_priority <= priority))) {
         ics_reject(ics, nr);

The change looks good to me. Can you post a v2 with the subject and build fixed ?

The bug fix link can go in:

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3324

just above your sign off.

Quoted 3 lines

Thanks,
- Aditya G

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#3 lore raw
Quoted 5 lines · Alex Bennée

Aditya Gupta <[email protected]> writes:
...

      if ((priority >= CPPR(icp))
          || (XISR(icp) && (icp->pending_priority <= priority))) {
          ics_reject(ics, nr);
Quoted 7 lines
Quoted 2 lines

The change looks good to me. Can you post a v2 with the subject and build fixed ?

The bug fix link can go in:

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3324

just above your sign off.

Hey Zexiang,

Ping, planning to send a v2 for this ?

cc +gautam

Thanks,

- Aditya G