From 6e641fadfa61d4b890db52fb60cc3709352336b6 Mon Sep 17 00:00:00 2001 From: Mart G Date: Thu, 6 May 2021 17:53:59 +0200 Subject: [PATCH] Kernel: Resize Ext2FSInode when writing directory contents (#6897) Ext2 directory contents are stored in a linked list of ext2_dir_entry structs. There is no sentinel value to determine where the list ends. Instead the list fills the entirety of the allocated space for the inode. Previously the inode was not correctly resized when it became smaller. This resulted in stale data being interpreted as part of the linked list of directory entries. --- Kernel/FileSystem/Ext2FileSystem.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index ff34c1c201..ab52115b82 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -1112,6 +1112,9 @@ KResult Ext2FSInode::write_directory(const Vector& entries stream.fill_to_end(0); + if (auto result = resize(stream.size()); result.is_error()) + return result; + auto buffer = UserOrKernelBuffer::for_kernel_buffer(stream.data()); auto result = write_bytes(0, stream.size(), buffer, nullptr); if (result.is_error())