Commit 7d8fc59308 for qemu.org
commit 7d8fc59308ce20661515555855af4e01ac9bab77
Author: Ren Yanyi <kevinren114514@163.com>
Date: Fri Nov 13 10:32:51 2026 +0800
hw/arm/virt-acpi-build: test vms->acpi_dev before building HEST
virt_acpi_build() gates HEST table construction on:
acpi_ged_state = ACPI_GED(vms->acpi_dev);
ags = &acpi_ged_state->ghes_state;
if (ags) {
ags is the address of the ghes_state member of AcpiGedState and can
never be NULL, so the check always passes. Whether the GED device
exists is a separate condition (has_ged also depends on firmware
being loaded and on ACPI being enabled), so a machine started with
ras=on but without a GED device reaches this code with a NULL
acpi_ged_state; ags then holds a bogus non-NULL pointer and
acpi_build_hest() dereferences it.
Test vms->acpi_dev in the enclosing condition instead, so the HEST
table is only built when the GED device exists and the ACPI_GED()
cast is always valid.
Fixes: 2e9c5c5bc85a ("acpi/ghes: prepare to change the way HEST offsets are calculated")
Signed-off-by: Ren Yanyi <kevinren114514@163.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
index d368913e76..5670d1eca7 100644
--- a/hw/arm/virt-acpi-build.c
+++ b/hw/arm/virt-acpi-build.c
@@ -1406,7 +1406,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
acpi_add_table(table_offsets, tables_blob);
build_dbg2(tables_blob, tables->linker, vms);
- if (vms->ras) {
+ if (vms->ras && vms->acpi_dev) {
AcpiGedState *acpi_ged_state;
static const AcpiNotificationSourceId *notify;
unsigned int notify_sz;
@@ -1414,21 +1414,20 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
acpi_ged_state = ACPI_GED(vms->acpi_dev);
ags = &acpi_ged_state->ghes_state;
- if (ags) {
- acpi_add_table(table_offsets, tables_blob);
- if (!ags->use_hest_addr) {
- notify = hest_ghes_notify_10_0;
- notify_sz = ARRAY_SIZE(hest_ghes_notify_10_0);
- } else {
- notify = hest_ghes_notify;
- notify_sz = ARRAY_SIZE(hest_ghes_notify);
- }
+ acpi_add_table(table_offsets, tables_blob);
- acpi_build_hest(ags, tables_blob, tables->hardware_errors,
- tables->linker, notify, notify_sz,
- vms->oem_id, vms->oem_table_id);
+ if (!ags->use_hest_addr) {
+ notify = hest_ghes_notify_10_0;
+ notify_sz = ARRAY_SIZE(hest_ghes_notify_10_0);
+ } else {
+ notify = hest_ghes_notify;
+ notify_sz = ARRAY_SIZE(hest_ghes_notify);
}
+
+ acpi_build_hest(ags, tables_blob, tables->hardware_errors,
+ tables->linker, notify, notify_sz,
+ vms->oem_id, vms->oem_table_id);
}
if (ms->numa_state->num_nodes > 0) {