From 304c03f457e294a3d756860325d93b809f50f7a6 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Tue, 16 Nov 2021 22:49:25 +0100 Subject: [PATCH] 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. --- Kernel/FileSystem/InodeFile.cpp | 5 +++++ 1 file changed, 5 insertions(+) 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 InodeFile::ioctl(OpenFileDescription& description, unsigned reques ErrorOr 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 vmobject; if (shared)