From dd0b8c4140db3220d1b2ea3ee2a980cdd3933fd2 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 18 Sep 2023 21:37:37 +0300 Subject: [PATCH] Kernel: Add pointer validation API to page table --- kernel/arch/x86_64/PageTable.cpp | 7 +++++++ kernel/include/kernel/Memory/PageTable.h | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/arch/x86_64/PageTable.cpp b/kernel/arch/x86_64/PageTable.cpp index fd6c9d3d2e..fca738bc68 100644 --- a/kernel/arch/x86_64/PageTable.cpp +++ b/kernel/arch/x86_64/PageTable.cpp @@ -110,6 +110,13 @@ namespace Kernel return *s_current; } + bool PageTable::is_valid_pointer(uintptr_t pointer) + { + if (!is_canonical(pointer)) + return false; + return true; + } + static uint64_t* allocate_zeroed_page_aligned_page() { void* page = kmalloc(PAGE_SIZE, PAGE_SIZE, true); diff --git a/kernel/include/kernel/Memory/PageTable.h b/kernel/include/kernel/Memory/PageTable.h index 55456df734..a0f434ad00 100644 --- a/kernel/include/kernel/Memory/PageTable.h +++ b/kernel/include/kernel/Memory/PageTable.h @@ -29,13 +29,15 @@ namespace Kernel static PageTable& kernel(); static PageTable& current(); + static bool is_valid_pointer(uintptr_t); + static BAN::ErrorOr create_userspace(); ~PageTable(); void unmap_page(vaddr_t); void unmap_range(vaddr_t, size_t bytes); - void map_range_at(paddr_t, vaddr_t, size_t, flags_t); + void map_range_at(paddr_t, vaddr_t, size_t bytes, flags_t); void map_page_at(paddr_t, vaddr_t, flags_t); paddr_t physical_address_of(vaddr_t) const;