[BUG] POSIX port: data races on xSchedulerEnd and xTimerTickThreadShouldRun reported by ThreadSanitizer
Los mantenedores suelen responder en 3 días
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- c, linux
- Área
- operating-systems
Línea de trabajo
Start in portable/ThirdParty/GCC/Posix/port.c: the racing accesses are xSchedulerEnd (read in xPortStartScheduler near line 295, written in vPortEndScheduler near line 340) and xTimerTickThreadShouldRun (written near line 331, read in prvTimerTickHandler near line 460). Reproduce with the attached build_and_run.sh, which builds the kernel with -fsanitize=thread. Done means the ThreadSanitizer data-race warnings no longer appear across repeated runs, and the program still exits normally.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
In portable/ThirdParty/GCC/Posix/port.c, xSchedulerEnd and xTimerTickThreadShouldRun are plain
(non-atomic, non-volatile) globals that are written by one thread and read by another without
synchronization:
xSchedulerEndis read by the main thread inxPortStartScheduler()(while( xSchedulerEnd != pdTRUE ),
line 295) and written by a task thread invPortEndScheduler()(line 340).xTimerTickThreadShouldRunis read by the tick thread inprvTimerTickHandler()(line 460) and
written invPortEndScheduler()(line 331).
Under the C11 memory model these are data races (undefined behaviour). ThreadSanitizer reports both.
Target
- Development board: none (POSIX simulator port)
- Instruction Set Architecture: x86_64
- IDE and version: none (command line)
- Toolchain and version: gcc 13.3.0,
-fsanitize=thread - Kernel: main at ca75944 (also reproduced on V11.3.2, 640d0c4), heap_3
Host
- Host OS: Ubuntu Linux
- Version: 24.04
To Reproduce
A single task that ends the scheduler is enough (attached main.c, FreeRTOSConfig.h, build_and_run.sh):
static void vTask( void * pv ) { ( void ) pv; vTaskEndScheduler(); }
int main( void ) {
xTaskCreate( vTask, "end", configMINIMAL_STACK_SIZE, NULL, 1, NULL );
vTaskStartScheduler();
return 0;
}
Build with -fsanitize=thread -pthread together with tasks.c list.c queue.c timers.c port.c wait_for_event.c heap_3.c and run with setarch $(uname -m) -R ./repro_tsan
(./build_and_run.sh <path-to-FreeRTOS-Kernel> does both and runs 5 times).
Reproduced in 5 of 5 runs:
WARNING: ThreadSanitizer: data race
Write of size 8 by thread T1:
#0 vPortEndScheduler portable/ThirdParty/GCC/Posix/port.c:340
#1 vTaskEndScheduler tasks.c:3884
Previous read of size 8 by main thread:
#0 xPortStartScheduler portable/ThirdParty/GCC/Posix/port.c:295
#1 vTaskStartScheduler tasks.c:3818
Location is global 'xSchedulerEnd'
The full output is in the attached tsan_output.txt (it also contains the report for
xTimerTickThreadShouldRun, port.c:331 x port.c:460).
Expected behavior
No data race. Possible fix: make both variables atomic (e.g. __atomic_load_n/__atomic_store_n,
or volatile sig_atomic_t for the flag polled around sigwait).
Additional context
We are aware that ThreadSanitizer does not model pthread_kill/sigwait as synchronization; however,
the first read of the loop happens before the signal is sent, so the accesses are concurrent. We did
not observe a functional failure without the sanitizer (the program ends normally).
Found with SMART CPS, a verification tool based on the ESBMC bounded model checker
(--data-races-check on the port), which also generated the reproducer: it rebuilds the unmodified
kernel sources with ThreadSanitizer, runs them 5 times and matches the reported race against the
variable in the counterexample.
- Lenguaje dominante
- C
- Estrellas
- 4.6k
- Forks
- 1.6k
- Merge medio
- 2 d 22 h
- PR fusionados (30 d)
- 4
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de FreeRTOS/FreeRTOS-Kernel
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
FreeRTOS/FreeRTOS-Kernel#1542 ·
Los mantenedores suelen responder en 3 días
-
[BUG] Release asset FreeRTOS-KernelV11.3.2.zip has the files of main, not of the tag V11.3.2Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
Los mantenedores suelen responder en 3 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
FreeRTOS/FreeRTOS-Kernel#1494 · 3 comentarios ·
Los mantenedores suelen responder en 3 días
-
enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
Los mantenedores suelen responder en 3 días
-
[BUG] event_wait_timed can't return falsePosiblemente ocupada @TedLyngmo la tomó hace 39 días. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
Los mantenedores suelen responder en 3 días
Todos los issues de FreeRTOS/FreeRTOS-Kernel
Issues similares
-
RecompLauncher supportAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
shinyquagsire23/OpenJKDF2#540 ·
Los mantenedores suelen responder en 12 días
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Life-Framework/Life-Framework#5939 ·
Los mantenedores suelen responder en 1 día
-
autoconf failes to find libsodium even when present due to implicit function declarationPosiblemente ocupada @coderjoe la tomó hoy. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 13 días
-
SessionInterfaceHandler is throwing a deprecation notice as a warning instead of a deprecationAbiertoBug Status: Needs Triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
enhancement_package: a site operand of another JSON type raises TypeError, not a named refusalAbiertobug python
Dificultad 2/5 1-3 horas Aptitud para principiantes 87/100
Jstar269/nakagawa-recomp#3521 ·
Los mantenedores suelen responder en 1 día