Parcourir la source

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.
Andreas Kling il y a 5 ans
Parent
commit
ecfde5997b
1 fichiers modifiés avec 6 ajouts et 1 suppressions
  1. 6 1
      Kernel/Process.cpp

+ 6 - 1
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();