diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-11-13 18:18:07 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-11-22 14:20:36 +0100 |
| commit | 718d7f46a22220a7c4a53195dadc7291431ff912 (patch) | |
| tree | d5ad7dda89760d04c7cfcad4d541d67877d6acb5 | |
| parent | 700123106b48f23fd083cfbc0f8a6d9d7364c1cb (diff) | |
| download | kernel-718d7f46a22220a7c4a53195dadc7291431ff912.tar.xz kernel-718d7f46a22220a7c4a53195dadc7291431ff912.zip | |
x86_64/memory: check leaf entry before unmapping
| -rw-r--r-- | arch/x86_64/arch/memory/higher_half_mapper.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
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<kapi::memory::frame>{}; |
