summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-01 21:09:30 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-01 21:16:27 +0100
commitecfde5997bb97b6d39f717379dc13645e12e1166 (patch)
tree527e3b2c1f5eaa54c999cfd4343222b7fb85ffac /Kernel
parentbb7dd63f7491b431e377cc1fde0b6d6f95398cdd (diff)
downloadserenity-ecfde5997bb97b6d39f717379dc13645e12e1166.zip
Kernel: Use SharedInodeVMObject for executables after all
I had the wrong idea about this. Thanks to Sergey for pointing it out! Here's what he says (reproduced for posterity): > Private mappings protect the underlying file from the changes made by > you, not the other way around. To quote POSIX, "If MAP_PRIVATE is > specified, modifications to the mapped data by the calling process > shall be visible only to the calling process and shall not change the > underlying object. It is unspecified whether modifications to the > underlying object done after the MAP_PRIVATE mapping is established > are visible through the MAP_PRIVATE mapping." In practice that means > that the pages that were already paged in don't get updated when the > underlying file changes, and the pages that weren't paged in yet will > load the latest data at that moment. > The only thing MAP_FILE | MAP_PRIVATE is really useful for is mapping > a library and performing relocations; it's definitely useless (and > actively harmful for the system memory usage) if you only read from > the file. This effectively reverts e2697c2dddd531c0ac7cad3fd6ca78e81d0d86da.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Process.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 58f0702715..74f699393f 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -810,7 +810,12 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve
return -ENOENT;
auto& inode = interpreter_description ? *interpreter_description->inode() : *main_program_description->inode();
- auto vmobject = PrivateInodeVMObject::create_with_inode(inode);
+ auto vmobject = SharedInodeVMObject::create_with_inode(inode);
+
+ if (static_cast<const SharedInodeVMObject&>(*vmobject).writable_mappings()) {
+ dbg() << "Refusing to execute a write-mapped program";
+ return -ETXTBSY;
+ }
// Disable profiling temporarily in case it's running on this process.
bool was_profiling = is_profiling();