kernel bug fixes#40
Open
MichealFlick wants to merge 12 commits into
Open
Conversation
added 12 commits
May 28, 2026 08:54
…e operation and inline mappings instead of drop-and-reacquire
… just setting pointer to NULL
…se spinlock when utilizedBy reaches 0. Reorder taskKill to set DEAD state before freeing page directory.
…ndefined behavior for signals >= 32
…t to iterative loop, fix pre-existing buff leaks in error paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
found around like 12 bugs poking around the kernel. memory leaks, overflows, races, ub, the usual fun stuff. decided to fix it in my spare time.
readHandler wasnt freeing its buffer on eof so every read(0) that hit the end leaked whatever limit was. added the free.
fsReadlink takes a size from userspace that can be negative. MIN picks the negative, memcpy goes to town. checked for negative at the top and cast to size_t before the comparison.
PhysicalFree never checked if a page was already free. double-free corrupts the bitmap silently, then two allocators get the same page. added a check that panics with debug info if it happens again.
sbrk returned 0 on failure instead of (void*)-1. dlmalloc checks for (void*)-1 so it thought address zero was valid memory. easy fix.
taskKill busy-spun with while(1){} when a task killed itself. 100% cpu for no reason. swapped to while(1) handControl() so it yields.
VirtualToPhysicalL had its page table lock commented out. walking ptes without the lock means another thread can change them while you read. just re-enabled the calls that were already there but disabled.
PageDirectoryUserDuplicate dropped the write lock in the middle of the fork copy to call VirtualMapL. another thread could sneeze on the page tables in that gap. inlined the writes and held the lock the whole time.
ext2Write cache clear set a pointer to null but never freed the old entries. was leaking every cache eviction. walks the chain and frees everything properly now.
taskInfoPdDiscard never actually freed the struct when the refcount hit zero and also forgot to release the spinlock. taskKill was freeing the page directory before setting the task state to dead so the scheduler could try to schedule a corpse. fixed both.
(1 << signal) for signal >= 32 is undefined behavior. signals 32-64 just broke silently. changed to ((sigset_t)1 << signal) everywhere.
ahciCmdIssue had no timeout. if a drive hung, the kernel locked up forever. added a 5k tick deadline and returns false.
shebang execve was recursive with no depth limit. a shebang loop blows the stack. rewrote it iterative with a depth counter capped at 8 and returns ELOOP. also found two buffer leaks in the error paths from before and plugged those while i was there.