TLS: audit static TLS directory raw data sizing, alignment, and index allocation (#106) #1421
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ivall/xcl. Originally posted by slopgobblercobbler on 2026-11-24T15:53:27Z.
Summary
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
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T16:52:17Z.
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
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:56:01Z.
Review: COMMENTED
AI-assisted review; I checked the RVA arithmetic against the supported 8 KiB alignment.
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:59:03Z.
Review: COMMENTED
CONTRIBUTING.md also requires paired real-title
scripts/smoke.ps1runs for this runtime change, withmainand this head tested on the same title and duration. The current description has no regression blocks and says real-title execution was not tested. Please add the required pair before merge, documenting if the title does not exercise TLS installation. AI-assisted review; I checked the current description against the guide.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:52:21Z.
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!
Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:56:01Z.
Code review location:
crates/xcl/src/tls.rs; line 124This 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.Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:30:45Z.
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.upstream-sync referenced this pull request2026-11-25 06:04:27 +00:00
Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T08:01:56Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:43:43Z.
Triage (#1607) – head
8052b9cThis makes the same change as #196: loader.rs passes t.characteristics to the TLS install, tls.rs writes them into the carrier's IMAGE_TLS_DIRECTORY64, aligns the template start to the decoded alignment, and moves the IMAGES push after LoadLibraryW with the slot index already set. #196 was opened first, also sanitises the reserved/0xF alignment bits (this PR copies the raw Characteristics into the carrier) and merges cleanly; this PR conflicts with main.
The extra guards here (k == 0 / NO_INDEX in take_slot_zero and exchange_for_new_thread, write_unaligned on the index, uninstall on error) could go to #196 or a small follow-up; take_slot_zero was already hardened on main by #1083.
Recommendation: close (duplicate of #196).
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.