Repository navigation
startup: refuse a storage request with a non-writable destination - #1672
Conversation
The guard works; one allowed protection is never exercised, and one check is redundantReviewed Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100. cmake --preset dev
ctest --preset dev --no-tests=error -R '^startup_dstorage_' -VMutations
The one that matters
Adding one case is cheap: The two that do not need a test
VerdictReviewed |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour 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. |
|
Here is the copy-on-write case I mentioned, verified on your head The first thing I tried does not work and is worth knowing before anyone else tries it: @@ -139,6 +139,25 @@ int main(int argc, char** argv)
else std::printf("ok: writable control after the refusals wrote every byte\n");
VirtualFree(region, 0, MEM_RELEASE);
+ // A copy-on-write page fault is not a write to the section, so the whitelist has to keep
+ // PAGE_WRITECOPY/PAGE_EXECUTE_WRITECOPY. Windows refuses PAGE_WRITECOPY on private memory,
+ // so the case needs a mapped view: a pagefile-backed section mapped FILE_MAP_COPY.
+ {
+ HANDLE section = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_WRITECOPY, 0,
+ static_cast<DWORD>(bytes), nullptr);
+ auto* cow = section ? static_cast<unsigned char*>(MapViewOfFile(section, FILE_MAP_COPY, 0, 0, bytes)) : nullptr;
+ if (!cow) fail("copy-on-write destination", "could not map a copy view");
+ else {
+ const long cow_hr = run_request(cow, bytes, bytes);
+ if (cow_hr == -1) fail("copy-on-write destination", "no completion");
+ else if (cow_hr != 0) fail("copy-on-write destination", "request failed");
+ else if (std::memcmp(cow, source, bytes) != 0) fail("copy-on-write destination", "bytes differ");
+ else std::printf("ok: copy-on-write destination accepted and written\n");
+ UnmapViewOfFile(cow);
+ }
+ if (section) CloseHandle(section);
+ }
+
if (failures) return 1;
std::printf("dstorage destination: refused without writes, queue kept working\n");
return 0;Verified both ways, rebuilding The first line is the positive case; the second is the negative control that was missing before — without the new case, deleting Two details in case the mapping matters to you: the section is If you would rather keep the case out of this PR, I will open it as its own with |
|
Thanks @ChazY11 for the thorough review and mutation check. Addressed in
Verification (
|
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 startup: decode BC3, BC4, and BC5 BCPack DirectStorage streams #1390, startup: support interleaved chunked streams in DirectStorage #1429 and runtime: experiment with metadata-backed compressed chunk windows #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.