runtime: validate chad permissive out-handle and add lifecycle checks #1864
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1871"
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 Ammmae0x on 2026-11-24T19:52:06Z.
Change
Validate the
handleoutput pointer inXDspConnectWithMaximumStreamLimitinsidesrc/startup_stubs/chad.cppwhenX2W_AUDIO_PERMISSIVE=1is set, and addtests/startup_chad_check.cpp(startup_chad_checkinCMakeLists.txt).handleis null or failsx2w_local::writable(handle, sizeof(void*)),XDspConnectWithMaximumStreamLimitlogs the refusal and returnsE_POINTER(0x80004003) instead of skipping the write and returningS_OK.x2w_trap::firebefore checkinghandle.tests/startup_chad_check.cppverifies:nullptr,PAGE_READONLY, and RW->RO page-boundary straddlingvoid**) returnE_POINTER.XDspActivate,XDspConnectWithMaximumStreamLimit,XDspSubmitCommand,XDspDeactivate,XDspDisconnect) returnsS_OK, populates the handle, and emits zerox2w-traplog lines.0xE2570200..0xE2570204exit codes across all five exports.Verification
Commit
4e6f2c81(rebased ontoupstream/mainat7c96def1), Windows x64 (devDebug andrelease/O2):cmake --preset dev&cmake --preset release-> configured cleanly (Total Tests: 1137).cmake --build --preset dev --target startup_stub_chad startup_chad_check startup_stub_consumer-> 0 errors, 0 warnings.cmake --build --preset release --target startup_stub_chad startup_chad_check startup_stub_consumer-> 0 errors, 0 warnings.ctest --preset dev --output-on-failure -R "^(startup_chad_check|startup_stubs)$" -E "cpu_native_archive_"-> 2/2 passed (startup_chad_check,startup_stubs).ctest --preset release --output-on-failure -R "^(startup_chad_check|startup_stubs)$" -E "cpu_native_archive_"-> 2/2 passed (startup_chad_check,startup_stubs).python -B tests/form_coverage_check.py-> passed.python -B tests/docs_links_check.py-> passed (18 Markdown files, 370 links).python -B tests/bidi_controls_check.py-> passed (1325 tracked files, no bidirectional controls).Evidence and follow-up
tests/startup_chad_check.cppis a source-built fixture (MIT) loading the builtchad.dlldirectly with no external assets.XDspConnectWithMaximumStreamLimitstill populates a static placeholder connection pointer underX2W_AUDIO_PERMISSIVE=1; full DSP stream semantics remain unimplemented until public ABI evidence exists.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:55:03Z.
Review: COMMENTED
Review of head
4e6f2c81086b22383fe19e2eed17b06bf2eb7c95(baseorigin/mainatdd753176when I fetched). Comment only, not an approval.Verdict: 0 P1 / 1 P2 (test strength) / a few P3. The production change looks correct. One of the new test assertions cannot fail, so it does not guard what it claims to.
Linux limits. This change is Windows-only C++ (
windows.h,VirtualAlloc, SEH,CreateProcess). On Linux I could not compile or runstartup_chad_check,startup_stubsor any mutation of the C++. Everything below about the code is from reading it; the author's Windows results (dev and release, 2/2 each) are theirs and not reproduced by me. What I did run:tests/docs_links_check.py(18 files, 370 links),tests/bidi_controls_check.py(1325 files) andgit diff --check origin/main...HEAD, all clean.Production change (
src/startup_stubs/chad.cpp)accept()runs first, so in non-permissive modex2w_trap::firestill terminates the process beforehandleis touched; in permissive mode the handle is validated before the write.!handle || !x2w_local::writable(handle, sizeof(void*))is the right guard.accessible()rejects addresses below 0x10000, a non-committed or guard page, a non-writable protection, and a range that crosses the end of the queried region. So the RW->RO straddle control (8 bytes starting 4 bytes before a read-only page) is refused by thebytes > end - starttest, as the author intends.E_POINTERis0x80004003, cast tolong(32-bit on Windows). The failure path logs throughx2w_local::logfand returns before any write. The success path is unchanged except that the%llx/%lluarguments are now cast tounsigned long long, which fixes the old mismatch withu64.E_POINTER. Onlytests/startup_chad_check.cpp,chad.defand docs reference the export in this tree, so I found no in-tree caller that breaks.Findings
tests/startup_chad_check.cppassertslog_text.find("x2w-trap") == std::string::nposfor the permissive lifecycle. In permissive modeaccept()records with the tag"x2w-audio", and the only code that writes"x2w-trap"isx2w_trap::fire, which terminates the process. So the assertion is true even if the log is empty, unreachable or never written, and a regression would end the test process rather than reach this line. As written it cannot fail for a logging or lifecycle regression. Suggest asserting something that can fail: that the log contains the expectedx2w-audio XDspConnectWithMaximumStreamLimit ... -> 0line for the success call, and the-> E_POINTERline for the refusals. That would also pin the new log message, which nothing asserts today.if (handle && writable(...)) *handle = &connection;and confirm the three negative controls fail. Please list that mutation and its result in the PR.chad.cppstill says the export returns 0 on success and "the others ... succeed (0)"; it does not mention the newE_POINTERfor a bad out-handle.nullandvalidchild cases forXDspConnectWithMaximumStreamLimitboth trap beforehandleis read, so they check the same thing twice. Harmless.VirtualProtectand aPAGE_READONLYallocation; both are checked for failure and report a FAIL instead of passing silently, which is good.Clean-room: the new test is a source-built fixture loading the built stub DLL, with no game files or dumps. The only vendor-style names are the export names already in
chad.def.Not run here: any compile,
ctest, or mutation of the C++.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:07:09Z.
Review: COMMENTED
Re-review of head
60ee4c20a559814f029cb18deb3cbae0ac4fa017(tests: assert permissive chad log entries and clarify header comment, on top of4e6f2c81), checked out at exactly that SHA. Verdict: 0 P1, 0 P2. My earlier P2 is closed; remaining notes are P3. I could not compile or run this change (Windows-only C++:windows.h,VirtualAlloc,VirtualProtect, SEH,CreateProcess).Earlier findings
XDspConnectWithMaximumStreamLimit memory=0x1000 ... handle_out=...line ending-> 0and exactly three ending-> E_POINTER, plus theXDspActivate,XDspSubmitCommand,XDspDeactivateandXDspDisconnectentries. To check that the counting loop discriminates, I copied it verbatim into a small program and fed it synthetic logs:So an empty or unreachable log, and a regression to the old "-> 0 on refusal" behaviour, now fail the test. This reproduces the parsing logic only, not the chad stub itself.
return hr_pointer;toreturn result;and getting 3 failing negative controls. That is consistent with the code (the three controls compare the return value withhr_pointer), but I did not reproduce it.chad.cppnow saysE_POINTER when handle is null or unwritable.Production change, re-read at this head
accept()still runs first, so in non-permissive mode the trap fires beforehandleis read. In permissive mode a null or unwritablehandlelogs the full argument line with-> E_POINTERand returnshr_pointerbefore any write; otherwise*handle = &connectionand the-> 0line is logged. The log arguments are now cast tounsigned long long, matching%llx/%llu.0x80004003tolongis the usual 32-bitE_POINTER. Clean-room and title-neutral: a source-built fixture loads the built stub; no title is named.Commands run (Linux)
P3
log_text.find("x2w-trap") == nposis still there; it passes on an empty log, so it adds nothing next to the new ones (harmless).E_POINTER; no caller in the tree is affected, but a sentence in the PR description would record the change.nullandvalidchild cases both trap beforehandleis read, so they check the same thing twice.Limits
Not built and not run on Windows. Please run
ctest -R startup_chad_check(dev and release) or rely on the Windows CI job; my verdict rests on reading the code and on the log-parsing reproduction above.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-24T20:03:19Z.
Updated
tests/startup_chad_check.cppto assert the positive-> 0log entry, all three-> E_POINTERrefusal log entries, and the permissive lifecycle export entries, and updated the header comment insrc/startup_stubs/chad.cpp. Mutation check revertingreturn hr_pointer;toreturn result;failed all 3 negative controls (startup_chad_check: 3 failure(s)). Re-verifiedstartup_chad_checkindevandrelease, plusdocs_links_check.py,bidi_controls_check.py, andform_coverage_check.py. AI-assisted.upstream-sync referenced this pull request2026-11-25 02:01:52 +00:00