fix: TOCTOU race condition in vTaskListTasks()#1431
Open
srpatcha wants to merge 1 commit into
Open
Conversation
Read uxCurrentNumberOfTasks once into uxArraySize and use that local variable for both the size check and pvPortMalloc() call. The previous code read the volatile variable twice, allowing a task to be created between the reads, resulting in an undersized allocation that could cause a buffer overflow in uxTaskGetSystemState().
|
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.



Description
vTaskListTasks() and vTaskList() read the volatile uxCurrentNumberOfTasks twice: once for the zero-check and once for pvPortMalloc(). If a task is created between the two reads, the allocated buffer is undersized, causing a potential buffer overflow in uxTaskGetSystemState().
Fix
Use the local variable uxArraySize (already assigned from uxCurrentNumberOfTasks) for the pvPortMalloc() call instead of re-reading the volatile.
Changes
Split from #1409 per reviewer request to separate the bug fix from .editorconfig changes.