Skip to content

Conversation

@visitorckw
Copy link
Collaborator

The system was encountering a critical kernel panic, manifesting as:

*** KERNEL PANIC (-16370) – heap corruption or invalid free

The core problem stemmed from a conflict between two memory management strategies for linked-list nodes. The timer module utilized a custom static memory pool for its nodes, while the generic list manipulation functions performed their own malloc() and free() operations. This architectural mismatch led to two critical bugs.

Firstly, a double-free occurred in mo_timer_destroy(). The generic list_remove() function would free a list node's memory, and then the same function would attempt to return this already-freed node to the custom memory pool.

Secondly, a use-after-free vulnerability existed in the _timer_tick_handler(). If an expired timer's callback function destroyed the timer, the handler would subsequently attempt to access the now-freed timer's memory to check its auto-reload status.

Fix these issues by removing the custom memory pool and unifying all node memory management under the generic list API. The _timer_tick_handler() now also re-validates the timer's existence after its callback executes to prevent accessing freed memory.

The system was encountering a critical kernel panic, manifesting as:
*** KERNEL PANIC (-16370) – heap corruption or invalid free

The core problem stemmed from a conflict between two memory management
strategies for linked-list nodes. The timer module utilized a custom
static memory pool for its nodes, while the generic list manipulation
functions performed their own malloc() and free() operations. This
architectural mismatch led to two critical bugs.

Firstly, a double-free occurred in mo_timer_destroy(). The generic
list_remove() function would free a list node's memory, and then the
same function would attempt to return this already-freed node to the
custom memory pool.

Secondly, a use-after-free vulnerability existed in the
_timer_tick_handler(). If an expired timer's callback function
destroyed the timer, the handler would subsequently attempt to access
the now-freed timer's memory to check its auto-reload status.

Fix these issues by removing the custom memory pool and unifying all
node memory management under the generic list API. The
_timer_tick_handler() now also re-validates the timer's existence after
its callback executes to prevent accessing freed memory.
@jserv jserv merged commit 2ad3517 into sysprog21:main Oct 19, 2025
@jserv
Copy link
Contributor

jserv commented Oct 19, 2025

Thank @visitorckw for contributing!

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.

2 participants