From 49b132a92d7b53e51a9ef44d5a052753cde3cc22 Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 8 May 2021 16:00:28 +0300 Subject: [PATCH] Kernel/ACPI: Map two pages when reading the FADT On some cases, the FADT could be on the end of a page, so if we don't have two pages being mapped, we could easily read from a non-mapped virtual address, which will trigger the UB sanitizer. Also, we need to treat the FADT structure as volatile and const, as it may change at any time, but we should not touch (write) it anyhow. --- Kernel/ACPI/Parser.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Kernel/ACPI/Parser.cpp b/Kernel/ACPI/Parser.cpp index 6053971383..213d796178 100644 --- a/Kernel/ACPI/Parser.cpp +++ b/Kernel/ACPI/Parser.cpp @@ -71,11 +71,13 @@ UNMAP_AFTER_INIT void Parser::init_fadt() m_fadt = find_table("FACP"); VERIFY(!m_fadt.is_null()); - auto sdt = map_typed(m_fadt); + // FIXME: We need at least two pages for mapping, since we can be on the "edge" of one page... + auto sdt = map_typed(m_fadt, PAGE_SIZE * 2); dbgln_if(ACPI_DEBUG, "ACPI: FADT @ V{}, {}", &sdt, m_fadt); - dmesgln("ACPI: Fixed ACPI data, Revision {}, length: {} bytes", sdt->h.revision, sdt->h.length); + auto* header = &sdt.ptr()->h; + dmesgln("ACPI: Fixed ACPI data, Revision {}, length: {} bytes", (size_t)header->revision, (size_t)header->length); dmesgln("ACPI: DSDT {}", PhysicalAddress(sdt->dsdt_ptr)); m_x86_specific_flags.cmos_rtc_not_present = (sdt->ia_pc_boot_arch_flags & (u8)FADTFlags::IA_PC_Flags::CMOS_RTC_Not_Present);