mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 01:37:39 +03:00
Kernel: Don't allow mmap()/mprotect() to set up PROT_WRITE|PROT_EXEC
..but also allow mprotect() to set PROT_EXEC on a region, something we were just ignoring before.
This commit is contained in:
parent
33efeaf71a
commit
419e0ced27
Notes:
sideshowbarker
2024-07-19 10:41:20 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/419e0ced27c
@ -235,6 +235,9 @@ void* Process::sys$mmap(const Syscall::SC_mmap_params* params)
|
||||
if ((flags & MAP_SHARED) && (flags & MAP_PRIVATE))
|
||||
return (void*)-EINVAL;
|
||||
|
||||
if ((prot & PROT_WRITE) && (prot & PROT_EXEC))
|
||||
return (void*)-EINVAL;
|
||||
|
||||
// EINVAL: MAP_STACK cannot be used with shared or file-backed mappings
|
||||
if ((flags & MAP_STACK) && ((flags & MAP_SHARED) || !(flags & MAP_PRIVATE) || !(flags & MAP_ANONYMOUS)))
|
||||
return (void*)-EINVAL;
|
||||
@ -338,8 +341,11 @@ int Process::sys$mprotect(void* addr, size_t size, int prot)
|
||||
return -EINVAL;
|
||||
if (!region->is_mmap())
|
||||
return -EPERM;
|
||||
if ((prot & PROT_WRITE) && (prot & PROT_EXEC))
|
||||
return -EINVAL;
|
||||
region->set_readable(prot & PROT_READ);
|
||||
region->set_writable(prot & PROT_WRITE);
|
||||
region->set_executable(prot & PROT_EXEC);
|
||||
region->remap();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user