From 1b04c4369012b2d8b5c7d29526a0e00dd71c7742 Mon Sep 17 00:00:00 2001 From: Marco Cutecchia Date: Sat, 1 Apr 2023 19:11:21 +0200 Subject: Kernel: Initialize DiskCache's buffer before the dirty&clean lists This commit fixes a kernel panic that happened when unmounting a disk due to an invalid memory access. This was because `DiskCache` initializes two linked lists that use an argument `KBuffer` as the storage for their elements. Since the member `KBuffer` was declared after the two lists, when `DiskCache`'s destructor was called, then `KBuffer`'s destructor was called before the ones of the two lists, causing a page fault in the kernel. --- Kernel/FileSystem/BlockBasedFileSystem.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Kernel/FileSystem/BlockBasedFileSystem.cpp') diff --git a/Kernel/FileSystem/BlockBasedFileSystem.cpp b/Kernel/FileSystem/BlockBasedFileSystem.cpp index 4e78a5d3ed..1dabaecf00 100644 --- a/Kernel/FileSystem/BlockBasedFileSystem.cpp +++ b/Kernel/FileSystem/BlockBasedFileSystem.cpp @@ -101,11 +101,14 @@ public: private: mutable NonnullRefPtr m_fs; + NonnullOwnPtr m_cached_block_data; + + // NOTE: m_entries must be declared before m_dirty_list and m_clean_list because their entries are allocated from it. + // We need to ensure that the destructors of m_dirty_list and m_clean_list are called before m_entries is destroyed. + NonnullOwnPtr m_entries; mutable IntrusiveList<&CacheEntry::list_node> m_dirty_list; mutable IntrusiveList<&CacheEntry::list_node> m_clean_list; mutable HashMap m_hash; - NonnullOwnPtr m_cached_block_data; - NonnullOwnPtr m_entries; }; BlockBasedFileSystem::BlockBasedFileSystem(OpenFileDescription& file_description) -- cgit v1.2.3