runtime: harden title_window_plan and ArenaBlocks bounds/overflow checks (RT-TITLE-WINDOW-AND-ARENA-BOUNDS) #1785
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1785
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/rt-title-window-and-arena-bounds"
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?
Pull request successfully merged and closed
Summary
Hardens boundary, alignment, and unsigned-overflow checks in
runtime/src/title_window_plan.handruntime/src/arena_blocks.h(both on the world-start title-memory mapping and GPU arena allocation path merged in #1723).RT-TITLE-WINDOW-AND-ARENA-BOUNDSRoot causes & changes
runtime/src/title_window_plan.h:title_window_range():va < lo: previously only checkedhi <= va, so whenlo > va(e.g., ifgap()returnedlo > va) it returnedtruewithrange.start = lo > va(excludingva), causingoffset + (va - range.start)inresolve_title_memoryto underflow.most == 0instead of callingstd::clamp<std::uint64_t>(want, 1, 0)(UB).alignbefore masking with~(align - 1).raw_end = va + wantand alignment round-up with separate saturation guards soUINT64_MAX - want - aligncannot underflow whenwant + alignwraps.title_pool_extent():alignand rejectreadable_end <= vabefore roundingendup toalign(previously a partial readable run ending beforevainside the same alignment page rounded up pastvaand returnedtruefor an unreadable address).mostcap after alignment rounding soout.size <= mostalways holds even whenpool_lois unaligned ormost < align, and refuse ifend <= va.runtime/src/arena_blocks.h:(value + alignment - 1) / alignment * alignmentwith overflow-checkedalign_up(value, alignment, out)so large alignments or akeep_out_endnearUINT64_MAXcannot wrap to0and spin forever insideallocate().keep_outloop cleanly ifkeep_out_end <= startinstead of stalling.consistent(live_bytes)againstsize_ < reserved_underflow andfree_bytes_ + live_bytesoverflow.runtime/test/arena_blocks_test.cpp,runtime/test/title_window_plan_bounds_test.cpp, &runtime/CMakeLists.txt:arena_blocks_testwith overflowalign_up, wrappingkeep_out_end, stagnantkeep_out_end <= start, andconsistent()bounds checks.title_window_plan_boundsCTest covering alltitle_window_fits,title_window_range, andtitle_pool_extentboundary/overflow cases without<windows.h>.Verification
title_window_plan_testrely on Windows CI).clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined -O1 runtime/test/arena_blocks_test.cpp— passclang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=thread -O1 runtime/test/arena_blocks_test.cpp— passclang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/arena_blocks_test.cpp— passclang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined -O1 runtime/test/title_window_plan_bounds_test.cpp— passclang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/title_window_plan_bounds_test.cpp— passmainheaders: bothtitle_window_plan_bounds_test(va < lo) andarena_blocks_test(align_upoverflow) fail onmain, confirming regression coveragepython3 -I scripts/check_no_game_data.py runtime/src/title_window_plan.h runtime/src/arena_blocks.h runtime/test/arena_blocks_test.cpp runtime/test/title_window_plan_bounds_test.cpp runtime/CMakeLists.txt— passpython3 -I tests/test_text_write_line_endings.py— 3/3 passMerged. Thank you, @IlyassRS3, and thanks to @lixonik for the A/B.
va < locheck covers a real, race-only path (a range added by another thread between theshader_vacheck andgap()), which underflowed before.title_window_plan_boundspasses.main: nothing goes from pass to fail.end <= vaintitle_window_rangeandend <= startintitle_pool_extentcan never fire after the earlier checks, and the!mostandraw_endchecks have no case that fails without them.mainc3b58ef03+eb4c4204e: it merges cleanly; the semantic suite passes (489 files, 6,288 tests, 0 files failed); the 14 docs and writer tests pass;check_no_game_data.pyis clean on the 5 changed files.AI-assisted (Claude Code, Claude Opus 5.5).