From 4d389ab4869d37a8d27bb161c0162c2163f3c816 Mon Sep 17 00:00:00 2001 From: Coleman Kane Date: Sat, 26 Oct 2024 17:08:08 -0400 Subject: [PATCH] If the freed block is smaller than a KernFree, then just discard it Do this rather than trying to insert back into the freelist, because we use the free blocks to store the freelist links, and trying to write into this results in overwriting adjacent memory when the freed block is too small. --- src/allocator.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/allocator.rs b/src/allocator.rs index 4d24029..5cb59dc 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -449,6 +449,11 @@ impl InnerKernelAlloc { let b = *a; *a = KernAllocation::default(); + if b.length < core::mem::size_of::() { + trace!("Freed block (len={}) less than KernFree (len={})", b.length, core::mem::size_of::()); + return; + } + // Then add it back to the free list if let Some(fl) = (*s).freelist { // If it belongs at the head, insert it at the head