qemu/include/hw/gpio
Zheyu Ma 87511bb878 hw/gpio/aspeed: Add reg_table_count to AspeedGPIOClass
ASan detected a global-buffer-overflow error in the aspeed_gpio_read()
function. This issue occurred when reading beyond the bounds of the
reg_table.

To enhance the safety and maintainability of the Aspeed GPIO code, this commit
introduces a reg_table_count member to the AspeedGPIOClass structure. This
change ensures that the size of the GPIO register table is explicitly tracked
and initialized, reducing the risk of errors if new register tables are
introduced in the future.

Reproducer:
cat << EOF | qemu-system-aarch64 -display none \
-machine accel=qtest, -m 512M -machine ast1030-evb -qtest stdio
readq 0x7e780272
EOF

ASAN log indicating the issue:
==2602930==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55a5da29e128 at pc 0x55a5d700dc62 bp 0x7fff096c4e90 sp 0x7fff096c4e88
READ of size 2 at 0x55a5da29e128 thread T0
    #0 0x55a5d700dc61 in aspeed_gpio_read hw/gpio/aspeed_gpio.c:564:14
    #1 0x55a5d933f3ab in memory_region_read_accessor system/memory.c:445:11
    #2 0x55a5d92fba40 in access_with_adjusted_size system/memory.c:573:18
    #3 0x55a5d92f842c in memory_region_dispatch_read1 system/memory.c:1426:16
    #4 0x55a5d92f7b68 in memory_region_dispatch_read system/memory.c:1459:9
    #5 0x55a5d9376ad1 in flatview_read_continue_step system/physmem.c:2836:18
    #6 0x55a5d9376399 in flatview_read_continue system/physmem.c:2877:19
    #7 0x55a5d93775b8 in flatview_read system/physmem.c:2907:12

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2355
Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Andrew Jeffery <andrew@codeconstruct.com.au>
2024-07-02 07:52:43 +02:00
..
aspeed_gpio.h hw/gpio/aspeed: Add reg_table_count to AspeedGPIOClass 2024-07-02 07:52:43 +02:00
bcm2835_gpio.h Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
bcm2838_gpio.h hw/gpio: Connect SD controller to BCM2838 GPIO 2024-02-27 13:01:42 +00:00
imx_gpio.h Use OBJECT_DECLARE_SIMPLE_TYPE when possible 2020-09-18 14:12:32 -04:00
npcm7xx_gpio.h hw/gpio: Add GPIO model for Nuvoton NPCM7xx 2020-10-27 11:10:32 +00:00
nrf51_gpio.h hw/gpio/nrf51: implement DETECT signal 2023-08-22 17:30:59 +01:00
pca9552_regs.h misc/pca955*: Move models under hw/gpio 2024-03-25 15:05:38 +01:00
pca9552.h misc/pca955*: Move models under hw/gpio 2024-03-25 15:05:38 +01:00
pca9554_regs.h misc/pca955*: Move models under hw/gpio 2024-03-25 15:05:38 +01:00
pca9554.h misc/pca955*: Move models under hw/gpio 2024-03-25 15:05:38 +01:00
pcf8574.h hw/gpio: introduce pcf8574 driver 2024-03-11 22:10:18 +01:00
sifive_gpio.h sifive: Use DECLARE_*CHECKER* macros 2020-09-18 13:49:48 -04:00
stm32l4x5_gpio.h hw/arm: Connect STM32L4x5 GPIO to STM32L4x5 SoC 2024-03-07 12:19:25 +00:00