summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-11-16 22:49:25 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-17 00:15:30 +0100
commit304c03f457e294a3d756860325d93b809f50f7a6 (patch)
treee34b14a3f3430cc0c8c0564d4659c2770c7818ac
parenta1d5849e675616b12ebc62ed76e1c565f72d5c1a (diff)
downloadserenity-304c03f457e294a3d756860325d93b809f50f7a6.zip
Kernel: Reject writable shared file mappings
We have no way of writing changes to memory-mapped files back to disk, and software relying on this functionality for output would fail miserably. Let's just return ENOTSUP instead to allow callers to fall back to standard file IO instead of silently discarding writes. This makes the LLD port work, which uses memory-mapped files to write its output by default.
-rw-r--r--Kernel/FileSystem/InodeFile.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp
index ad252f1d24..7c5c93c728 100644
--- a/Kernel/FileSystem/InodeFile.cpp
+++ b/Kernel/FileSystem/InodeFile.cpp
@@ -83,6 +83,11 @@ ErrorOr<void> InodeFile::ioctl(OpenFileDescription& description, unsigned reques
ErrorOr<Memory::Region*> InodeFile::mmap(Process& process, OpenFileDescription& description, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
{
+ // FIXME: Support writing changes made to shared file mappings back to disk.
+ // Some ports behave incorrectly if we silently discard writes to memory-mapped files, so let's not lie about what we can do.
+ if (shared && (prot & PROT_WRITE))
+ return ENOTSUP;
+
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
RefPtr<Memory::InodeVMObject> vmobject;
if (shared)