[BUG] Repeated delete or suspend of a task waiting termination desynchronizes uxDeletedTasksWaitingCleanUp and crashes the idle task
Les mainteneurs répondent en général sous 3 jours
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 20/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- c
- Domaine
- operating-systems
Piste de recherche
Start in tasks.c with vTaskDelete(), vTaskSuspend() and prvCheckTasksWaitingTermination(), tracing how xTasksWaitingTermination and uxDeletedTasksWaitingCleanUp are updated, and read the eDeleted note in task.h. Reproduce by deleting the same task twice, then delete followed by suspend, and watch the counter against the list length. Done means a repeated delete or suspend on a task already in xTasksWaitingTermination is a no-op, and the idle reap never reads the head of an empty list. The reporter says a fix is already prepared, so check for a linked PR before starting.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
A task that has been deleted but whose memory has not yet been freed by the idle task is kept on xTasksWaitingTermination (the eDeleted window documented in task.h). A second cleanup operation on that task corrupts the idle task's bookkeeping:
vTaskDelete()queues the TCB toxTasksWaitingTerminationand incrementsuxDeletedTasksWaitingCleanUpon every call with no membership guard (tasks.c, F4 branch:vListInsertEnd( &xTasksWaitingTermination, ... )+++uxDeletedTasksWaitingCleanUp). A repeated delete re-counts the task (deletedCount=2, termLen=1) or, if the task is no longer running, frees the TCB immediately while the idle task still owns its cleanup.vTaskSuspend()moves the state item out ofxTasksWaitingTerminationintoxSuspendedTaskListwithout decrementing the counter (deletedCount=1, termLen=0).prvCheckTasksWaitingTermination()loops on the counter and callslistGET_OWNER_OF_HEAD_ENTRY( &xTasksWaitingTermination )on an empty list (1-core and SMP paths) - the list end marker has no owner, so the idle task reads 8 bytes past theList_tand dereferences the garbage task pointer.
Result: crash-class memory corruption in the idle task on the next idle-loop iteration.
Target
- Development board: any SMP or single-core target (reproduced on a POSIX host-port harness, 1-core and 2-core configurations; the mechanism is configuration independent)
- Instruction Set Architecture: host arm64 reproduction; expected on any architecture
- Toolchain and version: clang (host), FreeRTOS-Kernel
8be86d4a2
To Reproduce
Only public APIs, no source changes: xTaskCreate, vTaskDelete, vTaskSuspend. Two independent cleanup call sites act on one task's handle before the idle reap (e.g. a watchdog-timeout delete and a shutdown-path delete), each issuing exactly one operation:
vTaskDelete(victim)while the victim is still executing -> TCB queued,uxDeletedTasksWaitingCleanUp = 1.vTaskDelete(victim)again -> counter re-counted (2 != 1); orvTaskSuspend(victim)-> TCB moved toxSuspendedTaskList, counter left at1, list length0.- Idle task runs
prvCheckTasksWaitingTermination()-> reads the head entry of the empty list -> SIGSEGV in plain builds.
ASan (2-core, double delete):
==ERROR: AddressSanitizer: global-buffer-overflow on address ...
READ of size 8 at ... thread T3
#0 ... in prvCheckTasksWaitingTermination tasks.c:6435
#1 ... in prvIdleTask tasks.c:6110
...is located 0 bytes after global variable 'xTasksWaitingTermination' ... of size 40
SUMMARY: AddressSanitizer: global-buffer-overflow tasks.c:6435 in prvCheckTasksWaitingTermination
The same ASan signature appears for the delete+suspend variant (and at the 1-core reap path when built for one core). A reproduction script with negative controls is available.
Expected behavior
task.h documents the eDeleted window as a first-class state, gives no exactly-once/liveness precondition for vTaskDelete(), and explicitly blesses repeated vTaskSuspend() calls ("not accumulative"). Therefore:
- a repeated
vTaskDelete()/vTaskSuspend()on a task inxTasksWaitingTerminationshould be a no-op (the idle task owns its cleanup), and prvCheckTasksWaitingTermination()must never read the head entry of an emptyxTasksWaitingTermination, whatever the counter says.
Additional context
- Honest caveat: if the idle reap wins the race before the second operation, the same second call becomes a use-after-free of the already-freed TCB (observed as an OOB read past
xSuspendedTaskListinvTaskSwitchContextunder ASan, silent in plain builds). That is the dangling-handle-after-free case and is outside what a membership guard can fix; the deterministic drift above is the kernel-side defect. configASSERTdoes not guard this path even when enabled; the counter is never recomputed from the list length.- No prior report of this mechanism found in issues, recently merged/closed PRs, or git history. (#892 names a sibling site as a question and was redirected to the forums; it does not report this drift.)
- A fix with regression tests is prepared; PRs will reference this issue.
- Langage dominant
- C
- Étoiles
- 4.6k
- Forks
- 1.6k
- Merge moyen
- 2 j 22 h
- PR mergées (30 j)
- 4
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de FreeRTOS/FreeRTOS-Kernel
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
FreeRTOS/FreeRTOS-Kernel#1542 ·
Les mainteneurs répondent en général sous 3 jours
-
[BUG] Release asset FreeRTOS-KernelV11.3.2.zip has the files of main, not of the tag V11.3.2Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
Les mainteneurs répondent en général sous 3 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
FreeRTOS/FreeRTOS-Kernel#1494 · 3 commentaires ·
Les mainteneurs répondent en général sous 3 jours
-
enhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
Les mainteneurs répondent en général sous 3 jours
-
[BUG] event_wait_timed can't return falsePeut-être pris @TedLyngmo l’a pris il y a 39 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
Les mainteneurs répondent en général sous 3 jours
Toutes les issues de FreeRTOS/FreeRTOS-Kernel
Issues similaires
-
RecompLauncher supportOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
shinyquagsire23/OpenJKDF2#540 ·
Les mainteneurs répondent en général sous 12 jours
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Life-Framework/Life-Framework#5939 ·
Les mainteneurs répondent en général sous 1 jour
-
autoconf failes to find libsodium even when present due to implicit function declarationPeut-être pris @coderjoe l’a pris aujourd’hui. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 13 jours
-
SessionInterfaceHandler is throwing a deprecation notice as a warning instead of a deprecationOuverteBug Status: Needs Triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 74/100
Les mainteneurs répondent en général sous 1 jour
-
enhancement_package: a site operand of another JSON type raises TypeError, not a named refusalOuvertebug python
Difficulté 2/5 1-3 heures Accessibilité débutants 87/100
Jstar269/nakagawa-recomp#3521 ·
Les mainteneurs répondent en général sous 1 jour