runtime: fix PipelineWorkers stack use-after-free on OOM in start() (RT-PIPELINE-WORKERS-OOM-UAF) #1821
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1821"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T12:32:44Z.
Summary
Item:
RT-PIPELINE-WORKERS-OOM-UAFClaim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162472188
Fixes a stack use-after-free and OOM submission failure in
leonida::PipelineWorkers::run()(runtime/src/pipeline_workers.h):&batchtoqueue_: previouslyrun()pushed the address of its stack-localBatchontoqueue_and updatedbatches_/jobs_before callingstart(count - 1). Becausestart()only caughtstd::system_errorand notstd::bad_alloc, an allocation failure growingthreads_(or allocating astd::threadcontrol block) unwoundrun()and destroyedbatchon the stack while leaving&batchdangling inqueue_. The next wakeup of any existing worker dereferenced the freed stack frame (AddressSanitizer: stack-use-after-returnatpipeline_workers.h:120).std::bad_allocinstart()andqueue_.push_back():start()catchesstd::bad_allocand breaks out of the growth loop without permanently latchingexhausted_, so the existing workers and caller complete the current batch and later batches can scale up again once memory is available.run()guardsqueue_.push_back(&batch)againststd::bad_alloc; if enqueuing fails, it unlocksmutex_and runs the batch inline on the calling thread without mutatingbatches_/jobs_or publishing a dangling pointer.oom_during_start_and_enqueue()toruntime/test/pipeline_workers_test.cppusing a thread-localoperator newfailure injector covering both mid-growth OOM (which deterministically triggers ASanstack-use-after-returnonmain) and hard first-batch OOM with inline fallback and post-OOM recovery.Testing
clang++(C++20)runtime/test/pipeline_workers_test.cppwith-std=c++20 -Wall -Wextra -Werror:ASAN_OPTIONS=detect_stack_use_after_return=1):pipeline_workers_test: passed-fsanitize=thread):pipeline_workers_test: passed(0 data races)-O2× 3 runs:pipeline_workers_test: passedmain(0d80bc5df): compiled the updatedpipeline_workers_test.cppagainstmain:runtime/src/pipeline_workers.hunder ASan (detect_stack_use_after_return=1); reproducedERROR: AddressSanitizer: stack-use-after-returninPipelineWorkers::step(pipeline_workers.h:120, rc=134).python3 -I scripts/check_no_game_data.py runtime/src/pipeline_workers.h runtime/test/pipeline_workers_test.cppandpython3 -I tests/test_text_write_line_endings.py: both passed.Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T12:32:59Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:51:47Z.
Verified on Windows 11 (
10.0.26200.9974) with MSVC19.44.35228(x64,/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) againstmain24549bdb1+703dfb493(claim#2570#issuecomment-7238799031):runtime/src/pipeline_workers.h,runtime/test/pipeline_workers_test.cpp); callsstart(count - 1)(catchingstd::bad_alloccleanly) before pushing stack-allocated&batchontoqueue_, and falls back to inline execution ifqueue_.push_back(&batch)throwsstd::bad_alloc, eliminating the dangling stackBatch*use-after-free on subsequent worker wakeups.check_no_game_data.pyclean.24549bdb1+ PR test):pipeline_workers_test.execrashes with0xc0000005(STATUS_ACCESS_VIOLATIONfrom the dangling stackBatch*inqueue_after injectedstd::bad_allocinstart()).24549bdb1+703dfb493merge): Merges cleanly (rc=0), compiles with0/W4warnings, andpipeline_workers_test.exepasses (pipeline_workers_test: passed,rc=0).AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:57:10Z.
Red/green: On main pipeline_workers_test crashes with an access violation (a dangling stack Batch pointer left in the queue after an injected bad_alloc in start()), and with the PR ctest -R "^pipeline_workers$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main
c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:54:17Z.
Verified by OreoFR
c1ecf04ed+ PR head703dfb493; green run in a merge package of 15 PRs, no new ctest failure vs mainctest -R ^pipeline_workers$AI-assisted (Claude Code, Claude Opus 5.5).