diff options
author | Andreas Kling <kling@serenityos.org> | 2020-01-18 23:31:29 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-01-18 23:40:12 +0100 |
commit | 862b3ccb4e54113fc4139a3b4d2af3a8f40fe122 (patch) | |
tree | 4f2cdde028bf55dbacba3bd824ab77998cf95edb /Kernel/VM/InodeVMObject.cpp | |
parent | 7ea264a660a184fadd75f74379320c0e4d1bda21 (diff) | |
download | serenity-862b3ccb4e54113fc4139a3b4d2af3a8f40fe122.zip |
Kernel: Enforce W^X between sys$mmap() and sys$execve()
It's now an error to sys$mmap() a file as writable if it's currently
mapped executable by anyone else.
It's also an error to sys$execve() a file that's currently mapped
writable by anyone else.
This fixes a race condition vulnerability where one program could make
modifications to an executable while another process was in the kernel,
in the middle of exec'ing the same executable.
Test: Kernel/elf-execve-mmap-race.cpp
Diffstat (limited to 'Kernel/VM/InodeVMObject.cpp')
-rw-r--r-- | Kernel/VM/InodeVMObject.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Kernel/VM/InodeVMObject.cpp b/Kernel/VM/InodeVMObject.cpp index b994f84e0d..36a97b87bb 100644 --- a/Kernel/VM/InodeVMObject.cpp +++ b/Kernel/VM/InodeVMObject.cpp @@ -175,3 +175,23 @@ int InodeVMObject::release_all_clean_pages_impl() }); return count; } + +u32 InodeVMObject::writable_mappings() const +{ + u32 count = 0; + const_cast<InodeVMObject&>(*this).for_each_region([&](auto& region) { + if (region.is_writable()) + ++count; + }); + return count; +} + +u32 InodeVMObject::executable_mappings() const +{ + u32 count = 0; + const_cast<InodeVMObject&>(*this).for_each_region([&](auto& region) { + if (region.is_executable()) + ++count; + }); + return count; +} |