qemu/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.c hw/gpio/aspeed: Add reg_table_count to AspeedGPIOClass 2024-07-02 07:52:43 +02:00
bcm2835_gpio.c hw/gpio: Constify VMState 2023-12-29 11:17:30 +11:00
bcm2838_gpio.c hw/gpio: Connect SD controller to BCM2838 GPIO 2024-02-27 13:01:42 +00:00
gpio_key.c hw/gpio: Constify VMState 2023-12-29 11:17:30 +11:00
gpio_pwr.c hw/gpio/gpio_pwr: use shutdown function for reboot 2021-07-02 11:48:36 +01:00
imx_gpio.c hw/gpio: Constify VMState 2023-12-29 11:17:30 +11:00
Kconfig hw/gpio: introduce pcf8574 driver 2024-03-11 22:10:18 +01:00
max7310.c hw/gpio: Constify VMState 2023-12-29 11:17:30 +11:00
meson.build misc/pca955*: Move models under hw/gpio 2024-03-25 15:05:38 +01:00
mpc8xxx.c hw/gpio: Constify VMState 2023-12-29 11:17:30 +11:00
npcm7xx_gpio.c hw, target: Add ResetType argument to hold and exit phase methods 2024-04-25 10:21:06 +01:00
nrf51_gpio.c hw/gpio: Constify VMState 2023-12-29 11:17:30 +11:00
omap_gpio.c hw/gpio/omap_gpio: Use CamelCase for TYPE_OMAP2_GPIO type name 2023-01-12 17:15:09 +00:00
pca9552.c misc/pca955*: Move models under hw/gpio 2024-03-25 15:05:38 +01:00
pca9554.c * Fix timeouts in Travis-CI jobs 2024-03-25 14:19:42 +00:00
pcf8574.c hw/gpio: introduce pcf8574 driver 2024-03-11 22:10:18 +01:00
pl061.c hw, target: Add ResetType argument to hold and exit phase methods 2024-04-25 10:21:06 +01:00
sifive_gpio.c hw/gpio: Constify VMState 2023-12-29 11:17:30 +11:00
stm32l4x5_gpio.c hw/gpio: Handle clock migration in STM32L4x5 gpios 2024-05-09 00:07:21 +02:00
trace-events misc/pca955*: Move models under hw/gpio 2024-03-25 15:05:38 +01:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
zaurus.c hw: arm: Remove use of tabs in some source files 2024-05-28 14:20:48 +01:00