Repository navigation
Implement stack/heap collision protection for processes - #42
Merged
Merged
Conversation
automas-dev
force-pushed
the
agents/stack-heap-protection-implementation
branch
2 times, most recently
from
September 6, 2026 03:20
a75453b to
e980edd
Compare
- Update I/O device handling in io_device.c - Modify system call processing in system_call_proc.c - Enhance process management in process.c - Improve test coverage for process handling in test_process.cpp
Adjust memory allocation logic for improved stack and heap protection.
- Update paging.h to enhance memory management definitions. - Modify memory.c to support new paging features. - Improve paging.c with additional stack-heap protection logic. - Adjust process.c to align with updated memory management. - Expand test coverage in test_paging.cpp and test_process.cpp.
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.
Implemented stack and heap collision protection so a process's heap and stack can never grow into each other, plus several related correctness fixes discovered and validated while testing this feature under headless QEMU boots.
Stack/heap collision guard (original feature)
HEAP_STACK_GUARD_PAGES, the minimum unmapped gap required between a process's heap and stack.process_add_pagesnow rejects heap growth that would come within the guard gap of the stack;process_grow_stacknow rejects stack growth that would come within the guard gap of the heap. Both check before touching paging structures and use additive comparisons to avoid unsigned underflow.process_add_pages_CollidesWithStack/process_grow_stack_CollidesWithHeap.Bug fixes found via headless-boot testing
SYS_CALL_PROC_PANIChandler had inverted null-checks that silently discarded the real panic message, and a%s/%uformat mismatch on the line number that crashed the kernel while trying to log a panic. Both fixed - process panics now log correctly instead of taking down the kernel.io_device_closehad an inverted success/failure check, logging a spurious "error 0" on every successful close and never logging real failures. Fixed.process_add_pagesandkernel_alloc_page(kmalloc's page source) both had an off-by-one when callingpaging_add_pages, mapping one extra page per call. This silently leaked/orphaned a physical page on every heap growth, and - sinceHEAP_STACK_GUARD_PAGES == 1- could fully erode the new stack/heap guard band in a single call.Range-convention refactor
Rather than patch each call site with a
-1/+1, convertedpaging_add_pages,paging_remove_pages, andpaging_id_map_rangefrom end-inclusive[start, end]to end-exclusive[start, end)ranges (matching common C/iterator conventions), and updated every call site accordingly. This removes the off-by-one bug at its root instead of just patching symptoms, and empty ranges (start == end) are now valid no-ops.Verification
make lintclean.