From e58a600d52be5544cab0e770b372488e35a38811 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 10 Mar 2021 16:24:01 +0100 Subject: [PATCH] Kernel: Remove VLA usage in Ext2FS block traversal code This was using up to 12KB of kernel stack in the triply indirect case and looks generally spooky. Let's just allocate a ByteBuffer for now and take the performance hit (of heap allocation). Longer term we can reorganize the code to reduce the majority of the heap churn. --- Kernel/FileSystem/Ext2FileSystem.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index d5f751f72b..4fadf8f70f 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -506,9 +506,11 @@ Vector Ext2FSInode::compute_block_list_impl_internal(const e auto count = min(blocks_remaining, entries_per_block); if (!count) return; - u32 array[count]; + size_t read_size = count * sizeof(u32); + auto array_storage = ByteBuffer::create_uninitialized(read_size); + auto* array = (u32*)array_storage.data(); auto buffer = UserOrKernelBuffer::for_kernel_buffer((u8*)array); - auto result = fs().read_block(array_block_index, &buffer, sizeof(array), 0); + auto result = fs().read_block(array_block_index, &buffer, read_size, 0); if (result.is_error()) { // FIXME: Stop here and propagate this error. dbgln("Ext2FS: compute_block_list_impl_internal had error: {}", result.error());