Skip to content

fix: TOCTOU race condition in vTaskListTasks()#1431

Merged
AniruddhaKanhere merged 1 commit into
FreeRTOS:mainfrom
srpatcha:fix/toctou-vTaskListTasks
Jun 19, 2026
Merged

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

Conversation

@srpatcha

Copy link
Copy Markdown
Contributor

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

@AniruddhaKanhere AniruddhaKanhere left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @srpatcha!
This looks good to me. Approved!

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.28%. Comparing base (d5d752a) to head (9401749).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1431      +/-   ##
==========================================
- Coverage   91.37%   91.28%   -0.10%     
==========================================
  Files           6        6              
  Lines        3259     3269      +10     
  Branches      902      905       +3     
==========================================
+ Hits         2978     2984       +6     
- Misses        132      135       +3     
- Partials      149      150       +1     
Flag Coverage Δ
unittests 91.28% <100.00%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AniruddhaKanhere AniruddhaKanhere merged commit e146d64 into FreeRTOS:main Jun 19, 2026
18 of 19 checks passed
@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.

3 participants