[BUG] POSIX port: data races on xSchedulerEnd and xTimerTickThreadShouldRun reported by ThreadSanitizer
メンテナーはふだん 3 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- c, linux
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- C
- スター
- 4.6k
- フォーク
- 1.6k
- 平均マージ
- 2日 22時間
- マージ済み PR(30日)
- 4
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
FreeRTOS/FreeRTOS-Kernel のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
FreeRTOS/FreeRTOS-Kernel#1542 ·
メンテナーはふだん 3 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
メンテナーはふだん 3 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
FreeRTOS/FreeRTOS-Kernel#1494 · コメント 3 件 ·
メンテナーはふだん 3 日以内に返信
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
メンテナーはふだん 3 日以内に返信
-
[BUG] event_wait_timed can't return false対応中かも @TedLyngmo が 39 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
メンテナーはふだん 3 日以内に返信
FreeRTOS/FreeRTOS-Kernel の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
shinyquagsire23/OpenJKDF2#540 ·
メンテナーはふだん 12 日以内に返信
-
Prison work hall: laundry and kitchen stations stand at bare walls, the hatch has no counter or signオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Life-Framework/Life-Framework#5939 ·
メンテナーはふだん 1 日以内に返信
-
autoconf failes to find libsodium even when present due to implicit function declaration対応中かも @coderjoe が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 13 日以内に返信
-
Bug Status: Needs Triage
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
bug python
難易度 2/5 1〜3時間 初心者へのやさしさ 87/100
Jstar269/nakagawa-recomp#3521 ·
メンテナーはふだん 1 日以内に返信