startup: refuse a storage request with a non-writable destination #1665
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1672"
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 R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:49:12Z.
Change
A DirectStorage request into a plain destination pointer is copied with one
memcpyinxcrdapi.cpp. The only check before it compares sizes. A run on #870 ended with a write fault inside that copy: the destination was not writable to its declared capacity.Now
destination_writablewalks the destination withVirtualQuery, region by region, over the whole declared capacity, before the first byte is written. A page that is uncommitted, read-only,PAGE_GUARDorPAGE_NOACCESSrefuses the request:requests_failed, logged once per the existing limit as... -> destination not writable, and the next status entry reportsE_FAIL, like the other refusals in the file;Choices:
VirtualQueryper region the destination spans, per request that reaches the copy. On a multi-gigabyte region one query can take about a millisecond.Refs #870, #1198.
Verification
Linux:
git diff --check: clean.python tests/docs_links_check.py: self-test passed, 16 Markdown files and 351 links.python tests/bidi_controls_check.py: self-test passed, 1277 tracked files, no bidirectional controls.x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-onlyontests/startup_dstorage_destination_check.cpp: no diagnostics. Onxcrdapi.cpp: only the MSVC-only__try/__excepterrors inlocal_log.h.destination_writablebuilt outside the project and run under Wine: all rows passed (all writable, zero bytes, null, length overflow, past the allocation, read-only, guard, no-access and decommitted middle or last page, mixed read-write and execute-read-write). Two local mutations were each caught and reverted: removing the guard/no-access test failed the guard row; stopping after the first region failed five rows.git merge-treeagainst #1390, #1429 and #1616: the same files conflict with this branch as with current main, so this change adds no new conflicting file.Windows Server 2025 (Build 26100, MSVC 14.44.35207), commit
79899b7d, viax2w_pipe.py win2025 1672 --targets d3d12_xs_shim,startup_dstorage_destination_check,startup_storage_alloc_failure,startup_stub_acphal,startup_stub_chad,startup_stub_consumer,startup_stub_gameinput,startup_stub_xapu,startup_stub_xcrdapi,startup_stub_xg_xs,xmem_shim --regex '^(startup_dstorage_destination|startup_heartbeat_commit|startup_storage_alloc_failure|startup_stubs)$':--preset dev): build passed;ctest --preset dev: 4/4 passed, includingstartup_dstorage_destination./O2(--preset release): build passed;ctest --preset release: 4/4 passed, includingstartup_dstorage_destination.Evidence
tests/startup_dstorage_destination_check.cpp(cteststartup_dstorage_destination) loads the stand-in DLL and sends memory-source requests into three pages that start as0xAA. Each case makes one part unusable: a read-only, a guard and a no-access middle page, and a capacity one page past the committed pages. Each must fail with the process alive and the first page (and, where readable, the last) still0xAA. Afterwards a request into a fully writable buffer on the same queue must write every byte.docs/startup-runtime.mdanddocs/experiments.mddescribe it.Checklist
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T16:56:10Z.
The guard works; one allowed protection is never exercised, and one check is redundant
Reviewed
79899b7d. Built at that head, ran the fixture, then removed four pieces ofdestination_writableone at atime and rebuilt the DLL that the fixture actually loads (
XCRDAPI.dll, targetstartup_stub_xcrdapi) — the firstattempt rebuilt the wrong target and every mutant appeared to survive, so the numbers below are from the run where
XCRDAPI.dll's timestamp changed each time.Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100.
Mutations
PAGE_GUARDfrom the reject maskPAGE_READWRITE, dropPAGE_WRITECOPYcursor = region_end->cursor += 1info.State != MEM_COMMITThe one that matters
PAGE_WRITECOPYandPAGE_EXECUTE_WRITECOPYare in the allowed set, and no case exercises them: deletingprotect != PAGE_WRITECOPYleaves the fixture green. A copy-on-write destination is a legitimate target for aDirectStorage copy, so that allowance is load-bearing, and today nothing would notice if it were dropped — or, worse, if
it were moved to the reject side, the fixture would stay green while a valid title request started failing.
Adding one case is cheap:
VirtualAlloc(MEM_COMMIT, PAGE_READWRITE)thenVirtualProtect(..., PAGE_WRITECOPY), enqueuea small copy, expect success and the bytes present. If you want it in this PR I can push it as a second commit on a
branch of yours, or open it separately with
Refs #1672— your call, since it is your fixture.The two that do not need a test
cursor += 1is the same accept/reject decision, only oneVirtualQueryper byte instead of per region. On amulti-megabyte destination that is a real cost, but asserting call counts would be brittle; I would leave it.
info.State != MEM_COMMITis redundant with thePAGE_NOACCESScheck that follows: free and reserved ranges reportPAGE_NOACCESS. Keeping it is fine as defence in depth; I mention it so nobody reads its survival as a hole.Verdict
Reviewed
79899b7d. The refusal is correct, the counters behave as described, and the "nothing written before the badpage" property holds in the run. One gap worth closing: the copy-on-write destination is allowed but untested.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T16:57:21Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
79899b7ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T17:04:10Z.
Here is the copy-on-write case I mentioned, verified on your head
79899b7d. I did not push to your branch — apply it or tell me to open it separately withRefs #1672.The first thing I tried does not work and is worth knowing before anyone else tries it:
VirtualProtect(..., PAGE_WRITECOPY)fails on private committed memory, so a copy-on-write destination cannot be made that way. It needs a mapped view — a pagefile-backed section mappedFILE_MAP_COPY. That is why the case below creates a section instead of protecting the existing region.Verified both ways, rebuilding
startup_dstorage_destination_checkandXCRDAPI.dlleach time:The first line is the positive case; the second is the negative control that was missing before — without the new case, deleting
protect != PAGE_WRITECOPYleft the fixture green (that was the mutation in my earlier comment).Two details in case the mapping matters to you: the section is
pages * 0x1000bytes, which matches thebytesthe other cases use, and the copy view is unwritten before the request, somemcmpagainstsourceproves the copy wrote every byte rather than leaving zeros.MapViewOfFileneedsFILE_MAP_COPYrather thanFILE_MAP_WRITEfor the pages to come back asPAGE_WRITECOPYat all.If you would rather keep the case out of this PR, I will open it as its own with
Refs #1672— it is a test-only change either way.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:06:37Z.
Thanks @ChazY11 for the thorough review and mutation check.
Addressed in
1a4557cef4bc82d6f7bac4a63244d613ad56a576:PAGE_WRITECOPY) destination case totests/startup_dstorage_destination_check.cpp(and updateddocs/startup-runtime.md). It creates a pagefile-backedCreateFileMappingAsection mapped withFILE_MAP_COPY, verifies viaVirtualQuerythat the view starts asPAGE_WRITECOPY, enqueues a copy across the full mapping, and checks that it succeeds and every byte matches. (A mapped view is used because Windows rejectsVirtualProtect(..., PAGE_WRITECOPY)on privateVirtualAllocpages.)info.State != MEM_COMMITas defense in depth (sinceMEMORY_BASIC_INFORMATION::Protectis only defined for committed pages), as you noted.Verification (
1a4557cef4bc82d6f7bac4a63244d613ad56a576)Linux:
git diff --check: cleanpython3 tests/docs_links_check.py: self-test passed, 16 Markdown files and 351 linkspython3 tests/bidi_controls_check.py: self-test passed, 1278 tracked files, no bidirectional controlsx86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only tests/startup_dstorage_destination_check.cpp: cleanWindows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
--preset dev):cmake --build --preset dev --target d3d12_xs_shim startup_dstorage_destination_check startup_storage_alloc_failure startup_stub_acphal startup_stub_chad startup_stub_consumer startup_stub_gameinput startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs xmem_shim -- -j 6: passed (3.52s)ctest --preset dev -R '^(startup_dstorage_destination|startup_heartbeat_commit|startup_storage_alloc_failure|startup_stubs)$' --parallel 4 --no-tests=error --output-on-failure: 4/4 passed (30.27s:startup_storage_alloc_failure0.07s,startup_dstorage_destination0.09s,startup_stubs0.55s,startup_heartbeat_commit30.20s)/O2(--preset release):cmake --build --preset release --target d3d12_xs_shim startup_dstorage_destination_check startup_storage_alloc_failure startup_stub_acphal startup_stub_chad startup_stub_consumer startup_stub_gameinput startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs xmem_shim -- -j 6: passed (1.08s)ctest --preset release -R '^(startup_dstorage_destination|startup_heartbeat_commit|startup_storage_alloc_failure|startup_stubs)$' --parallel 4 --no-tests=error --output-on-failure: 4/4 passed (30.26s:startup_dstorage_destination0.09s,startup_storage_alloc_failure0.09s,startup_stubs0.46s,startup_heartbeat_commit30.19s)AI-assisted; commands listed were executed locally.