[BUG] xTaskCreate() unsigned integer overflow when calculating stack size

Aperta
#1,472 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@JacksonBopp ci sta già lavorando.

Dal 5/9/2026.

  • #1488 di @JacksonBopp — aperta
  • #1489 di @saikumar-mandaji — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
c

Direzione di ricerca

The overflow is in prvCreateTask() in FreeRTOS/Source/tasks.c, where uxStackDepth * sizeof(StackType_t) is passed to pvPortMallocStack(), and prvInitialiseNewTask() then uses the unchecked depth. Read the open pull requests #1488 and #1489 first, since they already target this bug, and check whether the discussion has settled the approach. Done means an overflow check before allocation that returns a creation failure, applied to every dynamic stack allocation path.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Describe the bug
xTaskCreate() accepts a task stack depth in words. On 32-bit Cortex-M ports, the default configSTACK_DEPTH_TYPE and size_t are both 32-bit, but the kernel allocates the stack using unchecked uxStackDepth * sizeof(StackType_t). An oversized depth wraps to a small allocation; initialization then retains the original depth and performs stack pointer arithmetic using that value.

Target
FreeRTOS revision 592732b4d
FreeRTOS/Source/tasks.c, prvCreateTask() and prvInitialiseNewTask()
Cortex-M7 default port: FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1/portmacro.h

Host

  • Host OS: Ubuntu 24

To Reproduce
On a 32-bit size_t / 32-bit StackType_t target, pass a depth greater than UINT32_MAX / 4; for example 0x40000020 words. The allocation expression wraps to 128 bytes, while prvInitialiseNewTask() computes a top-of-stack using pxStack[uxStackDepth - 1] and initializes the task from that original depth.

Expected behavior
The allocation-size multiplication is not checked before pvPortMallocStack(). The later initialization path assumes the requested word count was allocated.

Additional context
Before allocating, reject uxStackDepth > SIZE_MAX / sizeof(StackType_t) and return task-creation failure. Apply the same check to all dynamic stack allocation paths. A product should additionally impose a realistic maximum task-stack size at its API boundary.

Lingua principale
C
Stelle
4.6k
Fork
1.6k
Merge medio
2g 22h
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di FreeRTOS/FreeRTOS-Kernel

Tutte le issue di FreeRTOS/FreeRTOS-Kernel

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.