ACPICA: Do not touch VGA memory when EBDA < 1ki_b
authorVit Kabele <vit@kabele.me>
Thu, 27 Oct 2022 17:50:59 +0000 (19:50 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 28 Oct 2022 15:28:22 +0000 (17:28 +0200)
ACPICA commit a36eda9631e84f271319c41288889dd5b1329369

The ACPICA code assumes that EBDA region must be at least 1ki_b in size.
Because this is not guaranteed, it might happen that while scanning the
memory for RSDP pointer, the kernel touches memory above 640ki_b.

This is unwanted as the VGA memory range may not be decoded or
even present when running under virtualization.

Link: https://github.com/acpica/acpica/commit/a36eda96
Signed-off-by: Vit Kabele <vit@kabele.me>
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/acpica/tbxfroot.c

index ede2745..f1c2ab0 100644 (file)
@@ -114,6 +114,7 @@ acpi_find_root_pointer(acpi_physical_address *table_address)
        u8 *table_ptr;
        u8 *mem_rover;
        u32 physical_address;
+       u32 ebda_window_size;
 
        ACPI_FUNCTION_TRACE(acpi_find_root_pointer);
 
@@ -145,24 +146,31 @@ acpi_find_root_pointer(acpi_physical_address *table_address)
         */
        if (physical_address > 0x400 && physical_address < 0xA0000) {
                /*
-                * 1b) Search EBDA paragraphs (EBDA is required to be a
-                *     minimum of 1K length)
+                * Calculate the scan window size
+                * The EBDA is not guaranteed to be larger than a ki_b and in case
+                * that it is smaller, the scanning function would leave the low
+                * memory and continue to the VGA range.
+                */
+               ebda_window_size = ACPI_MIN(ACPI_EBDA_WINDOW_SIZE,
+                                           0xA0000 - physical_address);
+
+               /*
+                * 1b) Search EBDA paragraphs
                 */
                table_ptr = acpi_os_map_memory((acpi_physical_address)
                                               physical_address,
-                                              ACPI_EBDA_WINDOW_SIZE);
+                                              ebda_window_size);
                if (!table_ptr) {
                        ACPI_ERROR((AE_INFO,
                                    "Could not map memory at 0x%8.8X for length %u",
-                                   physical_address, ACPI_EBDA_WINDOW_SIZE));
+                                   physical_address, ebda_window_size));
 
                        return_ACPI_STATUS(AE_NO_MEMORY);
                }
 
                mem_rover =
-                   acpi_tb_scan_memory_for_rsdp(table_ptr,
-                                                ACPI_EBDA_WINDOW_SIZE);
-               acpi_os_unmap_memory(table_ptr, ACPI_EBDA_WINDOW_SIZE);
+                   acpi_tb_scan_memory_for_rsdp(table_ptr, ebda_window_size);
+               acpi_os_unmap_memory(table_ptr, ebda_window_size);
 
                if (mem_rover) {