[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-7.2.16 01/31] hw/intc/openpic: Avoid taking address of out-of-bo
From: |
Michael Tokarev |
Subject: |
[Stable-7.2.16 01/31] hw/intc/openpic: Avoid taking address of out-of-bounds array index |
Date: |
Tue, 28 Jan 2025 00:40:53 +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 c757adbe53..adc79abbe5 100644
--- a/hw/intc/openpic.c
+++ b/hw/intc/openpic.c
@@ -1035,13 +1035,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-7.2.16 00/31] Patch Round-up for stable 7.2.16, freeze on 2025-02-06, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 01/31] hw/intc/openpic: Avoid taking address of out-of-bounds array index,
Michael Tokarev <=
- [Stable-7.2.16 02/31] bitops.h: Define bit operations on 'uint32_t' arrays, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 03/31] hw/intc/loongarch_extioi: Use set_bit32() and clear_bit32() for s->isr, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 04/31] cirrus-ci: Remove MSYS2 jobs duplicated with gitlab-ci, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 05/31] virtio-net: Fix size check in dhclient workaround, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 06/31] qdev: Fix set_pci_devfn() to visit option only once, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 07/31] ssh: Do not switch session to non-blocking mode, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 08/31] scsi: megasas: Internal cdbs have 16-byte length, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 09/31] tests/9p: fix Rreaddir response name, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 10/31] tests/9p: add missing Rgetattr response name, Michael Tokarev, 2025/01/28
- [Stable-7.2.16 11/31] tests/9p: add 'use-after-unlink' test, Michael Tokarev, 2025/01/28