From 055a896406af227e03708fa20a728259cace704a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 20 Mar 2024 10:17:08 +0100 Subject: kernel: secret: fix: see below. - fix is_valid_ptr and add definition to header file. - also remove NX flags. --- Private/Source/KernelHeap.cxx | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'Private/Source') diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx index 3acb3d79..e7dd09ed 100644 --- a/Private/Source/KernelHeap.cxx +++ b/Private/Source/KernelHeap.cxx @@ -95,7 +95,7 @@ Int32 ke_delete_ke_heap(VoidPtr ptr) { if (kPageManager.Free(kLastWrapper)) { virtualAddress->hSizeAddress = 0UL; virtualAddress->hPresent = false; - kLastWrapper->NoExecute(false); + return true; } @@ -114,8 +114,6 @@ Int32 ke_delete_ke_heap(VoidPtr ptr) { virtualAddress->hSizeAddress = 0UL; virtualAddress->hPresent = false; - wrapper->NoExecute(false); - return true; } @@ -127,28 +125,19 @@ Int32 ke_delete_ke_heap(VoidPtr ptr) { return -1; } -/// @brief find pointer in kernel heap +/// @brief Check if pointer is a valid kernel pointer. /// @param ptr the pointer /// @return if it exists. -Boolean kernel_valid_ptr(VoidPtr ptr) { +Boolean ke_is_valid_ptr(VoidPtr ptr) { if (ptr) { - const UIntPtr virtualAddress = reinterpret_cast(ptr); + Detail::HeapInformationBlockPtr virtualAddress = + reinterpret_cast(ptr) - + sizeof(Detail::HeapInformationBlock); - if (kLastWrapper && - virtualAddress == (kLastWrapper->VirtualAddress() + - sizeof(Detail::HeapInformationBlock))) { + if (virtualAddress->hPresent && + virtualAddress->hMagic == kHeapMagic) { return true; } - - Ref wrapper; - - for (SizeT indexWrapper = 0; indexWrapper < kHeapCount; ++indexWrapper) { - if ((kLastWrapper->VirtualAddress() + - sizeof(Detail::HeapInformationBlock)) == virtualAddress) { - wrapper = kWrapperList[indexWrapper]; - return true; - } - } } return false; -- cgit v1.2.3