pe_map: longjmp out of a mapped image fails fast (FAST_FAIL_INVALID_LONGJUMP_TARGET) when system CFG is on #1286

Open
opened 2026-11-24 07:00:41 +00:00 by archielcqp-a11y · 11 comments
archielcqp-a11y commented 2026-11-24 07:00:41 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by archielcqp-a11y on 2026-11-24T07:00:41Z.


Commit or build

f05369e (main); dev preset with OFFSCREEN_AGILITY_620_DIR and OFFSCREEN_WARP_DIR (the three tests do not depend on them)

Reproduction

# Windows 10 22H2: Windows Security > App & browser control > Exploit protection > System settings
# > "Control flow guard (CFG)" = "On by default" (the Windows default), then restart.
ctest --preset dev --no-tests=error -R '^(cpu_native_archive_blast|cpu_archive_texture_publication|cpu_archive_texture_gpu_warp)$' --output-on-failure

Expected behavior

The pe_map run of the "truncated" case matches the native and AOT runs: exit 2 and the trace alloc 8 / input 4 / input 0 / output 1 / free / completed 1.

Observed behavior

All three tests fail in the pe_map run of the truncated case. The mapped child stops after input 0 with exit 0xC0000409 (3221226505):

AssertionError: pe_map truncated status/trace: expected (2, b'alloc 8
input 8
output 13
free
alloc 8
input 4
input 0
output 1
free
completed 1
'), got (3221226505, b'alloc 8
input 8
output 13
free
alloc 8
input 4
i...

Under cdb -o (following the Python child):

Security check failure or stack buffer overrun - code c0000409 (!!! second chance !!!)
Subcode: 0x26 FAST_FAIL_INVALID_LONGJUMP_TARGET
ntdll!RtlFailFast2:
    int 29h

The native reader and the AOT EXE pass the same case; the "both", "first", "stale", "fail" and "leak" cases pass in all three runners, and cpu_native_archive_reader (no blast) passes. With system CFG set to Off (same build, after a restart) all three tests pass.

What the evidence points to

  • tests/cpu/archive/blast/blast.c leaves decomp through longjmp(s->env, 1) when the input runs out (lines 81 and 165; setjmp at line 408). Only the truncated case reaches that path.
  • tools/pe_map.cpp maps the image into private memory (VirtualAlloc(nullptr, SizeOfImage, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE), line 1084) and registers unwind data with RtlAddFunctionTable (line 1348), so the mapped blast code is not MEM_IMAGE and not in the loader's module list.
  • With CFG enabled system-wide, the x64 longjmp unwind validates its target; a target inside private memory is rejected with subcode 0x26. Native and AOT runs load blast as a real image, so their target is accepted.
  • None of the binaries involved are /guard:cf (blast_source.dll, archive_codec.dll, archive_texture_reader.exe), and neither the Python 3.12 nor the 3.14 python.exe sets GUARD_CF, so the check follows the system CFG policy rather than a CFG-built host.

Hypothesis, not tested: hosted CI passes on windows-2025, where CFG is also on by default, so newer Windows builds may validate longjmp targets in private memory differently. A Windows 11 run with CFG on would separate the two.

Possible directions, for discussion: map the image as an image section so it is MEM_IMAGE, or record this as a known pe_map boundary and report the case as a named skip when the longjmp target check is enforced.

This report was prepared with AI assistance.

Environment

Windows 10 22H2 build 19045.6466; Exploit protection system settings CFG On, bottom-up ASLR On, high-entropy ASLR On (defaults); MSVC 19.44.35230, Windows SDK 10.0.26100, CMake/Ninja from VS 2022 Build Tools; Python 3.14.3; cdb from Windows Kits 10. The three tests use no GPU-specific path for the failing case (archive_texture_gpu_warp also fails there on WARP 1.0.22).

Checklist

  • I reproduced this on a source-built input.
  • I did not include game files, dumps, distribution links or credentials.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6576465528 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293). Originally posted by [archielcqp-a11y](https://github.com/archielcqp-a11y) on 2026-11-24T07:00:41Z. --- ### Commit or build f05369e (main); dev preset with OFFSCREEN_AGILITY_620_DIR and OFFSCREEN_WARP_DIR (the three tests do not depend on them) ### Reproduction ```shell # Windows 10 22H2: Windows Security > App & browser control > Exploit protection > System settings # > "Control flow guard (CFG)" = "On by default" (the Windows default), then restart. ctest --preset dev --no-tests=error -R '^(cpu_native_archive_blast|cpu_archive_texture_publication|cpu_archive_texture_gpu_warp)$' --output-on-failure ``` ### Expected behavior The `pe_map` run of the "truncated" case matches the native and AOT runs: exit 2 and the trace `alloc 8 / input 4 / input 0 / output 1 / free / completed 1`. ### Observed behavior All three tests fail in the `pe_map` run of the truncated case. The mapped child stops after `input 0` with exit `0xC0000409` (3221226505): ```text AssertionError: pe_map truncated status/trace: expected (2, b'alloc 8 input 8 output 13 free alloc 8 input 4 input 0 output 1 free completed 1 '), got (3221226505, b'alloc 8 input 8 output 13 free alloc 8 input 4 i... ``` Under `cdb -o` (following the Python child): ```text Security check failure or stack buffer overrun - code c0000409 (!!! second chance !!!) Subcode: 0x26 FAST_FAIL_INVALID_LONGJUMP_TARGET ntdll!RtlFailFast2: int 29h ``` The native reader and the AOT EXE pass the same case; the "both", "first", "stale", "fail" and "leak" cases pass in all three runners, and `cpu_native_archive_reader` (no blast) passes. With system CFG set to Off (same build, after a restart) all three tests pass. **What the evidence points to** - `tests/cpu/archive/blast/blast.c` leaves `decomp` through `longjmp(s->env, 1)` when the input runs out (lines 81 and 165; `setjmp` at line 408). Only the truncated case reaches that path. - `tools/pe_map.cpp` maps the image into private memory (`VirtualAlloc(nullptr, SizeOfImage, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)`, line 1084) and registers unwind data with `RtlAddFunctionTable` (line 1348), so the mapped blast code is not `MEM_IMAGE` and not in the loader's module list. - With CFG enabled system-wide, the x64 `longjmp` unwind validates its target; a target inside private memory is rejected with subcode 0x26. Native and AOT runs load blast as a real image, so their target is accepted. - None of the binaries involved are `/guard:cf` (`blast_source.dll`, `archive_codec.dll`, `archive_texture_reader.exe`), and neither the Python 3.12 nor the 3.14 `python.exe` sets `GUARD_CF`, so the check follows the system CFG policy rather than a CFG-built host. Hypothesis, not tested: hosted CI passes on `windows-2025`, where CFG is also on by default, so newer Windows builds may validate longjmp targets in private memory differently. A Windows 11 run with CFG on would separate the two. Possible directions, for discussion: map the image as an image section so it is `MEM_IMAGE`, or record this as a known `pe_map` boundary and report the case as a named skip when the longjmp target check is enforced. This report was prepared with AI assistance. ### Environment Windows 10 22H2 build 19045.6466; Exploit protection system settings CFG On, bottom-up ASLR On, high-entropy ASLR On (defaults); MSVC 19.44.35230, Windows SDK 10.0.26100, CMake/Ninja from VS 2022 Build Tools; Python 3.14.3; cdb from Windows Kits 10. The three tests use no GPU-specific path for the failing case (archive_texture_gpu_warp also fails there on WARP 1.0.22). ### Checklist - [x] I reproduced this on a source-built input. - [x] I did not include game files, dumps, distribution links or credentials.
legacy-code-archaeologist commented 2026-11-24 09:04:44 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T08:15:50Z.


Windows 11 data point for the hypothesis. It does not separate the two: Windows 11 rejects the target too.

Setup: Windows 11 Pro 26100.9168, MSVC 19.52, Python 3.12, dev preset at e3193607. The system CFG setting on this machine is Off (Get-ProcessMitigation -System). I did not change it. Instead, I forced CFG on for the one mapped child process: CreateProcessW with PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY = PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_ON (1 << 40), with ALWAYS_OFF (2 << 40) as the control.

Command: the mapped run of the truncated case: python -B tests/cpu/archive_check.py --mapped pe_map.dll archive_reader.exe archive_codec.dll blast_source.dll, with FIRST_RECORD + SECOND_RECORD[:5] on stdin.

Child CFG policy Exit Trace ends with
always off 2 output 1 / free / completed 1 (expected)
always on 0xC0000409 alloc 8 / input 4 / input 0

This matches your Windows 10 result. Your run is under the system setting; mine is a per-process opt-in. On 26100, a longjmp target in pe_map's private mapping is rejected once CFG is enforced for the process. It does not depend on the Windows 10 build.

I could not read the fail-fast subcode: no cdb on this machine. That it is 0x26 here as well is an assumption.

One trap for anyone repeating this: the policy has to go on the base interpreter (sys._base_executable, with the venv's site-packages on PYTHONPATH). out/pe-env/Scripts/python.exe is a venv redirector that starts a second process, and the policy is not passed on. Through the redirector the case passes even with "always on".

Not tested: why the hosted windows-2025 runner passes. Its effective CFG policy for the Python child is unknown to me.

A detection for a named skip seems easy to add: the child can read GetProcessMitigationPolicy(ProcessControlFlowGuardPolicy) → EnableControlFlowGuard before the truncated case. The per-process launcher above would then give CI a deterministic positive and negative run of that skip, without touching system settings. I can take either that or a first look at mapping the image as MEM_IMAGE, whichever you prefer.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7125922918 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7125922918). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T08:15:50Z. --- Windows 11 data point for the hypothesis. It does not separate the two: Windows 11 rejects the target too. **Setup:** Windows 11 Pro 26100.9168, MSVC 19.52, Python 3.12, `dev` preset at e3193607. The system CFG setting on this machine is Off (`Get-ProcessMitigation -System`). I did not change it. Instead, I forced CFG on for the one mapped child process: `CreateProcessW` with `PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY` = `PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_ON` (`1 << 40`), with `ALWAYS_OFF` (`2 << 40`) as the control. **Command:** the mapped run of the truncated case: `python -B tests/cpu/archive_check.py --mapped pe_map.dll archive_reader.exe archive_codec.dll blast_source.dll`, with `FIRST_RECORD + SECOND_RECORD[:5]` on stdin. | Child CFG policy | Exit | Trace ends with | |---|---|---| | always off | 2 | `output 1 / free / completed 1` (expected) | | always on | `0xC0000409` | `alloc 8 / input 4 / input 0` | This matches your Windows 10 result. Your run is under the system setting; mine is a per-process opt-in. On 26100, a longjmp target in `pe_map`'s private mapping is rejected once CFG is enforced for the process. It does not depend on the Windows 10 build. I could not read the fail-fast subcode: no cdb on this machine. That it is 0x26 here as well is an assumption. **One trap for anyone repeating this:** the policy has to go on the base interpreter (`sys._base_executable`, with the venv's `site-packages` on `PYTHONPATH`). `out/pe-env/Scripts/python.exe` is a venv redirector that starts a second process, and the policy is not passed on. Through the redirector the case passes even with "always on". **Not tested:** why the hosted `windows-2025` runner passes. Its effective CFG policy for the Python child is unknown to me. A detection for a named skip seems easy to add: the child can read `GetProcessMitigationPolicy(ProcessControlFlowGuardPolicy)` → `EnableControlFlowGuard` before the truncated case. The per-process launcher above would then give CI a deterministic positive and negative run of that skip, without touching system settings. I can take either that or a first look at mapping the image as `MEM_IMAGE`, whichever you prefer.
MasterDomino commented 2026-11-24 11:02:59 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T10:22:26Z.


@legacy-code-archaeologist, are you already working on either option from your comment? If not, I'd like to take the root-cause side: make a longjmp out of a pe_map-mapped image pass the CFG long-jump target check (for example by registering the image's GuardLongJumpTargetTable targets, or by mapping it as MEM_IMAGE, whichever turns out to be the supported route), with your per-process ALWAYS_ON/ALWAYS_OFF launcher as the positive and negative control. The skip detection would stay yours if you want it. @R0Y00, happy to follow whichever split you prefer; I'll only reproduce locally until one of you answers.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7128688262 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7128688262). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T10:22:26Z. --- @legacy-code-archaeologist, are you already working on either option from your comment? If not, I'd like to take the root-cause side: make a `longjmp` out of a `pe_map`-mapped image pass the CFG long-jump target check (for example by registering the image's `GuardLongJumpTargetTable` targets, or by mapping it as `MEM_IMAGE`, whichever turns out to be the supported route), with your per-process `ALWAYS_ON`/`ALWAYS_OFF` launcher as the positive and negative control. The skip detection would stay yours if you want it. @R0Y00, happy to follow whichever split you prefer; I'll only reproduce locally until one of you answers. AI-assisted.
MasterDomino commented 2026-11-24 11:03:00 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T10:28:00Z.


Root cause, measured on this machine. No code change yet. The fix options at the end need your call.

Setup

  • Windows 11 26H2 (build 26300.9974), ntdll.dll 10.0.26100.9974. System CFG setting NOTSET.
  • dev build at b9c9f624.
  • I used the per-process launcher from @legacy-code-archaeologist's comment: CreateProcessW on the base interpreter with PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, and the venv site-packages on PYTHONPATH. It runs the mapped truncated case archive_check.py --mapped pe_map.dll archive_reader.exe archive_codec.dll blast_source.dll with FIRST_RECORD + SECOND_RECORD[:5] on stdin.
child CFG policy exit trace ends with
default 2 output 1 / free / completed 1
ALWAYS_OFF 2 output 1 / free / completed 1
ALWAYS_ON 0xC0000409 alloc 8 / input 4 / input 0

Where it fails

The longjmp is in blast.c (blast_source.dll, mapped by pe_map like the reader). Its CRT longjmp goes through RtlUnwindEx, which calls the exported RtlGuardCheckLongJumpTarget. Reading that function in this ntdll build:

  1. If CFG is not enforced, the target is accepted. That matches the default and ALWAYS_OFF runs.
  2. Otherwise it looks up the image that contains the target in the loader's inverted function table (KiUserInvertedFunctionTable). If an image is found, it reads the image's load config. With no long-jump table present (GuardFlags & 0x10000), the target is accepted; otherwise the target is binary-searched in GuardLongJumpTargetTable. blast_source.dll has no CF instrumentation, which is why the native run passes under CFG.
  3. If no image is found, it looks up one entry in the process's protected-policy table, the store behind RtlSetProtectedPolicy / SetProtectedPolicy, under GUID {4f6ae3a6-8b1b-4623-a293-294cd743bbd1}. A non-zero value accepts the target. Otherwise it calls RtlFailFast(38): 0x26, FAST_FAIL_INVALID_LONGJUMP_TARGET.

pe_map maps into private memory and registers .pdata with RtlAddFunctionTable. That makes unwinding work, but it does not put the image into the inverted function table, so step 2 never finds it, and step 3 fails.

Confirmation: in the ALWAYS_ON child, calling SetProtectedPolicy(&{4f6ae3a6-…}, 1, &old) before mapping makes the truncated case pass. The call returns ok=1, old=0, the exit is 2 and the trace is the expected one. Without that call the same child fails with 0xC0000409. This was an experiment in a wrapper script only; nothing in the repository changed.

Options

  1. Opt into the policy in pe_map, or in the test child. This is the smallest change and it is measured to work. But that GUID is undocumented, Microsoft describes SetProtectedPolicy as "for use primarily by Windows, and not designed for external use", and the policy turns off long-jump target validation for every non-image address in the whole process, not just the mapped image. I would not do this by default. At most it would be an explicit opt-in for test runs.
  2. Leave CFG alone and give the tests a named skip when the child runs with CFG enforced. This is @legacy-code-archaeologist's detection idea: GetProcessMitigationPolicy(ProcessControlFlowGuardPolicy). It is honest about the limitation, but the mapped long-jump path then goes untested on CFG machines.
  3. Make the mapped image visible to step 2. The inverted function table is filled only by the loader (LoadLibrary), which pe_map deliberately avoids. Mapping with SEC_IMAGE alone would not register it either, as far as I can tell from step 2. I don't see a supported route here.
  4. Bind the mapped image's longjmp import to a pe_map replacement that restores the jmp_buf without RtlUnwindEx. This avoids the check, but it changes unwind semantics: no frame unwinding, so no C++ destructors. For C code like blast that is fine, but it would be wrong for a general image.

My suggestion: option 2 for the tests now, with option 1 only if you explicitly want the mapped long-jump path exercised under CFG and accept the process-wide relaxation in test runs. Which do you want? I can implement either. I'll leave the skip side to @legacy-code-archaeologist if they still want it.

Limits

  • One machine and one ntdll build. Older builds may differ in step 3.
  • I read the disassembly without symbols for the helper routines. The lookup and the policy test are inferred from the control flow, and the experiment above confirms only the end result.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7128818495 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7128818495). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T10:28:00Z. --- Root cause, measured on this machine. No code change yet. The fix options at the end need your call. ## Setup - Windows 11 26H2 (build 26300.9974), `ntdll.dll` 10.0.26100.9974. System CFG setting `NOTSET`. - `dev` build at `b9c9f624`. - I used the per-process launcher from @legacy-code-archaeologist's comment: `CreateProcessW` on the base interpreter with `PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY`, and the venv `site-packages` on `PYTHONPATH`. It runs the mapped truncated case `archive_check.py --mapped pe_map.dll archive_reader.exe archive_codec.dll blast_source.dll` with `FIRST_RECORD + SECOND_RECORD[:5]` on stdin. | child CFG policy | exit | trace ends with | |---|---|---| | default | 2 | `output 1 / free / completed 1` | | `ALWAYS_OFF` | 2 | `output 1 / free / completed 1` | | `ALWAYS_ON` | `0xC0000409` | `alloc 8 / input 4 / input 0` | ## Where it fails The `longjmp` is in `blast.c` (`blast_source.dll`, mapped by `pe_map` like the reader). Its CRT `longjmp` goes through `RtlUnwindEx`, which calls the exported `RtlGuardCheckLongJumpTarget`. Reading that function in this `ntdll` build: 1. If CFG is not enforced, the target is accepted. That matches the default and `ALWAYS_OFF` runs. 2. Otherwise it looks up the image that contains the target in the loader's inverted function table (`KiUserInvertedFunctionTable`). If an image is found, it reads the image's load config. With no long-jump table present (`GuardFlags & 0x10000`), the target is accepted; otherwise the target is binary-searched in `GuardLongJumpTargetTable`. `blast_source.dll` has no CF instrumentation, which is why the native run passes under CFG. 3. If no image is found, it looks up one entry in the process's protected-policy table, the store behind `RtlSetProtectedPolicy` / `SetProtectedPolicy`, under GUID `{4f6ae3a6-8b1b-4623-a293-294cd743bbd1}`. A non-zero value accepts the target. Otherwise it calls `RtlFailFast(38)`: `0x26`, `FAST_FAIL_INVALID_LONGJUMP_TARGET`. `pe_map` maps into private memory and registers `.pdata` with `RtlAddFunctionTable`. That makes unwinding work, but it does not put the image into the inverted function table, so step 2 never finds it, and step 3 fails. **Confirmation:** in the `ALWAYS_ON` child, calling `SetProtectedPolicy(&{4f6ae3a6-…}, 1, &old)` before mapping makes the truncated case pass. The call returns `ok=1, old=0`, the exit is 2 and the trace is the expected one. Without that call the same child fails with `0xC0000409`. This was an experiment in a wrapper script only; nothing in the repository changed. ## Options 1. **Opt into the policy in `pe_map`, or in the test child.** This is the smallest change and it is measured to work. But that GUID is undocumented, Microsoft describes `SetProtectedPolicy` as "for use primarily by Windows, and not designed for external use", and the policy turns off long-jump target validation for every non-image address in the whole process, not just the mapped image. I would not do this by default. At most it would be an explicit opt-in for test runs. 2. **Leave CFG alone and give the tests a named skip** when the child runs with CFG enforced. This is @legacy-code-archaeologist's detection idea: `GetProcessMitigationPolicy(ProcessControlFlowGuardPolicy)`. It is honest about the limitation, but the mapped long-jump path then goes untested on CFG machines. 3. **Make the mapped image visible to step 2.** The inverted function table is filled only by the loader (`LoadLibrary`), which `pe_map` deliberately avoids. Mapping with `SEC_IMAGE` alone would not register it either, as far as I can tell from step 2. I don't see a supported route here. 4. **Bind the mapped image's `longjmp` import to a `pe_map` replacement** that restores the `jmp_buf` without `RtlUnwindEx`. This avoids the check, but it changes unwind semantics: no frame unwinding, so no C++ destructors. For C code like blast that is fine, but it would be wrong for a general image. My suggestion: option 2 for the tests now, with option 1 only if you explicitly want the mapped long-jump path exercised under CFG and accept the process-wide relaxation in test runs. Which do you want? I can implement either. I'll leave the skip side to @legacy-code-archaeologist if they still want it. ## Limits - One machine and one `ntdll` build. Older builds may differ in step 3. - I read the disassembly without symbols for the helper routines. The lookup and the policy test are inferred from the control flow, and the experiment above confirms only the end result. AI-assisted.
legacy-code-archaeologist commented 2026-11-24 11:03:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T10:50:17Z.


@MasterDomino I haven't started either option and have no code for it, so the root-cause side is yours. I won't work on #1293 while you're on it. The launcher I used is just the CreateProcessW + PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY call described above. If a Windows 11 26100 rerun of your fix would help (system CFG Off here, per-process ALWAYS_ON/OFF), ping me.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129310008 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7129310008). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T10:50:17Z. --- @MasterDomino I haven't started either option and have no code for it, so the root-cause side is yours. I won't work on #1293 while you're on it. The launcher I used is just the `CreateProcessW` + `PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY` call described above. If a Windows 11 26100 rerun of your fix would help (system CFG Off here, per-process ALWAYS_ON/OFF), ping me.
MasterDomino commented 2026-11-24 11:03:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T10:51:03Z.


Thanks @legacy-code-archaeologist, I'm taking #1293. I'll ping you for a 26100 rerun once there is a change. @R0Y00, I'll start coding once you pick between option 2 (named skip when CFG is enforced) and option 1 (explicit test-only opt-in to the long-jump protected policy) from my previous comment.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129327961 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7129327961). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T10:51:03Z. --- Thanks @legacy-code-archaeologist, I'm taking #1293. I'll ping you for a 26100 rerun once there is a change. @R0Y00, I'll start coding once you pick between option 2 (named skip when CFG is enforced) and option 1 (explicit test-only opt-in to the long-jump protected policy) from my previous comment. AI-assisted.
R0Y00 commented 2026-11-24 15:02:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T14:04:29Z.


Please go ahead with option 2, the named capability skip. Leave the host’s CFG policy in force and check the effective policy in the process that executes the mapped fixture. Use the existing CTest skip convention only for the mapped case that requires longjmp when CFG is confirmed active. Give the skip a specific diagnostic. Keep the native truncated-input check and unrelated mapped checks running. If reading the policy fails, report the failure explicitly.

Please verify that the affected mapped case reports the named skip on a CFG-enforced host and still checks the expected error, cleanup, and exit when the effective policy permits it. Keep this issue open for actual mapped longjmp support under CFG. The test-only protected-policy opt-in is declined.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133798189 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7133798189). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T14:04:29Z. --- Please go ahead with option 2, the named capability skip. Leave the host’s CFG policy in force and check the effective policy in the process that executes the mapped fixture. Use the existing CTest skip convention only for the mapped case that requires `longjmp` when CFG is confirmed active. Give the skip a specific diagnostic. Keep the native truncated-input check and unrelated mapped checks running. If reading the policy fails, report the failure explicitly. Please verify that the affected mapped case reports the named skip on a CFG-enforced host and still checks the expected error, cleanup, and exit when the effective policy permits it. Keep this issue open for actual mapped `longjmp` support under CFG. The test-only protected-policy opt-in is declined.
MasterDomino commented 2026-11-24 15:02:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T14:59:32Z.


Claiming option 2: the mapped child reads its own effective CFG policy; only the mapped longjmp case reports a named capability skip (77) when CFG is active, a failed policy read fails explicitly, the native truncated check and the other mapped cases keep running. Refs only, so the issue stays open for real mapped longjmp support. PR link to follow.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7135280624 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7135280624). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T14:59:32Z. --- Claiming option 2: the mapped child reads its own effective CFG policy; only the mapped `longjmp` case reports a named capability skip (77) when CFG is active, a failed policy read fails explicitly, the native truncated check and the other mapped cases keep running. Refs only, so the issue stays open for real mapped `longjmp` support. PR link to follow. AI-assisted.
MasterDomino commented 2026-11-24 16:03:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-24T15:03:05Z.


Option 2 PR: https://github.com/R0Y00/Xbox2Windows/pull/1614 (Refs, so this issue stays open). The mapped child checks its own effective CFG policy before mapping; only the marked longjmp case reports the named skip (77), a failed policy read fails explicitly, and everything else keeps running. Verified with the per-child CFG launcher (on → 77 + diagnostic; off → full error/cleanup/exit trace; unrelated mapped case under CFG → passes; unmarked → original fail-fast) and end to end for all three checks. @legacy-code-archaeologist, if your 26100 setup can put CFG on the test children, a rerun of the three CTests would be welcome.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7135377099 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7135377099). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-24T15:03:05Z. --- Option 2 PR: https://github.com/R0Y00/Xbox2Windows/pull/1614 (Refs, so this issue stays open). The mapped child checks its own effective CFG policy before mapping; only the marked longjmp case reports the named skip (77), a failed policy read fails explicitly, and everything else keeps running. Verified with the per-child CFG launcher (on → 77 + diagnostic; off → full error/cleanup/exit trace; unrelated mapped case under CFG → passes; unmarked → original fail-fast) and end to end for all three checks. @legacy-code-archaeologist, if your 26100 setup can put CFG on the test children, a rerun of the three CTests would be welcome. AI-assisted.
legacy-code-archaeologist commented 2026-11-24 16:03:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-24T15:24:42Z.


@MasterDomino rerun of #1614 on Windows 11 Pro 26100.9168 (MSVC 19.52, Python 3.12, dev preset at 7c5dac78, i.e. with #1614 on main). System CFG on this machine is Off.

CTest, with system CFG Off: ctest --preset dev --no-tests=error -R '^(cpu_native_archive_blast|cpu_archive_texture_publication|cpu_archive_texture_gpu_warp)$' passes 3/3.

CFG on the test children. I can't put CFG on the children that CTest itself starts: the policy attribute applies to the process I create, and the checks spawn their own children. So I ran the mapped child (archive_check.py --mapped pe_map.dll archive_reader.exe archive_codec.dll blast_source.dll) directly. It runs on the base interpreter, with PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_ON or _ALWAYS_OFF:

CFG input X2W_MAPPED_LONGJMP_CASE exit last stderr line
on truncated 1 77 skip: CFG is active in the pe_map runner; …
off truncated 1 2 completed 1 (full alloc/input/output/free trace)
on truncated unset 0xC0000409 input 0 (the original fail-fast, unmarked)
on both records unset 0 completed 2

This matches your results: the skip fires only for the marked case with CFG active, and the error, cleanup and exit trace is intact with CFG off. One thing I noticed, not a problem in practice: the child skips whenever the marker is set, whatever its input. With CFG on, marker 1 and the "both" input, it also exits 77. That is fine as long as only the parent sets the marker, as run_mapped_case does.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7135980717 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7135980717). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-24T15:24:42Z. --- @MasterDomino rerun of #1614 on Windows 11 Pro 26100.9168 (MSVC 19.52, Python 3.12, `dev` preset at 7c5dac78, i.e. with #1614 on main). System CFG on this machine is Off. **CTest**, with system CFG Off: `ctest --preset dev --no-tests=error -R '^(cpu_native_archive_blast|cpu_archive_texture_publication|cpu_archive_texture_gpu_warp)$'` passes 3/3. **CFG on the test children.** I can't put CFG on the children that CTest itself starts: the policy attribute applies to the process I create, and the checks spawn their own children. So I ran the mapped child (`archive_check.py --mapped pe_map.dll archive_reader.exe archive_codec.dll blast_source.dll`) directly. It runs on the base interpreter, with `PROCESS_CREATION_MITIGATION_POLICY_CONTROL_FLOW_GUARD_ALWAYS_ON` or `_ALWAYS_OFF`: | CFG | input | `X2W_MAPPED_LONGJMP_CASE` | exit | last stderr line | |---|---|---|---|---| | on | truncated | 1 | 77 | `skip: CFG is active in the pe_map runner; …` | | off | truncated | 1 | 2 | `completed 1` (full alloc/input/output/free trace) | | on | truncated | unset | `0xC0000409` | `input 0` (the original fail-fast, unmarked) | | on | both records | unset | 0 | `completed 2` | This matches your results: the skip fires only for the marked case with CFG active, and the error, cleanup and exit trace is intact with CFG off. One thing I noticed, not a problem in practice: the child skips whenever the marker is set, whatever its input. With CFG on, marker 1 and the "both" input, it also exits 77. That is fine as long as only the parent sets the marker, as `run_mapped_case` does.
R0Y00 commented 2026-11-24 16:03:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T15:24:57Z.


#1614 merged at 5bfd55a4. The three affected archive checks passed on my Windows Release run with zero skips. The author separately verified the named skip when CFG is active in the mapped child. This stays open for actual mapped longjmp support with CFG enforced.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7135987635 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7135987635). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T15:24:57Z. --- #1614 merged at 5bfd55a4. The three affected archive checks passed on my Windows Release run with zero skips. The author separately verified the named skip when CFG is active in the mapped child. This stays open for actual mapped longjmp support with CFG enforced.
Not-Saii commented 2026-11-29 14:49:10 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-29T14:49:10Z.


@MasterDomino, after #1614 are you still on the part that stays open here, actual mapped longjmp support under CFG? If not, I'd like to take it. I'll wait for your answer, and for @R0Y00's on the design below, before writing code.

Why the open options don't cover it. From your analysis above: option 1, the process-wide protected policy, is declined. Option 3 has no supported route, because only the loader fills the inverted function table. The plain version of option 4 skips frame unwinding, so it would be wrong for any image with __finally blocks or destructors between setjmp and longjmp.

Proposal (option 4 with a real unwind).

  • pe_map binds the mapped image's longjmp import to its own replacement.
  • The replacement does the CRT's target unwind itself:
    • walk the frames from the current one up to the jmp_buf frame with RtlLookupFunctionEntry / RtlVirtualUnwind, which already works through the RtlAddFunctionTable registration;
    • call each frame's language handler with EXCEPTION_UNWINDING | EXCEPTION_TARGET_UNWIND;
    • restore the jmp_buf context.
  • RtlGuardCheckLongJumpTarget is never reached, and the host's CFG policy stays in force.
  • Scope limits:
    • The replacement only handles chains whose frames all belong to the mapped images.
    • If a host frame with a handler sits in between, it fails with a specific diagnostic instead of guessing.
    • Whether RtlRestoreContext validates the target under CFG is the first thing I'll measure. If it does, I'll report that, and the issue stays open.

Tests. Use the per-process ALWAYS_ON / ALWAYS_OFF launcher from @legacy-code-archaeologist's comment.

  1. The truncated blast case passes in the mapped run with CFG on, with the same trace and exit as the native run. The #1614 skip still applies where the replacement is not used.
  2. A new source-built fixture has a __finally block and a nested handler frame between setjmp and longjmp. In the mapped run, with CFG on and off, they run in the same order as in the native run.
  3. Negative controls:
    • a mutant replacement that skips the handler calls fails fixture 2;
    • with the replacement reverted, CFG on fails fast with 0xC0000409 again;
    • a chain with a host handler frame in between gets the named refusal.

@R0Y00, is a pe_map unwinder limited to mapped frames acceptable as "actual support", or would you rather this stay a known boundary?

Environment: Windows 11 build 26300, MSVC (VS 2022 / dev preset), Windows SDK 10.0.26100, Python 3.12. No GPU needed.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7257600675 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1293#issuecomment-7257600675). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-29T14:49:10Z. --- @MasterDomino, after #1614 are you still on the part that stays open here, actual mapped `longjmp` support under CFG? If not, I'd like to take it. I'll wait for your answer, and for @R0Y00's on the design below, before writing code. **Why the open options don't cover it.** From your analysis above: option 1, the process-wide protected policy, is declined. Option 3 has no supported route, because only the loader fills the inverted function table. The plain version of option 4 skips frame unwinding, so it would be wrong for any image with `__finally` blocks or destructors between `setjmp` and `longjmp`. **Proposal (option 4 with a real unwind).** - `pe_map` binds the mapped image's `longjmp` import to its own replacement. - The replacement does the CRT's target unwind itself: - walk the frames from the current one up to the `jmp_buf` frame with `RtlLookupFunctionEntry` / `RtlVirtualUnwind`, which already works through the `RtlAddFunctionTable` registration; - call each frame's language handler with `EXCEPTION_UNWINDING | EXCEPTION_TARGET_UNWIND`; - restore the `jmp_buf` context. - `RtlGuardCheckLongJumpTarget` is never reached, and the host's CFG policy stays in force. - Scope limits: - The replacement only handles chains whose frames all belong to the mapped images. - If a host frame with a handler sits in between, it fails with a specific diagnostic instead of guessing. - Whether `RtlRestoreContext` validates the target under CFG is the first thing I'll measure. If it does, I'll report that, and the issue stays open. **Tests.** Use the per-process `ALWAYS_ON` / `ALWAYS_OFF` launcher from @legacy-code-archaeologist's comment. 1. The truncated blast case passes in the mapped run with CFG on, with the same trace and exit as the native run. The #1614 skip still applies where the replacement is not used. 2. A new source-built fixture has a `__finally` block and a nested handler frame between `setjmp` and `longjmp`. In the mapped run, with CFG on and off, they run in the same order as in the native run. 3. Negative controls: - a mutant replacement that skips the handler calls fails fixture 2; - with the replacement reverted, CFG on fails fast with `0xC0000409` again; - a chain with a host handler frame in between gets the named refusal. @R0Y00, is a `pe_map` unwinder limited to mapped frames acceptable as "actual support", or would you rather this stay a known boundary? Environment: Windows 11 build 26300, MSVC (VS 2022 / dev preset), Windows SDK 10.0.26100, Python 3.12. No GPU needed. AI-assisted.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#1286
No description provided.