From de980de0e48a78a5c7c53433012b1e15fe5b3985 Mon Sep 17 00:00:00 2001 From: Mike Akers Date: Fri, 12 Aug 2022 09:48:59 -0400 Subject: [PATCH] Kernel: Lock the inode before writing in SharedInodeVMObject::sync We ensure that when we call SharedInodeVMObject::sync we lock the inode lock before calling Inode virtual write_bytes method directly to avoid assertion on the unlocked inode lock, as it was regressed recently. This is not a complete fix as the need to lock from each path before calling the write_bytes method should be avoided because it can lead to hard-to-find bugs, and this commit only fixes the problem temporarily. --- Kernel/FileSystem/Inode.h | 2 ++ Kernel/Memory/SharedInodeVMObject.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index 3974d963509..de22fa74ee0 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -19,6 +19,7 @@ #include #include #include +#include namespace Kernel { @@ -32,6 +33,7 @@ class Inode : public ListedRefCounted friend class VirtualFileSystem; friend class FileSystem; friend class InodeFile; + friend class Kernel::Memory::SharedInodeVMObject; // FIXME: Remove when write_bytes becomes non-virtual public: virtual ~Inode(); diff --git a/Kernel/Memory/SharedInodeVMObject.cpp b/Kernel/Memory/SharedInodeVMObject.cpp index 3c20012718b..2f1e3e27cb8 100644 --- a/Kernel/Memory/SharedInodeVMObject.cpp +++ b/Kernel/Memory/SharedInodeVMObject.cpp @@ -53,6 +53,7 @@ ErrorOr SharedInodeVMObject::sync(off_t offset_in_pages, size_t pages) u8 page_buffer[PAGE_SIZE]; MM.copy_physical_page(*physical_page, page_buffer); + MutexLocker locker(m_inode->m_inode_lock); TRY(m_inode->write_bytes(page_index * PAGE_SIZE, PAGE_SIZE, UserOrKernelBuffer::for_kernel_buffer(page_buffer), nullptr)); }