runtime: harden title_window_plan and ArenaBlocks bounds/overflow checks (RT-TITLE-WINDOW-AND-ARENA-BOUNDS) #1785
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1785"
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:08:24Z.
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 passImported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T12:08:36Z.
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 lixonik on 2026-11-25T12:13:40Z.
Review: COMMENTED
Independent A/B at
eb4c4204against its base0d80bc5d. The new bounds suite fails against the base at the check for a requested address below the lower bound. On this head, both the new bounds suite and arena_blocks_test passed with GCC and UBSan under Ubuntu/WSL. The existing title_window_plan_test also built with MSVC and passed on native Windows, including its budget and paired-view mapping controls.AI-assisted. CPU-only synthetic cases.
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T14:40:09Z.
Merged. 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).