From ecfde5997bb97b6d39f717379dc13645e12e1166 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 1 Mar 2020 21:09:30 +0100 Subject: [PATCH] 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. --- Kernel/Process.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 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(*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();