Skip to content

kernel bug fixes#40

Open
MichealFlick wants to merge 12 commits into
malwarepad:masterfrom
MichealFlick:master
Open

kernel bug fixes#40
MichealFlick wants to merge 12 commits into
malwarepad:masterfrom
MichealFlick:master

Conversation

@MichealFlick

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant