From 36a2fd5eb75e87bfe6f6f6c775ebac3d80902110 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 14 Nov 2026 15:59:11 +0100 Subject: x86_64/memory: panic on huge page mappings The x86_64 platform's higher half memory mapper currently has not support for huge page mappings. However, the previous implementation did not explicitly exclude huge page mappings, instead potentially corrupting the contents of huge pages by treating them as regular pages. The kernel now panics whenever an attempt is made to map a page inside a region covered by a huge page, or when trying to unmap a huge page or a range covered by a huge page. --- arch/x86_64/arch/memory/higher_half_mapper.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86_64/arch/memory/higher_half_mapper.cpp b/arch/x86_64/arch/memory/higher_half_mapper.cpp index 814cc991..cd0f943a 100644 --- a/arch/x86_64/arch/memory/higher_half_mapper.cpp +++ b/arch/x86_64/arch/memory/higher_half_mapper.cpp @@ -70,6 +70,11 @@ namespace arch::memory return std::nullopt; } + if (entry.huge()) + { + kapi::system::panic("[ARCH:MEM] Tried to unmap a huge page, which is not supported!"); + } + auto next_table = to_higher_half_pointer(entry.frame()->start_address()); auto next_index = pml_index(level - 1, page); table_path[4 - (level - 1)] = std::pair{next_table, next_index}; @@ -121,6 +126,11 @@ namespace arch::memory auto index = pml_index(level, page); auto & entry = (*table)[index]; + if (entry.huge()) + { + kapi::system::panic("[ARCH:MEM] Tried map an entry in a huge page, which is not supported!"); + } + if (!entry.present()) { auto table_frame = kapi::memory::allocate_frame(); -- cgit v1.2.3