MemoryManager: Add validate_userspace_string()

A bit crude, should be replaced by a strdup_from_user() helper to avoid touching userspace memory directly.
But it'll do for now.
This commit is contained in:
apio 2023-01-05 22:39:09 +01:00
parent 0ea9974512
commit caa3fe8c45
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 19 additions and 0 deletions

View File

@ -347,6 +347,23 @@ namespace MemoryManager
return false;
}
// FIXME: Replace this with some kind of strdup_from_user() function.
bool validate_userspace_string(u64 address)
{
if (!validate_readable_page(address)) return false;
while (*(char*)address != 0)
{
address++;
if (address % ARCH_PAGE_SIZE)
{
if (!validate_readable_page(address)) return false;
}
}
return true;
}
usize free()
{
return free_mem;

View File

@ -20,6 +20,8 @@ namespace MemoryManager
bool validate_readable_page(u64 address);
bool validate_writable_page(u64 address);
bool validate_userspace_string(u64 address);
Result<void> map_frames_at(u64 virt, u64 phys, usize count, int flags);
Result<u64> alloc_at(u64 virt, usize count, int flags);