UCM: check sbrk failure in ucm_fire_mmap_events_internal #12519
All Vouch review confidence checks passed
Residual risk 0.33 = Change Risk (0.57) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #12519"
general
weight: 0.35
tvegas1
What?
Check the result status of
sbrkinucm_fire_mmap_events_internaland avoid unmapping if it didn't succeed.Why?
This PR fixes a rare but persistent failure we've seen in Legion CI for many years. We finally root caused and diagnosed the issue as an unchecked
sbrkcall in UCX. We are working around the failure in Legion, but meanwhile, the proper fix in UCX is ~2 lines and seems worth taking.For posterity, the Legion CI workaround: https://gitlab.com/StanfordLegion/legion/-/merge_requests/2144
How?
The fix is about 2 lines of actual changes and hopefully self-evident enough, but a detailed root cause diagnosis is also available below.
Note: this bug was triaged and fixed by Claude Opus 5.5, but the fix is so simple that I think it's fairly self-evident even as a non-UCX expert. Claude's analysis also includes a reproducer for posterity.
Claude's analysis
UCM: Unchecked
sbrk(sbrk_size)failure inucm_fire_mmap_events_internal()unmaps live[heap]page and causesSIGSEGVinmallocSummary
In
src/ucm/mmap/install.c,ucm_fire_mmap_events_internal()testsUCM_EVENT_SBRKby callingsbrk(sbrk_size)and thensbrk(-sbrk_size), ignoring the return value ofsbrk(sbrk_size).If
sbrk(sbrk_size)fails withENOMEM(returns(void )-1/MAP_FAILED)—for example because an existing VMA sits immediately adjacent to the end of[heap]—the unconditionalsbrk(-sbrk_size)call still succeeds and shrinks the program break by one page below its original value, silently unmapping the top page of glibc's live[heap]. Subsequentmalloc()calls dereferencing chunks ormain_arena.topin that unmapped page crash withSIGSEGV.Affected Versions
Confirmed in v1.14.1 and v1.20.1, and the bug is still present on
master(andv1.23.0-rc4) atsrc/ucm/mmap/install.clines 217–222.Root Cause
In
src/ucm/mmap/install.c(ucm_fire_mmap_events_internal()):brk(p + sbrk_size)fails, the subsequentbrk(p)is a no-op because the break is stillp.sbrk(sbrk_size)fails ((void )-1), the break did not advance, yetsbrk(-sbrk_size)unconditionally moves the break backward bysbrk_size(4096 bytes), unmapping a live page owned by glibc's allocator.Real-world trigger
We hit this in CI (~1 in 20,000–30,000 process launches) in Legion/Regent (
terra), which runs LuaJIT beforedlopen()-ing a shared library linked against UCX. LuaJIT'smcodeallocator maps 64 KBr-xpJIT code pages with anmmap(hint)within ±2 GB of the PIE binary (overlapping[heap]'s address range). Whenever[heap]ends immediately adjacent to a LuaJITmcodeVMA at the timelibucs.so.0initializes (ucs_init()→ucm_mmap_init()→ucm_mmap_install(events, 1)),sbrk(+4096)fails withENOMEM,sbrk(-4096)unmaps the top 4 KB page of[heap], and the process segfaults inside glibcmalloc(_int_malloc,unlink_chunk, or tcache pop).Minimal Reproducer
The following standalone C program (requiring only
libucs.so.0) reproduces the bug 100% deterministically on Linux x86_64:Build & Run
Observed Output (UCX 1.20.1, Ubuntu 22.04 / glibc 2.35, x86_64)
In
gdb:With
UCX_MEM_MMAP_HOOK_MODE=relocorUCX_MEM_EVENTS=no:Suggested Fix
Check the return value of
sbrk(sbrk_size)before callingsbrk(-sbrk_size)(matching theif (p != MAP_FAILED)guard already used formmap()a few lines below):We verified this patch against UCX 1.20.1: with the patch applied,
brk_after == brk_before(delta = 0 bytes) and both the standalone C reproducer and our fullterra/Regent reproducers exit cleanly with status0.