From dbab4d34d737a0f35edd8f811e9c7254c0faa95d Mon Sep 17 00:00:00 2001 From: Liav A Date: Wed, 16 Aug 2023 22:45:00 +0300 Subject: [PATCH] Kernel/FileSystem: Remove disk cache only after ext2 superblock flush We first must flush the superblock through the BlockBasedFileSystem methods properly and only then clear the DiskCache pointer, to prevent a possible kernel panic due to nullptr dereference. --- Kernel/FileSystem/Ext2FS/FileSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel/FileSystem/Ext2FS/FileSystem.cpp b/Kernel/FileSystem/Ext2FS/FileSystem.cpp index ce5711ded93..67ad8e80838 100644 --- a/Kernel/FileSystem/Ext2FS/FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FS/FileSystem.cpp @@ -589,7 +589,6 @@ ErrorOr Ext2FS::prepare_to_clear_last_mount(Inode& mount_guest_inode) if (any_inode_busy) return EBUSY; - BlockBasedFileSystem::remove_disk_cache_before_last_unmount(); m_inode_cache.clear(); m_root_inode = nullptr; @@ -597,6 +596,7 @@ ErrorOr Ext2FS::prepare_to_clear_last_mount(Inode& mount_guest_inode) dmesgln("Ext2FS: Clean unmount, setting superblock to valid state"); m_super_block.s_state = EXT2_VALID_FS; TRY(flush_super_block()); + BlockBasedFileSystem::remove_disk_cache_before_last_unmount(); return {}; }