cpu: start the load-config /guard:cf fixtures with an explicit CFG policy #1360
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1367"
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 Maxim-Root on 2026-11-24T09:25:47Z.
Change
cpu_native_load_config_callbackfailed on every run on a host where system CFG is off. The check asserts that Windows replaces both guard slots of a/guard:cfimage. That holds only when CFG is enforced for the process. A child inherits the host's CFG setting, so with system CFG off the loader keeps the image's own slots.cfg_recordthen behaved likerecord(exit0x55, no slot bits) and the check stopped before reaching thepe_mapside. Hosted CI uses the Windows default (CFG on), which is why it stayed green.This PR starts the two
/guard:cfimages (cfg_record,cfg_invalid) with an explicit per-processPROC_THREAD_ATTRIBUTE_MITIGATION_POLICYinstead of the host default:0x30055), and the invalid target ends before writing output (0xC0000409).cfg_recordmust equalrecordandcfg_invalidmust equalinvalid. This shows that the policy, and nothing else, changes the result.EnableControlFlowGuardbit is read from its handle and must match the requested policy. A launcher that silently ignores the policy is reported by name and does not turn into a pass.The non-CFG variants, the
pe_mapside and every existing expected value are unchanged. Onlytests/cpu/load_config_callback_check.pychanges. No system setting is read or modified.Fixes #1366
Verification
At
f2082414(on top of4b166b7d),devpreset (Debug), Windows 11 Pro 26300.9818 with system CFG off (Get-ProcessMitigation -System), MSVC 14.44.35207, Python 3.12.10:Before this change, the same command at
c4966c64failed withAssertionError: cfg_record: Windows (85, (...)), expected both slots replaced and 0x55.ctest ... -R '^cpu_native_load_config_callback$' --repeat until-fail:10: 10/10 passed.ctest --preset pr --no-tests=error -j 16withX2W_REQUIRE_SPIRV_TOOLS=1: 24/24 passed.ctest --preset dev --no-tests=error -E '_hardware$' -j 16(same change onc4966c64, before the rebase): 587/589 passed. The two failures,cpu_native_worker_aliveandcpu_native_package_ordinal_startup, are 30 s timeouts under-j 16load. They also occur atc4966c64without this change when this test is excluded, and both pass when run alone. I will report them separately.cfg_record: requested CFG on, but the child reports EnableControlFlowGuard=0;CreateProcessWfails with error 87 and the check fails.Not run here: a host with system CFG on. The always-on branch gives the same result the hosted runner already measured. The always-off control on a CFG-on host is exercised by the
Build and test on Windowsjob.Evidence and follow-up
No new fixture binaries: the existing source-built
cpu_load_callback_*images are used. Related: #1293 hits the opposite host condition (system CFG on) in the archive tests. A per-process policy like this one could give that check a deterministic positive and negative run as well.Checklist
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:42:18Z.
Review: COMMENTED
Technical peer-review of commit
f2082414689a5d9413fa912899d5f71bc212cf53:Verification
git diff --check origin/main...HEAD: clean.tests/docs_links_check.py: passed (16 Markdown files, 302 links).tests/bidi_controls_check.py: passed (1,146 files).python -B -m py_compile tests/cpu/load_config_callback_check.py: passed.--preset dev): targets built (0.08s);ctest -R '^cpu_native_load_config_callback$'1/1 passed (1.16s)./O2(--preset release): targets built (2.68s);ctest -R '^cpu_native_load_config_callback$'1/1 passed (1.05s).Findings (
tests/cpu/load_config_callback_check.py)PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY(0x20007),PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_ON(1 << 40) /_ALWAYS_OFF(2 << 40),StartupInfoExx64 layout,GetProcessMitigationPolicy(..., ProcessControlFlowGuardPolicy=7, ...)bit-0 verification, handle/attribute-list cleanup, and the CFG-off negative control (uncontrolled == expected[base]) are all sound.Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-24T09:38:52Z.
Read through
f2082414. The launcher looks correct to me and no existing assertion is weakened. One gap in the evidence, then some small things. I could not run it (no Windows host here), so this is from the code and the workflow only.The CFG-on host path has not run in CI. The description says the always-off control on a CFG-on host "is exercised by the
Build and test on Windowsjob". On a pull request that job runsctest --preset pr(.github/workflows/windows.yml), and theprpreset's include filter inCMakePresets.jsondoes not matchcpu_native_load_config_callback. So the green check on this PR did not execute the changed test, and the only measurement is the CFG-off host in the description. Two things are therefore unmeasured on a CFG-on host:ALWAYS_OFFoverrides a system-on default for these images (the control), andGetProcessMitigationPolicysucceeds on the handle of a process that has already exited on the hosted image. It worked on build 26300; the documentation only states the access right.If either differs, the first run to show it would be the
devpreset onmainafter the merge. Aworkflow_dispatchrun of the workflow on this branch, or a local run on a host with system CFG on, would close it.Smaller points, none blocking:
CreateProcessWis called withbInheritHandles=Trueand noPROC_THREAD_ATTRIBUTE_HANDLE_LIST, so the child inherits every inheritable handle of the test process, not only the three opened for it. The attribute list would need a count of 2.TIMEOUT, so with a hung child ctest can end the test before its own "did not end" message prints. The sharedlaunch()also records thread state on a timeout, which this path skips.CreateFileWcalls fails, the error is read after all three, so a later successful call can replace it; the raisedWinErrormay then name the wrong cause.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:03:58Z.
Review: COMMENTED
Technical peer-review (retest) of commit
818181369f3e59f8ab1d7fd2a1453dec0f604e1a:Verification
git diff --check origin/main...HEAD: clean.tests/docs_links_check.py: passed (16 Markdown files, 302 links).tests/bidi_controls_check.py: passed (1,146 files).python -B -m py_compile tests/cpu/load_config_callback_check.py: passed.--preset dev): targets built (0.08s, configure1.72s);ctest -R '^cpu_native_load_config_callback$'1/1 passed (1.02s)./O2(--preset release): targets built (0.08s, configure1.59s);ctest -R '^cpu_native_load_config_callback$'1/1 passed (0.96s).Findings (
tests/cpu/load_config_callback_check.py)81818136cleanly addresses the handle-inheritance and error-capture follow-ups:PROC_THREAD_ATTRIBUTE_HANDLE_LIST(0x20002) restricts inherited handles tostdin/stdout/stderr.CreateFileWerrors are captured immediately before closing previously opened handles.timeout=15keeps all four policy launches well within the 120s CTest timeout and recordsthread_ids(process.pid)before terminating on a hang.Imported from R0Y00/Xbox2Windows. Originally posted by Maxim-Root on 2026-11-24T10:22:47Z.
@JohnConnorNPC thanks, you were right about the CI claim. The
prpreset does not includecpu_native_load_config_callback, so the green check never ran it. I have corrected that point below and measured both unmeasured items on a host where CFG is on by default.CFG-on host run. I could not get a full
workflow_dispatchrun ofwindows.ymlin my fork to finish: both the Debug and/O2jobs hit the 20-minutetimeout-minutes(the fork-runner limit also mentioned in #1173). Instead I ran a fork-only probe workflow on the hostedwindows-2025image. It records the runner's system CFG setting, builds only the load-config targets at this PR's head81818136, and runs the test three times. The probe is not part of this PR: run 45373932340, workflow file.This covers both points:
ALWAYS_OFFoverrides a system-on default for these images. The CFG-off control gives0x55and0x77on the hosted image, exactly as on my CFG-off host.GetProcessMitigationPolicyon an exited child's handle succeeds on build 26100. Otherwiselaunch_cfgwould have raised before the comparison. It also works on 26300.Together with my CFG-off host (26300) and @tedin7's Windows Server 2025 runs, the check has now passed on both host settings in Debug, and in
/O2on 26100.The three smaller points are addressed in
81818136, which @tedin7 re-reviewed:PROC_THREAD_ATTRIBUTE_HANDLE_LISTwith an attribute count of 2.launch_cfgwaits 15 s per launch, so the four launches take at most 60 s within the 120 s CTest timeout. A launch that does not end recordsthread_ids(pid)before it is terminated. I checked this path locally against a deliberately lingering EXE:signaled=False, one live thread recorded, terminated after 1.0 s.CreateFileWerror is read immediately after the failing call and names the file.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:16:28Z.
Review: COMMENTED
Verification review for commit
818181369f3e59f8ab1d7fd2a1453dec0f604e1a:Scope & Audit
tests/cpu/load_config_callback_check.py, +138/-10): launches/guard:cffixtures with explicitPROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_ON(1 << 40) and_ALWAYS_OFF(2 << 40) viaPROC_THREAD_ATTRIBUTE_MITIGATION_POLICY(0x20007), restricts handle inheritance viaPROC_THREAD_ATTRIBUTE_HANDLE_LIST(0x20002), verifies each child's effectiveEnableControlFlowGuardbit viaGetProcessMitigationPolicy(..., 7, ...), and asserts the CFG-off negative control matches the non-/guard:cfbaseline.TemporaryDirectory, clean-room/title-neutral.Checks Executed
git diff --check origin/main...HEAD: clean.python3 -I tests/docs_links_check.py: passed (16 Markdown files, 302 links).python3 -I tests/bidi_controls_check.py: passed (1,146 files, no bidirectional controls).python3 -B -m py_compile tests/cpu/load_config_callback_check.py: passed.--preset dev): targets built (0.08s, configure1.72s);ctest --preset dev -R '^cpu_native_load_config_callback$' --no-tests=error: 1/1 passed (1.02s)./O2(--preset release): targets built (0.08s, configure1.59s);ctest --preset release -R '^cpu_native_load_config_callback$' --no-tests=error: 1/1 passed (0.96s).--patch, cache bypassed, repo restored after each run):CFG_POLICY"on"/"off"(2 << 40/1 << 40):cpu_native_load_config_callbackfailed (AssertionError: cfg_record: requested CFG on, but the child reports EnableControlFlowGuard=0).CFG_POLICY["off"] = 0(defer to host default):cpu_native_load_config_callbackfailed (AssertionError: cfg_record: requested CFG off, but the child reports EnableControlFlowGuard=1), confirmingALWAYS_OFFoverrides the CFG-on host default.Verdict: 0 P1, 0 P2. Clean Tier B merge candidate.
AI-assisted; commands listed were executed locally.