hw/intc/loongarch_dintc: Fix OOB access in DINT MMIO write handler
Validate guest-controlled cpu_num before using it to index the cpu[] array or pass to async_run_on_cpu(). Without this check, a malicious guest can trigger a NULL pointer dereference in async_run_on_cpu() and an out-of-bounds array access in qemu_set_irq(), causing host crash. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3616 Fixes: 0d148eaf5a3e ("hw/loongarch: Implement dintc set irq") Reported-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Song Gao <gaosong@loongson.cn> Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Message-ID: <20260701065454.1976188-1-gaosong@loongson.cn> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Song Gao committed
Jul 1, 2026 at 14:54 UTC
399ba75fbe308f179da48d183bd48d662ee16199
1 file changed
+13
hw/intc/loongarch_dintc.c
+13
@@ -19,6 +19,7 @@
19
#include "target/loongarch/cpu.h"
20
#include "qemu/error-report.h"
21
#include "system/hw_accel.h"
22
+#include "qemu/log.h"
23
24
/* msg addr field */
25
FIELD(MSG_ADDR, IRQ_NUM, 4, 8)
@@ -52,7 +53,19 @@ static void loongarch_dintc_mem_write(void *opaque, hwaddr addr,
53
CPUState *cs;
54
55
cpu_num = FIELD_EX64(msg_addr, MSG_ADDR, CPU_NUM);
56
+
57
+ /* Validate cpu_num against the configured number of CPUs */
58
+ if (cpu_num >= s->num_cpu) {
59
+ qemu_log_mask(LOG_GUEST_ERROR,
60
+ "loongarch-dintc: invalid cpu number%d\n", cpu_num);
61
+ return;
62
+ }
63
cs = cpu_by_arch_id(cpu_num);
64
+ if (!cs) {
65
+ qemu_log_mask(LOG_GUEST_ERROR,
66
+ "loongarch-dintc: no CPU for arch_id %d\n", cpu_num);
67
+ return;
68
+ }
69
irq_num = FIELD_EX64(msg_addr, MSG_ADDR, IRQ_NUM);
70
71
async_run_on_cpu(cs, do_set_vcpu_dintc_irq,