From 718d7f46a22220a7c4a53195dadc7291431ff912 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 13 Nov 2026 18:18:07 +0100 Subject: x86_64/memory: check leaf entry before unmapping --- arch/x86_64/arch/memory/higher_half_mapper.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86_64/arch/memory/higher_half_mapper.cpp b/arch/x86_64/arch/memory/higher_half_mapper.cpp index ee11d50a..814cc991 100644 --- a/arch/x86_64/arch/memory/higher_half_mapper.cpp +++ b/arch/x86_64/arch/memory/higher_half_mapper.cpp @@ -75,6 +75,14 @@ namespace arch::memory table_path[4 - (level - 1)] = std::pair{next_table, next_index}; } + auto [leaf_table, leaf_index] = table_path.back(); + if (!(*leaf_table)[leaf_index].present()) + { + return std::nullopt; + } + + // If execution reaches this point, all page table entries leading to, and including, the leaf entry are present. It + // is therefore safe to access their `frame` value without additional checks. auto release_path = std::views::reverse(table_path); auto previous_was_empty = true; auto unmapped_frame = std::optional{}; -- cgit v1.2.3