TLS: audit static TLS directory raw data sizing, alignment, and index allocation (#106) #1431
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1431
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1431"
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?
@slopgobblercobbler on GitHub · 2026-11-24 15:53 UTC · original
slopgobblercobbler:fix/tls-directory-audit→main· +233 −30 · 2 files · 1 commits · openSummary
Fixes #106 Item 1:
crates/xcl/src/tls.rs):carrier_template_size_alignedtoMAX_CARRIER_TEMPLATE_SIZE = 0xFFFE_0000, usingsaturating_addand masking against requested alignment.install_with_characteristics, computedrequired_len = total_len.max(template_len as u64)to strictly prevent buffer overflow whentotal_len < template_len.saturating_addinbuild_carrier_dll_withfordata_vsizeandsize_of_image.alignment_from_characteristicsandcharacteristics_from_alignmentto decode/encode PEIMAGE_SCN_ALIGN_*bits (bits 20..24, 1..8192 bytes).Characteristicsin the synthesized carrier DLL'sIMAGE_TLS_DIRECTORY64, ensuring the OS loader allocates TLS blocks with requested alignment (e.g. 32/64 bytes for AVX/cachelines)..datatemplate offset whenalign > 256soStartAddressOfRawDataandEndAddressOfRawDatasatisfy the alignment requirement.NO_INDEXchecks intls_block_of,take_slot_zero,exchange_for_new_thread, andfill_block.TlsImageintoIMAGESonly after load success, and addeduninstall(img_name)for teardown cleanup.crates/xcl/src/loader.rs):t.characteristicsfrompe.tls()totls_installand wiredcrate::tls::uninstall(&module.name)andmodules::unregister_mapped(base)on installation failure.Changes
crates/xcl/src/tls.rs:carrier_template_size_aligned: alignment and saturating length bounds.alignment_from_characteristics/characteristics_from_alignment: PE alignment bit mapping.uninstall: TLS image cleanup helper.crates/xcl/src/loader.rs:Tested
cargo test -p xcl -- tls: 10 passed, 0 failed (100% pass rate).Not Tested
AI Use
Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
@futurepro62 on GitHub · 2026-11-24 16:52 UTC · original · edited 2026-11-24 17:01 UTC
Full-suite run, since this PR has no test report yet. Tested exact head
8052b9c(on its base930e8b4).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 755 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.alignment_preservation_and_characteristics,carrier_alignments_in_pe_headers,index_allocation_safety,install_with_characteristics_aligned.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 755 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
@DavidM1911 on GitHub · 2026-11-24 18:52 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
@Toons29 on GitHub · 2026-11-25 03:30 UTC · original
Regression run of
8052b9c2on the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 99 % of
main's frames, 100 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; I checked the blocks before posting.@ -90,0 +121,4 @@let align = alignment_from_characteristics(opts.characteristics);let template_size = carrier_template_size_aligned(template_size as u64, align);let off_template = if align > 256 {(OFF_TEMPLATE + align - 1) & !(align - 1)@gut0to on GitHub · 2026-11-24 18:56 UTC · original
This aligns the section-relative offset, but the final template RVA is
DATA_RVA + off_templatewithDATA_RVA = 0x3000. For the supported 8 KiB alignment, this computesoff_template = 0x2000, so the start RVA is0x5000and0x5000 % 0x2000 == 0x1000; it is not 8 KiB aligned. The current 512-byte test passes because0x3000is divisible by 512. Could the offset be chosen from the absolute RVA and add an 8 KiB header test? AI-assisted review; I verified the arithmetic.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.