hw/intc/bcm2835_ic: reject out-of-range FIQ source values
Subsystems (3)
PATCH 1/1 hw/intc/bcm2835_ic: reject out-of-range FIQ source values
The FIQ_CONTROL register accepts a 7-bit source selector, but only sources 0..71 (64 GPU + 8 ARM IRQs) exist. Values 96..127 cause bcm2835_ic_update() to call extract32(arm_irq_level, start, 1) with start >= 32, which trips the assertion in bitops.h and aborts QEMU.
Reject writes that select a non-existent source and log a guest error, so that a malicious or buggy guest cannot kill the emulator.
Add a qtest that verifies both valid and out-of-range FIQ source selections on raspi3b.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4368
--- hw/intc/bcm2835_ic.c | 13 +++++-- tests/qtest/bcm2835-ic-test.c | 66 +++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 tests/qtest/bcm2835-ic-test.c
hw/intc/bcm2835_ic.c +11 -2
@@ -139,10 +139,19 @@ static void bcm2835_ic_write(void *opaque, hwaddr offset, uint64_t val,BCM2835ICState *s = opaque;switch (offset) { -case FIQ_CONTROL : - s->fiq_select =extract32 (val,0 ,7 ); +case FIQ_CONTROL : { +unsigned fiq_select =extract32 (val,0 ,7 ); + +if (fiq_select >=GPU_IRQS +ARM_IRQS ) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: FIQ select %u out of range\n" , + __func__, fiq_select); +return ; + } + s->fiq_select = fiq_select; s->fiq_enable =extract32 (val,7 ,1 );break ; + }case IRQ_ENABLE_1 : s->gpu_irq_enable |= val;break ;
tests/qtest/bcm2835-ic-test.c new file +66 -0
66 lines not on this page · raw message
tests/qtest/meson.build +1 -1
@@ -274,7 +274,7 @@ qtests_aarch64 = \ ['tpm-tis-device-test', 'tpm-tis-device-swtpm-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_ZYNQMP_ARM') ? ['xlnx-can-test', 'fuzz-xlnx-dp-test'] : []) + \ (config_all_devices.has_key('CONFIG_XLNX_VERSAL') ? ['xlnx-canfd-test', 'xlnx-versal-trng-test'] : []) + \ - (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test', 'bcm2835-i2c-test'] : []) + \ + (config_all_devices.has_key('CONFIG_RASPI') ? ['bcm2835-dma-test', 'bcm2835-i2c-test', 'bcm2835-ic-test'] : []) + \ (config_all_accel.has_key('CONFIG_TCG') and \ config_all_devices.has_key('CONFIG_TPM_TIS_I2C') ? ['tpm-tis-i2c-test', 'tpm-tis-i2c-swtpm-test'] : []) + \ (config_all_devices.has_key('CONFIG_ASPEED_SOC') ? qtests_aspeed64 : []) + \
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 11 lines · Bin Guo
The
FIQ_CONTROLregister accepts a 7-bit source selector, but only sources 0..71 (64 GPU + 8 ARM IRQs) exist. Values 96..127 causebcm2835_ic_update()to callextract32(arm_irq_level, start, 1)with start >= 32, which trips the assertion inbitops.hand aborts QEMU.Reject writes that select a non-existent source and log a guest error, so that a malicious or buggy guest cannot kill the emulator.
Add a qtest that verifies both valid and out-of-range FIQ source selections on raspi3b.
Quoted 8 lines
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4368
Signed-off-by Bin Guo <[email protected]>--- hw/intc/bcm2835_ic.c | 13 +++++-- tests/qtest/bcm2835-ic-test.c | 66 +++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 3 files changed, 78 insertions(+), 3 deletions(-)create mode 100644
tests/qtest/bcm2835-ic-test.c
Peter Maydell
AppliedQuoted 6 lines · Bin Guo
The
FIQ_CONTROLregister accepts a 7-bit source selector, but only sources 0..71 (64 GPU + 8 ARM IRQs) exist. Values 96..127 causebcm2835_ic_update()to callextract32(arm_irq_level, start, 1)with start >= 32, which trips the assertion inbitops.hand aborts QEMU.
Quoted 8 lines
Reject writes that select a non-existent source and log a guest error, so that a malicious or buggy guest cannot kill the emulator.
Add a qtest that verifies both valid and out-of-range FIQ source selections on raspi3b.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4368
Signed-off-by Bin Guo <[email protected]>
Applied to target-arm.next, thanks.
-- PMM
Quoted 11 lines · Bin Guo
The
FIQ_CONTROLregister accepts a 7-bit source selector, but only sources 0..71 (64 GPU + 8 ARM IRQs) exist. Values 96..127 causebcm2835_ic_update()to callextract32(arm_irq_level, start, 1)with start >= 32, which trips the assertion inbitops.hand aborts QEMU.Reject writes that select a non-existent source and log a guest error, so that a malicious or buggy guest cannot kill the emulator.
Add a qtest that verifies both valid and out-of-range FIQ source selections on raspi3b.
Quoted 8 lines
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4368
Signed-off-by Bin Guo <[email protected]>--- hw/intc/bcm2835_ic.c | 13 +++++-- tests/qtest/bcm2835-ic-test.c | 66 +++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 3 files changed, 78 insertions(+), 3 deletions(-)create mode 100644
tests/qtest/bcm2835-ic-test.c
I'm picking this up for currently active stable qemu series. Please let me know if I shouldn't.
Thanks,
/mjt