(cortex-m) unexpected kernel panic after thread exit #20812
Labels
Area: core
Area: RIOT kernel. Handle PRs marked with this with care!
Type: bug
The issue reports a bug / The PR fixes a bug (including spelling errors)
Description
I've noticed an unexpected kernel panic after a thread exited. I've traced it down to
sched_switch
incore/sched.c
retrieving an invalid active thread. Insidesched_task_exit
, thesched_active_thread
pointer is being set to NULL andsched_switch
does not check if the retrieved thread pointer points to a valid thread.Steps to reproduce the issue
I have created a small application that triggers the problem (tested on an STM32 NUCLEO-F401RE, problem initially seen on an EFR32). It uses the
shell
module as the problem is triggered when the scheduler is invoked. After starting the application, enter a character in the console/terminal to invoke the scheduler.Inside
core/sched.c
I've added an assertion to enforce the problem (without it sometimes magically goes well).main.c
Expected results
After accessing the console, I would expect the system to stay alive ;)
Actual results
After entering an enter character in the console, I get the following panic and stack trace.
Potential Fix
I've changed
sched_switch
to include a check for active thread being valid to deal with threads having exited.I don't know if
sched_switch
must be able to deal with this case or ifsched_task_exit
shouldn't set thesched_active_thread
to NULL. The comment aroundthread_get_active
indicates the first. In that case we need to check if there are other functions that cannot deal with this case and potentially add assertions to help finding those cases in the future.Versions
RIOT version: master (5267300)
The text was updated successfully, but these errors were encountered: