cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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