hw/arm/aspeed_ast2700-fc: Fix null pointer dereference
v3 cover hw/arm/aspeed_ast2700-fc: Fix null pointer dereference
Clang's sanitizer reports a runtime error when booting with '-net nic -net user', due to a null pointer being passed to memory_region_find(), which subsequently triggers a crash in flatview_lookup().
Root cause:
- Missing NIC configuration in the CA35 initialization.
Fix:
- Reduce ca35 ram size from 2GiB to 1GiB to align with ast2700a1-evb, where the ram-container is defined as 1GiB in its class.
- Add nic configuration in ast2700fc's ca35 init function.
v2:
- Split the CA35 memory mapping into a separate patch.
- Added a new patch to fix BMC memory mapping in the fby35 machine, which had a similar issue (unmapped system_memory).
- Removed Change-Id tag from commit messages
v3:
- Fixed issue with incorrectly inheriting TYPE_ASPEED_MACHINE.
- Rewrote the commit message for "Map BMC memory into system memory".
- Added more details to the commit message for "Fix unimplemented region overlap with VBootROM".
Steven Lee (5):
hw/arm/aspeed_ast2700-fc: Fix null pointer dereference in ca35 init hw/arm/aspeed_ast27x0: Fix unimplemented region overlap with vbootrom hw/arm/aspeed_ast27x0-fc: Map ca35 memory into system memory hw/arm/fby35: Map BMC memory into system memory
docs: Remove ast2700fc from Aspeed family boards
docs/system/arm/aspeed.rst | 2 +- hw/arm/aspeed_ast27x0-fc.c | 10 +++++++++- hw/arm/aspeed_ast27x0.c | 4 ++-- hw/arm/fby35.c | 1 + 4 files changed, 13 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/5 hw/arm/aspeed_ast2700-fc: Fix null pointer dereference in ca35 init
Clang's sanitizer reports a runtime error when booting with '-net nic -net user', due to a null pointer being passed to memory_region_find(), which subsequently triggers a crash in flatview_lookup().
Root cause:
- Missing NIC configuration in the CA35 initialization.
Fix:
- Reduce ca35 ram size from 2GiB to 1GiB to align with ast2700a1-evb, where the ram-container is defined as 1GiB in its class.
- Add nic configuration in ast2700fc's ca35 init function.
--- hw/arm/aspeed_ast27x0-fc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
hw/arm/aspeed_ast27x0-fc.c +8 -1
@@ -48,7 +48,7 @@ struct Ast2700FCState {bool mmio_exec; }; -#define AST2700FC_BMC_RAM_SIZE (2 * GiB) +#define AST2700FC_BMC_RAM_SIZE (1 * GiB)#define AST2700FC_CM4_DRAM_SIZE (32 * MiB)#define AST2700FC_HW_STRAP1 0x000000C0
@@ -86,6 +86,13 @@ static void ast2700fc_ca35_init(MachineState *machine) AST2700FC_BMC_RAM_SIZE, &error_abort)) {return ; } + +for (int i =0 ; i < sc->macs_num; i++) { +if (!qemu_configure_nic_device (DEVICE (&soc->ftgmac100[i]), + true,NULL )) { +break ; + } + }if (!object_property_set_int (OBJECT (&s->ca35),"hw-strap1" ,AST2700FC_HW_STRAP1 , &error_abort)) {return ;
Signature · 1 line
2.43.0
Re: [PATCH v3 1/5] hw/arm/aspeed_ast2700-fc: Fix null pointer dereference in ca35 init
Hello Steven
Quoted 5 lines · Steven Lee
Clang's sanitizer reports a runtime error when booting with '-net nic -net user', due to a null pointer being passed to
memory_region_find(), which subsequently triggers a crash inflatview_lookup().
Quoted 7 lines
Root cause:
- Missing NIC configuration in the CA35 initialization.Fix:
- Reduce ca35 ram size from 2GiB to 1GiB to align with ast2700a1-evb, where the ram-container is defined as 1GiB in its class.
- Add nic configuration in ast2700fc's ca35 init function.
Please split in 2.
Thanks,
C.
Quoted 32 lines
Signed-off-by Steven Lee <[email protected]>--- hw/arm/aspeed_ast27x0-fc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)hw/arm/aspeed_ast27x0-fc.c +8
-1@@ -48,7 +48,7 @@ struct Ast2700FCState {bool mmio_exec; }; -#define AST2700FC_BMC_RAM_SIZE (2 * GiB) +#define AST2700FC_BMC_RAM_SIZE (1 * GiB)#define AST2700FC_CM4_DRAM_SIZE (32 * MiB)#define AST2700FC_HW_STRAP1 0x000000C0@@ -86,6 +86,13 @@ static void ast2700fc_ca35_init(MachineState *machine) AST2700FC_BMC_RAM_SIZE, &error_abort)) {return ; } + +for (int i =0 ; i < sc->macs_num; i++) { +if (!qemu_configure_nic_device (DEVICE (&soc->ftgmac100[i]), + true,NULL )) { +break ; + } + }if (!object_property_set_int (OBJECT (&s->ca35),"hw-strap1" ,AST2700FC_HW_STRAP1 , &error_abort)) {return ;
RE: [PATCH v3 1/5] hw/arm/aspeed_ast2700-fc: Fix null pointer dereference in ca35 init
Hi Cédric,
Quoted 25 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Thursday, May 22, 2025 3:52 PM
To: Steven Lee <[email protected]>; Peter Maydell <[email protected]>; Troy Lee <[email protected]>; Jamin Lin <[email protected]>; Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>; open list:ASPEED BMCs <[email protected]>; open list:All patches CC here <[email protected]>
Cc: Troy Lee <[email protected]>; [email protected]; Yunlin Tang <[email protected]>
Subject: Re: [PATCH v3 1/5] hw/arm/aspeed_ast2700-fc: Fix null pointer dereference in ca35 initHello Steven
Quoted 8 lines · Steven Lee
Clang's sanitizer reports a runtime error when booting with '-net nic -net user', due to a null pointer being passed to
memory_region_find(), which subsequently triggers a crash inflatview_lookup().Root cause:
- Missing NIC configuration in the CA35 initialization.
Quoted 7 lines
Quoted 4 lines
Fix:
- Reduce ca35 ram size from 2GiB to 1GiB to align with ast2700a1-evb, where the ram-container is defined as 1GiB in its class.
- Add nic configuration in ast2700fc's ca35 init function.Please split in 2.
Will split in v4
Regards,
Steven
Quoted 37 lines
Quoted 12 lines
Signed-off-by Steven Lee <[email protected]>--- hw/arm/aspeed_ast27x0-fc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)hw/arm/aspeed_ast27x0-fc.c +0
-0hw/arm/aspeed_ast27x0-fc.c struct Ast2700FCState { · line 54
Quoted 8 lines
hw/arm/aspeed_ast27x0-fc.c +1
-1@@ -48,7 +48,7 @@ struct Ast2700FCState {bool mmio_exec; }; -#define AST2700FC_BMC_RAM_SIZE (2 * GiB) +#define AST2700FC_BMC_RAM_SIZE (1 * GiB)#define AST2700FC_CM4_DRAM_SIZE (32 * MiB)#define AST2700FC_HW_STRAP1 0x000000C0 @@ -86,6 +86,13 @@static
Quoted 2 lines
void
ast2700fc_ca35_init(MachineState *machine)AST2700FC_BMC_RAM_SIZE,
&error_abort)) {hw/arm/aspeed_ast27x0-fc.c static void ast2700fc_ca35_init(MachineState *machine)
Quoted 11 lines
return; }hw/arm/aspeed_ast27x0-fc.c +7
-0+ +for (int i =0 ; i < sc->macs_num; i++) { +if (!qemu_configure_nic_device (DEVICE (&soc->ftgmac100[i]), + true,NULL )) { +break ; + } + } if (!object_property_set_int(OBJECT(&s->ca35), "hw-strap1", AST2700FC_HW_STRAP1,
&error_abort)) {Quoted 1 line
return;
PATCH v3 2/5 hw/arm/aspeed_ast27x0: Fix unimplemented region overlap with vbootrom
In reply to Steven Lee viaThe unimplemented memory region overlaps with the VBootROM address range, causing incorrect memory layout.
This patch adjusts the size and start address of the unimplemented region to avoid collision. The IO memory region (ASPEED_DEV_IOMEM) is now moved to 0x20000 to reserve space for VBootROM at 0x0.
Although the memory range 0x20000 - 0x10000000 is undefined in the datasheet and should not be required, further testing shows OP-TEE or U-Boot may access 0x400000 during early boot. Removing the unimplemented region causes firmware hangs.
To prevent unexpected accesses, retain the region as a safeguard.
--- hw/arm/aspeed_ast27x0.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/arm/aspeed_ast27x0.c +2 -2
@@ -23,14 +23,14 @@#include "qobject/qlist.h" #include "qemu/log.h" -#define AST2700_SOC_IO_SIZE 0x01000000 +#define AST2700_SOC_IO_SIZE 0x00FE0000#define AST2700_SOC_IOMEM_SIZE 0x01000000#define AST2700_SOC_DPMCU_SIZE 0x00040000#define AST2700_SOC_LTPI_SIZE 0x01000000static const hwaddr aspeed_soc_ast2700_memmap[] = { - [ASPEED_DEV_IOMEM ] =0x00000000 , [ASPEED_DEV_VBOOTROM ] =0x00000000 , + [ASPEED_DEV_IOMEM ] =0x00020000 , [ASPEED_DEV_SRAM ] =0x10000000 , [ASPEED_DEV_DPMCU ] =0x11000000 , [ASPEED_DEV_IOMEM0 ] =0x12000000 ,
Signature · 1 line
2.43.0
PATCH v3 2/5 hw/arm/aspeed_ast27x0: Remove unused iomem region overlapping VBootROM
In reply to Steven Lee viaThe iomem region at 0x00000000 is unused and overlaps with VBootROM. Removing it avoids incorrect memory layout.
--- hw/arm/aspeed_ast27x0.c | 8 -------- 1 file changed, 8 deletions(-)
hw/arm/aspeed_ast27x0.c +0 -8
@@ -23,13 +23,11 @@#include "qobject/qlist.h" #include "qemu/log.h" -#define AST2700_SOC_IO_SIZE 0x01000000#define AST2700_SOC_IOMEM_SIZE 0x01000000#define AST2700_SOC_DPMCU_SIZE 0x00040000#define AST2700_SOC_LTPI_SIZE 0x01000000static const hwaddr aspeed_soc_ast2700_memmap[] = { - [ASPEED_DEV_IOMEM ] =0x00000000 , [ASPEED_DEV_VBOOTROM ] =0x00000000 , [ASPEED_DEV_SRAM ] =0x10000000 , [ASPEED_DEV_DPMCU ] =0x11000000 ,
@@ -521,8 +519,6 @@ static void aspeed_soc_ast2700_init(Object *obj) TYPE_UNIMPLEMENTED_DEVICE);object_initialize_child (obj,"ltpi" , &s->ltpi,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"iomem" , &s->iomem, -TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"iomem0" , &s->iomem0,TYPE_UNIMPLEMENTED_DEVICE ); object_initialize_child(obj, "iomem1", &s->iomem1,
@@ -942,10 +938,6 @@ static void aspeed_soc_ast2700_realize(DeviceState *dev, Error **errp)"aspeed.ltpi" , sc->memmap[ASPEED_DEV_LTPI ], AST2700_SOC_LTPI_SIZE); -aspeed_mmio_map_unimplemented (s,SYS_BUS_DEVICE (&s->iomem), -"aspeed.io" , - sc->memmap[ASPEED_DEV_IOMEM ], -AST2700_SOC_IO_SIZE ); aspeed_mmio_map_unimplemented(s, SYS_BUS_DEVICE(&s->iomem0), "aspeed.iomem0", sc->memmap[ASPEED_DEV_IOMEM0],
Signature · 1 line
2.43.0
RE: [PATCH v3 2/5] hw/arm/aspeed_ast27x0: Remove unused iomem region overlapping VBootROM
Hi reviewers,
Please ignore this patch - I mistakenly sent two versions of patch 2/5.
The correct one is titled:
[PATCH v3 2/5] hw/arm/aspeed_ast27x0: Fix unimplemented region overlap with VBootROM
Sorry for the confusion.
Regards,
Steven
Quoted 64 lines
-----Original Message-----
From: Steven Lee <[email protected]>
Sent: Thursday, May 22, 2025 11:36 AM
To: Cédric Le Goater <[email protected]>; Peter Maydell <[email protected]>; Troy Lee <[email protected]>; Jamin Lin <[email protected]>; Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>; open list:ASPEED BMCs <[email protected]>; open list:All patches CC here <[email protected]>
Cc: Troy Lee <[email protected]>; [email protected]; Yunlin Tang <[email protected]>; Steven Lee <[email protected]>
Subject: [PATCH v3 2/5] hw/arm/aspeed_ast27x0: Remove unused iomem region overlapping VBootROMThe iomem region at
0x00000000is unused and overlaps with VBootROM. Removing it avoids incorrect memory layout.Signed-off-by Steven Lee <[email protected]>--- hw/arm/aspeed_ast27x0.c | 8 -------- 1 file changed, 8 deletions(-)hw/arm/aspeed_ast27x0.c index renamed from hw/arm/aspeed_ast27x0.c +0
-0
1974a25766..328897ded0100644hw/arm/aspeed_ast27x0.c +0
-4@@ -23,13 +23,11 @@#include "qobject/qlist.h" #include "qemu/log.h" -#define AST2700_SOC_IO_SIZE 0x01000000#define AST2700_SOC_IOMEM_SIZE 0x01000000#define AST2700_SOC_DPMCU_SIZE 0x00040000#define AST2700_SOC_LTPI_SIZE 0x01000000static const hwaddr aspeed_soc_ast2700_memmap[] = { - [ASPEED_DEV_IOMEM ] =0x00000000 , [ASPEED_DEV_VBOOTROM ] =0x00000000 , [ASPEED_DEV_SRAM ] =0x10000000 , [ASPEED_DEV_DPMCU ] =0x11000000 ,@@ -521,8 +519,6 @@ static void aspeed_soc_ast2700_init(Object *obj) TYPE_UNIMPLEMENTED_DEVICE);object_initialize_child (obj,"ltpi" , &s->ltpi,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"iomem" , &s->iomem, -TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"iomem0" , &s->iomem0,TYPE_UNIMPLEMENTED_DEVICE ); object_initialize_child(obj, "iomem1", &s->iomem1, @@ -942,10 +938,6@@ static void
aspeed_soc_ast2700_realize(DeviceState *dev, Error **errp)"aspeed.ltpi", sc->memmap[ASPEED_DEV_LTPI], AST2700_SOC_LTPI_SIZE);hw/arm/aspeed_ast27x0.c +0
-3- aspeed_mmio_map_unimplemented(s, SYS_BUS_DEVICE(&s->iomem), - "aspeed.io", -sc->memmap[ASPEED_DEV_IOMEM],
- AST2700_SOC_IO_SIZE); aspeed_mmio_map_unimplemented(s, SYS_BUS_DEVICE(&s->iomem0), "aspeed.iomem0",sc->memmap[ASPEED_DEV_IOMEM0],
--
2.43.0
PATCH v3 3/5 hw/arm/aspeed_ast27x0-fc: Map ca35 memory into system memory
In reply to Steven Lee viaMap the CA35 memory region as a subregion of system_memory to ensure a valid FlatView. This prevents failures in APIs that rely on the global memory view, such as rom_check_and_register_reset().
--- hw/arm/aspeed_ast27x0-fc.c | 1 + 1 file changed, 1 insertion(+)
hw/arm/aspeed_ast27x0-fc.c +1 -0
@@ -68,6 +68,7 @@ static void ast2700fc_ca35_init(MachineState *machine)memory_region_init (&s->ca35_memory,OBJECT (&s->ca35),"ca35-memory" ,UINT64_MAX ); +memory_region_add_subregion (get_system_memory (),0 , &s->ca35_memory);if (!memory_region_init_ram (&s->ca35_dram,OBJECT (&s->ca35),"ca35-dram" ,AST2700FC_BMC_RAM_SIZE , &error_abort)) {
Signature · 1 line
2.43.0
Re: [PATCH v3 3/5] hw/arm/aspeed_ast27x0-fc: Map ca35 memory into system memory
Quoted 5 lines · Steven Lee
Map the CA35 memory region as a subregion of
system_memoryto ensure a valid FlatView. This prevents failures in APIs that rely on the global memory view, such asrom_check_and_register_reset().Signed-off-by Steven Lee <[email protected]>
Thanks,
C.
Quoted 16 lines
--- hw/arm/aspeed_ast27x0-fc.c | 1 + 1 file changed, 1 insertion(+)hw/arm/aspeed_ast27x0-fc.c +1
-0@@ -68,6 +68,7 @@ static void ast2700fc_ca35_init(MachineState *machine)memory_region_init (&s->ca35_memory,OBJECT (&s->ca35),"ca35-memory" ,UINT64_MAX ); +memory_region_add_subregion (get_system_memory (),0 , &s->ca35_memory);if (!memory_region_init_ram (&s->ca35_dram,OBJECT (&s->ca35),"ca35-dram" ,AST2700FC_BMC_RAM_SIZE , &error_abort)) {
PATCH v3 4/5 hw/arm/fby35: Map BMC memory into system memory
In reply to Steven Lee viaAdd the BMC memory region as a subregion of system_memory so that modules relying on system memory can operate correctly.
--- hw/arm/fby35.c | 1 + 1 file changed, 1 insertion(+)
hw/arm/fby35.c +1 -0
@@ -77,6 +77,7 @@ static void fby35_bmc_init(Fby35State *s)memory_region_init (&s->bmc_memory,OBJECT (&s->bmc),"bmc-memory" ,UINT64_MAX ); +memory_region_add_subregion (get_system_memory (),0 , &s->bmc_memory);memory_region_init_ram (&s->bmc_dram,OBJECT (&s->bmc),"bmc-dram" ,FBY35_BMC_RAM_SIZE , &error_abort);
Signature · 1 line
2.43.0
PATCH v3 5/5 docs: Remove ast2700fc from Aspeed family boards
In reply to Steven Lee viaThe ast2700fc machine is now covered in the dedicated ast2700-evb section. Listing it in the general Aspeed board family list is redundant.
--- docs/system/arm/aspeed.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
docs/system/arm/aspeed.rst +1 -1
@@ -1,4 +1,4 @@ -Aspeed family boards (``ast2500-evb``, ``ast2600-evb``, ``ast2700-evb``, ``ast2700fc``, ``bletchley-bmc``, ``fuji-bmc``, ``fby35-bmc``, ``fp5280g2-bmc``, ``g220a-bmc``, ``palmetto-bmc``, ``qcom-dc-scm-v1-bmc``, ``qcom-firework-bmc``, ``quanta-q71l-bmc``, ``rainier-bmc``, ``romulus-bmc``, ``sonorapass-bmc``, ``supermicrox11-bmc``, ``supermicrox11spi-bmc``, ``tiogapass-bmc``, ``witherspoon-bmc``, ``yosemitev2-bmc``) +Aspeed family boards (``ast2500-evb``, ``ast2600-evb``, ``ast2700-evb``, ``bletchley-bmc``, ``fuji-bmc``, ``fby35-bmc``, ``fp5280g2-bmc``, ``g220a-bmc``, ``palmetto-bmc``, ``qcom-dc-scm-v1-bmc``, ``qcom-firework-bmc``, ``quanta-q71l-bmc``, ``rainier-bmc``, ``romulus-bmc``, ``sonorapass-bmc``, ``supermicrox11-bmc``, ``supermicrox11spi-bmc``, ``tiogapass-bmc``, ``witherspoon-bmc``, ``yosemitev2-bmc``) ================================================================================================================================================================================================================================================================================================================================================================================================================================= The QEMU Aspeed machines model BMCs of various OpenPOWER systems and
Signature · 1 line
2.43.0
Quoted 33 lines · Steven Lee
Clang's sanitizer reports a runtime error when booting with '-net nic -net user', due to a null pointer being passed to
memory_region_find(), which subsequently triggers a crash inflatview_lookup().Root cause:
- Missing NIC configuration in the CA35 initialization.Fix:
- Reduce ca35 ram size from 2GiB to 1GiB to align with ast2700a1-evb, where the ram-container is defined as 1GiB in its class.
- Add nic configuration in ast2700fc's ca35 init function.v2:
- Split the CA35 memory mapping into a separate patch.
- Added a new patch to fix BMC memory mapping in the fby35 machine, which had a similar issue (unmappedsystem_memory).
- Removed Change-Id tag from commit messagesv3:
- Fixed issue with incorrectly inheritingTYPE_ASPEED_MACHINE.
- Rewrote the commit message for "Map BMC memory into system memory".
- Added more details to the commit message for "Fix unimplemented region overlap with VBootROM".Steven Lee (5):
hw/arm/aspeed_ast2700-fc: Fix null pointer dereference in ca35 init hw/arm/aspeed_ast27x0: Fix unimplemented region overlap with vbootrom hw/arm/aspeed_ast27x0-fc: Map ca35 memory into system memory hw/arm/fby35: Map BMC memory into system memory
docs: Remove ast2700fc from Aspeed family boards
Quoted 6 lines
docs/system/arm/aspeed.rst | 2 +- hw/arm/aspeed_ast27x0-fc.c | 10 +++++++++- hw/arm/aspeed_ast27x0.c | 4 ++-- hw/arm/fby35.c | 1 + 4 files changed, 13 insertions(+), 4 deletions(-)
Steven,
please resend. the number of patches is confusing the b4 tool. It's easier for me too.
Thanks,
C.