Skip to content

fix: TOCTOU race condition in vTaskListTasks()#1431

Open
srpatcha wants to merge 1 commit into
FreeRTOS:mainfrom
srpatcha:fix/toctou-vTaskListTasks
Open

fix: TOCTOU race condition in vTaskListTasks()#1431
srpatcha wants to merge 1 commit into
FreeRTOS:mainfrom
srpatcha:fix/toctou-vTaskListTasks

Conversation

@srpatcha

Copy link
Copy Markdown

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

  • tasks.c: 2 lines changed (line 7359 and 7528)

Split from #1409 per reviewer request to separate the bug fix from .editorconfig changes.

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().
@sonarqubecloud

Copy link
Copy Markdown

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