UserMemory: do not map refs into kernel memory

This is bad design. But it fails if mapped, since something overwrites KernelHeap.
This commit is contained in:
apio 2022-10-20 18:50:07 +02:00
parent 712f4f5e51
commit 27448611b3
2 changed files with 19 additions and 7 deletions

View File

@ -1,21 +1,35 @@
#pragma once #pragma once
#ifndef MODULE
#define MODULE "mem"
#endif
#include "log/Log.h"
#include "memory/MemoryManager.h" #include "memory/MemoryManager.h"
#include "memory/VMM.h" #include "memory/VMM.h"
#include "misc/utils.h" #include "misc/utils.h"
char* strdup_from_user(const char* user_string); char* strdup_from_user(const char* user_string);
// FIXME: Map the physical addresses into kernel address space. Right now, something overwrites KernelHeap and crashes
// it, so that's not really possible. But it should be done in the future.
template <typename T, unsigned long S = sizeof(T), typename V> T* user_address_to_typed_pointer(V address) template <typename T, unsigned long S = sizeof(T), typename V> T* user_address_to_typed_pointer(V address)
{ {
uint64_t phys = VMM::get_physical((uint64_t)address); uint64_t phys = VMM::get_physical((uint64_t)address);
if (phys == (uint64_t)-1) return nullptr; if (phys == (uint64_t)-1)
return (T*)MemoryManager::get_unaligned_mappings((void*)phys, Utilities::get_blocks_from_size(PAGE_SIZE, S), {
MAP_READ_WRITE); kinfoln("warning: user pointer is not mapped in its address space");
return nullptr;
}
// return (T*)MemoryManager::get_unaligned_mappings((void*)phys, Utilities::get_blocks_from_size(PAGE_SIZE, S),
// MAP_READ_WRITE);
return (T*)phys;
} }
template <typename T, unsigned long S = sizeof(T)> void free_user_typed_pointer(T* ptr) template <typename T, unsigned long S = sizeof(T)> void free_user_typed_pointer(T*)
{ {
MemoryManager::release_unaligned_mappings(ptr, Utilities::get_blocks_from_size(PAGE_SIZE, S)); // MemoryManager::release_unaligned_mappings(ptr, Utilities::get_blocks_from_size(PAGE_SIZE, S));
} }
template <typename T> T* obtain_user_ref(T* user_ptr) template <typename T> T* obtain_user_ref(T* user_ptr)

View File

@ -482,8 +482,6 @@ void sys_waitpid(Context* context, long pid, int* wstatus,
} }
if (wstatus) if (wstatus)
{ {
VMM::switch_to_user_address_space(sched_current_task->address_space);
VMM::enter_syscall_context();
int* kwstatus = obtain_user_ref(wstatus); int* kwstatus = obtain_user_ref(wstatus);
if (kwstatus) if (kwstatus)
{ {