Nucleus
Barry Improved page fault handling and mmap system call 665af0a (3 years, 2 months ago)
/*
* This file handles safely getting data from userspace for the kernel. This is
* for security reasons to prevent the user from tricking a syscall into
* manipulating/leaking kernel data structures. User memory is defined as any
* address range that completely sits in a Virtual Memory Region.
*/
#include <nucleus/memory.h>
#include <nucleus/task.h>
#include "namespace.h"
VMRegion *find_region(uintptr_t addr);
/* Check if user has access to a region of memory */
int
verify_access(const void *addr, size_t len, int prot)
{
if (!len || !(current && current->inSyscall))
return 1;
VMRegion *region;
int minprot = ~0;
uintptr_t end = (uintptr_t) addr;
do {
region = find_region(end);
if (!region)
return 0;
minprot &= region->prot;
end = region->end;
} while (end < (uintptr_t) addr + len);
return (minprot & prot);
}