platform/x86: Check validity of EBDA pointer in mpparse.c
Subsystems (4)
PATCH RESEND 1/3 platform/x86: Check validity of EBDA pointer in mpparse.c
In reply to a message not in the archiveThe pointer to EBDA area is retrieved from a word at 0x40e in BDA. In case that the memory there is not initialized and contains garbage, it might happen that the kernel touches memory above 640K.
This may cause unwanted reads from VGA memory which may not be decoded, or even present when running under virtualization.
This patch adds sanity check for the EBDA pointer retrieved from the memory so that scanning EBDA does not leave the low memory.
--- arch/x86/include/asm/bios_ebda.h | 3 +++ arch/x86/kernel/ebda.c | 3 --- arch/x86/kernel/mpparse.c | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-)
arch/x86/include/asm/bios_ebda.h +3 -0
@@ -4,6 +4,9 @@#include <asm/io.h> +#define BIOS_START_MIN 0x20000U/* 128K, less than this is insane */ +#define BIOS_START_MAX 0x9f000U/* 640K, absolute maximum */ +/* * Returns physical address of EBDA. Returns 0 if there is no EBDA. */
arch/x86/kernel/ebda.c +0 -3
@@ -50,9 +50,6 @@#define BIOS_RAM_SIZE_KB_PTR 0x413 -#define BIOS_START_MIN 0x20000U/* 128K, less than this is insane */ -#define BIOS_START_MAX 0x9f000U/* 640K, absolute maximum */ -void __init reserve_bios_regions (void ) {unsigned int bios_start, ebda_start;
arch/x86/kernel/mpparse.c +11 -1
@@ -633,7 +633,17 @@ void __init default_find_smp_config(void)*/ address =get_bios_ebda (); -if (address) + +/* Check that the EBDA address is sane and the get_bios_ebda() did not +* return just garbage from memory. +* The upper bound is considered valid if it points below 1K before +* end of the lower memory (i.e. 639K). The EBDA can be smaller +* than 1K in which case the pointer will point above 639K but that +* case is handled in step 2) above, and we don't need to adjust scan +* size to not bump into the memory above 640K. +*/ +if (address >=BIOS_START_MIN && + address <639 *0x400 )smp_scan_config (address,0x400 ); }
Signature · 1 line
2.30.2
PATCH RESEND 2/3 acpica: Check that the EBDA pointer is in valid range
In reply to a message not in the archiveIf the memory at 0x40e is uninitialized, the retrieved physical_memory address of EBDA may be beyond the low memory (i.e. above 640K).
If so, the kernel may unintentionally access the VGA memory, that might not be decoded or even present in case of virtualization.
--- drivers/acpi/acpica/tbxfroot.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/acpi/acpica/tbxfroot.c +5 -2
@@ -138,8 +138,11 @@ acpi_find_root_pointer(acpi_physical_address *table_address)acpi_os_unmap_memory (table_ptr,ACPI_EBDA_PTR_LENGTH );/* EBDA present? */ - -if (physical_address >0x400 ) { +/* Check that the EBDA pointer from 0x40e is sane and does not point +* above valid low memory +*/ +if (physical_address >0x400 && + physical_address <0xA0000 ) {/* * 1b) Search EBDA paragraphs (EBDA is required to be a * minimum of 1K length)
Signature · 1 line
2.30.2
PATCH RESEND 3/3 acpica: Do not touch VGA memory when EBDA < 1KiB
In reply to a message not in the archiveThe ACPICA code assumes that EBDA region must be at least 1KiB in size. Because this is not guaranteed, it might happen that while scanning the memory for RSDP pointer, the kernel touches memory above 640KiB.
This is unwanted as the VGA memory range may not be decoded or even present when running under virtualization.
--- drivers/acpi/acpica/tbxfroot.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/acpi/acpica/tbxfroot.c +14 -6
@@ -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);
@@ -143,25 +144,32 @@ acpi_find_root_pointer(acpi_physical_address *table_address)*/ if (physical_address >0x400 && physical_address <0xA0000 ) { +/* Calculate the scan window size +* The EBDA is not guaranteed to be larger than a KiB +* 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 (EBDA is required to be a -* minimum of 1K length) +* 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 ); + ebda_window_size); +acpi_os_unmap_memory (table_ptr, ebda_window_size);if (mem_rover) {
Signature · 1 line
2.30.2