[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-9.1.3 01/58] hw/intc/openpic: Avoid taking address of out-of-bou
From: |
Michael Tokarev |
Subject: |
[Stable-9.1.3 01/58] hw/intc/openpic: Avoid taking address of out-of-bounds array index |
Date: |
Mon, 27 Jan 2025 23:24:47 +0300 |
The clang sanitizer complains about the code in the EOI handling
of openpic_cpu_write_internal():
UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1 ./build/clang/qemu-system-ppc -M
mac99,graphics=off -display none -kernel day15/invaders.elf
../../hw/intc/openpic.c:1034:16: runtime error: index -1 out of bounds for type
'IRQSource[264]' (aka 'struct IRQSource[264]')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../hw/intc/openpic.c:1034:16 in
This is because we do
src = &opp->src[n_IRQ];
when n_IRQ may be -1. This is in practice harmless because if n_IRQ
is -1 then we don't do anything with the src pointer, but it is
undefined behaviour. (This has been present since this device
was first added to QEMU.)
Rearrange the code so we only do the array index when n_IRQ is not -1.
Cc: qemu-stable@nongnu.org
Fixes: e9df014c0b ("Implement embedded IRQ controller for PowerPC 6xx/740 & 75")
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-id: 20241105180205.3074071-1-peter.maydell@linaro.org
(cherry picked from commit 3bf7dcd47a3da0e86a9347ce5b2b5d5a1dcb5857)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
index 9792a11224..b35b1ee6f7 100644
--- a/hw/intc/openpic.c
+++ b/hw/intc/openpic.c
@@ -1032,13 +1032,14 @@ static void openpic_cpu_write_internal(void *opaque,
hwaddr addr,
s_IRQ = IRQ_get_next(opp, &dst->servicing);
/* Check queued interrupts. */
n_IRQ = IRQ_get_next(opp, &dst->raised);
- src = &opp->src[n_IRQ];
- if (n_IRQ != -1 &&
- (s_IRQ == -1 ||
- IVPR_PRIORITY(src->ivpr) > dst->servicing.priority)) {
- DPRINTF("Raise OpenPIC INT output cpu %d irq %d",
- idx, n_IRQ);
- qemu_irq_raise(opp->dst[idx].irqs[OPENPIC_OUTPUT_INT]);
+ if (n_IRQ != -1) {
+ src = &opp->src[n_IRQ];
+ if (s_IRQ == -1 ||
+ IVPR_PRIORITY(src->ivpr) > dst->servicing.priority) {
+ DPRINTF("Raise OpenPIC INT output cpu %d irq %d",
+ idx, n_IRQ);
+ qemu_irq_raise(opp->dst[idx].irqs[OPENPIC_OUTPUT_INT]);
+ }
}
break;
default:
--
2.39.5
- [Stable-9.1.3 00/58] Patch Round-up for stable 9.1.3, freeze on 2025-02-06, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 02/58] bitops.h: Define bit operations on 'uint32_t' arrays, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 03/58] hw/intc/loongarch_extioi: Use set_bit32() and clear_bit32() for s->isr, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 04/58] linux-user: Fix strace output for s390x mmap(), Michael Tokarev, 2025/01/28
- [Stable-9.1.3 01/58] hw/intc/openpic: Avoid taking address of out-of-bounds array index,
Michael Tokarev <=
- [Stable-9.1.3 09/58] migration: Allow pipes to keep working for fd migrations, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 05/58] virtio-net: Fix size check in dhclient workaround, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 06/58] qdev: Fix set_pci_devfn() to visit option only once, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 07/58] ssh: Do not switch session to non-blocking mode, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 08/58] plugins: add missing export for qemu_plugin_num_vcpus, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 10/58] virtio-net: Add queues before loading them, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 11/58] ppc/spapr: fix drc index mismatch for partially enabled vcpus, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 12/58] scsi: megasas: Internal cdbs have 16-byte length, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 13/58] tests/9p: fix Rreaddir response name, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 14/58] tests/9p: add missing Rgetattr response name, Michael Tokarev, 2025/01/28