diff options
author | dzwdz | 2022-05-21 21:24:15 +0200 |
---|---|---|
committer | dzwdz | 2022-05-21 21:24:15 +0200 |
commit | ef52650c4a0723b242deb72ce2726f6846a6e986 (patch) | |
tree | bdf42a732d694a58cdae1ba8314ae98e096e2399 /src/kernel/syscalls.c | |
parent | e0101ecf0d2f29d8860e865e3f333803af918f2e (diff) |
kernel/i386: only map what's absolutely necessary in the user
Diffstat (limited to 'src/kernel/syscalls.c')
-rw-r--r-- | src/kernel/syscalls.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index af70e4e..4d64d32 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -253,6 +253,7 @@ int _syscall_fs_respond(char __user *buf, int ret) { int _syscall_memflag(void __user *addr, size_t len, int flags) { userptr_t goal = addr + len; struct pagedir *pages = process_current->pages; + void *phys; addr = (userptr_t)((int __force)addr & ~PAGE_MASK); // align to page boundary for (; addr < goal; addr += PAGE_SIZE) { @@ -261,13 +262,16 @@ int _syscall_memflag(void __user *addr, size_t len, int flags) { continue; } + phys = pagedir_virt2phys(pages, addr, false, false); + if (!(flags & MEMFLAG_PRESENT)) { - page_free(pagedir_unmap(pages, addr), 1); + if (phys) + page_free(pagedir_unmap(pages, addr), 1); continue; } - if (!pagedir_virt2phys(pages, addr, false, false)) { - void *phys = page_alloc(1); + if (!phys) { + phys = page_alloc(1); memset(phys, 0, PAGE_SIZE); // TODO somehow test this pagedir_map(pages, addr, phys, true, true); } |