Blame SOURCES/kvm-acpi-fix-QEMU-crash-when-started-with-SLIC-table.patch

60061b
From 2596689db79a5710fdfdb1f0d5bfe02557bb30e5 Mon Sep 17 00:00:00 2001
60061b
From: Igor Mammedov <imammedo@redhat.com>
60061b
Date: Mon, 27 Dec 2021 14:31:17 -0500
60061b
Subject: [PATCH 03/12] acpi: fix QEMU crash when started with SLIC table
60061b
MIME-Version: 1.0
60061b
Content-Type: text/plain; charset=UTF-8
60061b
Content-Transfer-Encoding: 8bit
60061b
60061b
RH-Author: Igor Mammedov <imammedo@redhat.com>
60061b
RH-MergeRequest: 129: acpi: fix QEMU crash when started with SLIC table
60061b
RH-Commit: [1/10] da8a19a574ce0c8862c84173434fa186aaddc855
60061b
RH-Bugzilla: 2059311
60061b
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
60061b
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
60061b
RH-Acked-by: MST <None>
60061b
60061b
if QEMU is started with used provided SLIC table blob,
60061b
60061b
  -acpitable sig=SLIC,oem_id='CRASH ',oem_table_id="ME",oem_rev=00002210,asl_compiler_id="",asl_compiler_rev=00000000,data=/dev/null
60061b
it will assert with:
60061b
60061b
  hw/acpi/aml-build.c:61:build_append_padded_str: assertion failed: (len <= maxlen)
60061b
60061b
and following backtrace:
60061b
60061b
  ...
60061b
  build_append_padded_str (array=0x555556afe320, str=0x555556afdb2e "CRASH ME", maxlen=0x6, pad=0x20) at hw/acpi/aml-build.c:61
60061b
  acpi_table_begin (desc=0x7fffffffd1b0, array=0x555556afe320) at hw/acpi/aml-build.c:1727
60061b
  build_fadt (tbl=0x555556afe320, linker=0x555557ca3830, f=0x7fffffffd318, oem_id=0x555556afdb2e "CRASH ME", oem_table_id=0x555556afdb34 "ME") at hw/acpi/aml-build.c:2064
60061b
  ...
60061b
60061b
which happens due to acpi_table_begin() expecting NULL terminated
60061b
oem_id and oem_table_id strings, which is normally the case, but
60061b
in case of user provided SLIC table, oem_id points to table's blob
60061b
directly and as result oem_id became longer than expected.
60061b
60061b
Fix issue by handling oem_id consistently and make acpi_get_slic_oem()
60061b
return NULL terminated strings.
60061b
60061b
PS:
60061b
After [1] refactoring, oem_id semantics became inconsistent, where
60061b
NULL terminated string was coming from machine and old way pointer
60061b
into byte array coming from -acpitable option. That used to work
60061b
since build_header() wasn't expecting NULL terminated string and
60061b
blindly copied the 1st 6 bytes only.
60061b
60061b
However commit [2] broke that by replacing build_header() with
60061b
acpi_table_begin(), which was expecting NULL terminated string
60061b
and was checking oem_id size.
60061b
60061b
1) 602b45820 ("acpi: Permit OEM ID and OEM table ID fields to be changed")
60061b
2)
60061b
Fixes: 4b56e1e4eb08 ("acpi: build_fadt: use acpi_table_begin()/acpi_table_end() instead of build_header()")
60061b
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/786
60061b
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
60061b
Message-Id: <20211227193120.1084176-2-imammedo@redhat.com>
60061b
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
60061b
Tested-by: Denis Lisov <dennis.lissov@gmail.com>
60061b
Tested-by: Alexander Tsoy <alexander@tsoy.me>
60061b
Cc: qemu-stable@nongnu.org
60061b
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
60061b
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
60061b
(cherry picked from commit 8cdb99af45365727ac17f45239a9b8c1d5155c6d)
60061b
---
60061b
 hw/acpi/core.c       | 4 ++--
60061b
 hw/i386/acpi-build.c | 2 ++
60061b
 2 files changed, 4 insertions(+), 2 deletions(-)
60061b
60061b
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
60061b
index 1e004d0078..3e811bf03c 100644
60061b
--- a/hw/acpi/core.c
60061b
+++ b/hw/acpi/core.c
60061b
@@ -345,8 +345,8 @@ int acpi_get_slic_oem(AcpiSlicOem *oem)
60061b
         struct acpi_table_header *hdr = (void *)(u - sizeof(hdr->_length));
60061b
 
60061b
         if (memcmp(hdr->sig, "SLIC", 4) == 0) {
60061b
-            oem->id = hdr->oem_id;
60061b
-            oem->table_id = hdr->oem_table_id;
60061b
+            oem->id = g_strndup(hdr->oem_id, 6);
60061b
+            oem->table_id = g_strndup(hdr->oem_table_id, 8);
60061b
             return 0;
60061b
         }
60061b
     }
60061b
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
60061b
index a4478e77b7..acc4869db0 100644
60061b
--- a/hw/i386/acpi-build.c
60061b
+++ b/hw/i386/acpi-build.c
60061b
@@ -2726,6 +2726,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
60061b
 
60061b
     /* Cleanup memory that's no longer used. */
60061b
     g_array_free(table_offsets, true);
60061b
+    g_free(slic_oem.id);
60061b
+    g_free(slic_oem.table_id);
60061b
 }
60061b
 
60061b
 static void acpi_ram_update(MemoryRegion *mr, GArray *data)
60061b
-- 
60061b
2.27.0
60061b