Skip to content

RR plugin: stay off when another Ray Reconstruction plugin is already active - #43

Merged
phantoslayer21 merged 5 commits into
mainfrom
22-rr-guard
Nov 14, 2026
Merged

phantoslayer21 merged 5 commits into
mainfrom
22-rr-guard

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Policy (decided 2026-11-14). WrongGPU RR stays off only when another Ray Reconstruction plugin is positively
identified: a second copy of WrongGPU RR, or the host's plugin API refusing our registration. A foreign hook that cannot
be identified as an RR plugin keeps WrongGPU RR on, because a false positive would take RR away from players whose game
merely has a wrapper, overlay or helper on that path.

Known limitation. A different RR plugin that hooks the call path from its own module is not identified as such. With
the default setting both can run side by side; the log names the module (see below). A player who sees that can set
rr_other_plugin = yield to keep WrongGPU RR off.

WrongGPU's RR plugin now notices when something else sits on the game's Ray Reconstruction call path, and says so in
one line of wronggpu-rr.log. It switches itself off only on evidence that is positive by contract; it never
switches RR off for a player on a guess. Model M is not affected.

When WrongGPU RR switches itself off

  • A second copy of WrongGPU RR (a process-wide marker, or a call that leads into a module exporting the 60.9
    contract export): the second copy starts nothing and writes no exit summary.
  • The host's plugin API says no: it refuses our NGX RR provider (the NGX route stays off) or our game-interface
    routes (that route stays off). The API gives the same false for an occupied slot and for a structure it does not
    accept, so the log says only that the host refused; it does not claim another plugin.

Nothing else.

A named module on the call path is inconclusive. It may be another RR plugin, but it may as well be a game's own
wrapper DLL, an overlay, a security shim, a host helper in a third image or a forwarded export's implementation DLL.
WrongGPU RR stays active, as in 0.6.0, and one line names the module and the place:
another module hooks the game's RR calls: <module> (<where>); it is not known to be a Ray Reconstruction plugin: WrongGPU RR stays active (...). A bug report shows it, and the launcher's Last run can say "another module hooks the
game's RR calls: <module>" from that line's beginning. What the scan cannot explain at all (unreadable memory, code
outside every module that does not jump on, the exe's own code, more than 4 hook jumps) gets one "inconclusive"
diagnostic line and changes nothing either.

rr_other_plugin in wronggpu-rr.ini (all three documented in HOOK-MODE.md):

  • off (the default): as above.
  • take: as before. With a module named at load (or under our host routes) WrongGPU RR goes in front of it and
    continues the game's other calls through it. take never switches RR off because of a named module (a copy of
    WrongGPU RR still stops it, a host refusal still keeps that route off); a module that hooks after ours is only named.
  • yield: WrongGPU RR stays off whenever any named module outside the recognised images is on the path. Found at load:
    nothing patched, the RR core and runtime are not loaded. Found later: WrongGPU's handlers pass every call on
    unchanged. yield cannot establish who owns that module: a game's own wrapper DLL, an overlay or a host helper in a
    third image switch it off as well.

The host is taken to be the module that called InitializeASI and the module holding the host's API table. With
the default setting this guess is now used only for the log's wording (the host's own patches are not named), so a
wrong host identification can no longer switch RR off. The load-check re-run of the first round is removed. It could
leave a misleading "stays off" line in the log, and it did not help when the host table is on the heap or in a helper
image.

Also in this pull request (the guard runs in every player's game at load):

  • Another module's PE headers are used only within the image's extent: the smaller of SizeOfImage and what is
    really mapped there, measured with VirtualQuery before any header is read. e_lfanew, every data directory, every
    RVA the walk follows and every byte of an import name are checked against it before an address is formed; import
    descriptors are read only within the directory's declared size (PeView, import_slots, thunks in
    src/rr_guard.{h,cpp}). Module APIs run under a held module reference. The load scan has a budget (200000 entries,
    100 ms) that fails open: over it, nothing is decided, one line, RR stays active. Jump targets are computed as
    integers.
  • The documentation no longer claims guard pages are "never touched". The check and the copy are not atomic, and
    HOOK-MODE.md now says what that leaves. The log's process-wide lock is described as best effort after a timeout
    (log_append.h, HOOK-MODE.md "The log with two copies").

Beyond the feature: the hook plugin's log writing (unchanged from round 1). Two copies of the plugin in one process
write the same wronggpu-rr.log. In the hook plugin (src/hook_dll.cpp, src/log_append.h), every line is now one
append call, and the size check and rotation happen under a process-wide lock. The exit summary only tries the lock,
with no wait. The probe log starts a new empty file even when the old one cannot be moved aside. The file-replacement
proxy's part is not in this pull request.

Two decisions taken in this round (beyond the written design)

  • take never switches WrongGPU RR off. In round 1, take with a module that hooked after ours meant "cannot be
    applied, stays off", which would have made take stricter than the default. Now a late module is only named, as with
    off.
  • The follow-up issue also takes the pre-existing patch code's header walk (the rest of the second review's item 5),
    next to items 3, 4 and the rest of 6. Module references and the time budget are done here (third review).
  • Also: the late check reports only RR exports that changed since the load check, so an export hook named at load is
    not reported again as "took the RR calls after WrongGPU".

Fixes #22

Review findings, first review (head 58a283c)

  • Blocking 1, unreadable or unrecognised counted as another plugin; execute-only pages unreadable: fixed in round 1
    (src/rr_guard.cpp Verdict::add, readable()), and this round goes further: a named module is no longer a finding
    either (see second review 1).
  • Should-fix 2, the host was only the caller of InitializeASI: superseded. The table's module still counts as the host
    for the wording (src/hook_dll.cpp OptiPluginInit), but the host guess no longer decides anything with the default
    setting, and the load-check re-run is removed (src/hook_dll.cpp). Tests: hostsplit, heaptable and
    helpertable all stay active.
  • Should-fix 3, the two-copies log test could not fail: fixed in round 1 (tests/test_rr_guard_dll.cpp owncopy: five
    copies log at once; build.py repeats it 200 times).
  • Should-fix 4, 500 ms wait under the loader lock: fixed in round 1 (src/hook_dll.cpp exit_summary: 0 ms try).
  • Should-fix 5, a second copy wrote a misleading exit summary: fixed in round 1 (src/hook_dll.cpp, early return;
    checked in owncopy).
  • Should-fix 6, the hook probe log could append to the old file: fixed in round 1 (src/hook_dll.cpp, CREATE_ALWAYS).
  • Should-fix 7, Model M guard tools: split out in round 1 (removed, no references left).
  • Note, hop limit 5 vs docs 4: fixed in round 1 (src/rr_guard.cpp; tested).
  • Note, plain globals: fixed in round 1 (atomics). This round g_take became g_mode, also atomic.
  • Note, runtime-unloaded claim: fixed in round 1 (tests/test_rr_guard_dll.cpp). This round checks it for
    wrapper --yield (not loaded) and for every stays-active mode (loaded).
  • Note, CI undersold: said below (CI runs every guard mode).
  • Note, fail-open cases: documented (HOOK-MODE.md, "What the guard does not see"); more in the follow-up below.
  • Note, the log rewrite goes beyond the feature: said above.

Review findings, second review (head 44db7ed)

  • 1, a named destination treated as proof of an RR plugin: fixed in src/rr_guard.{h,cpp} (Verdict::kForeign,
    decide, line_foreign, Mode) and src/hook_dll.cpp (guard_apply, the load, host-route and late checks). A
    named module is inconclusive: one line, RR stays active. Only a copy of WrongGPU RR or the host's API refusing us
    switches off; yield gives the player the old behaviour. New tests: test_rr_guard (the whole decide table for a
    game-owned wrapper DLL, a host helper in a third image, an overlay-style wrapper, a forwarded export, the heap-table
    and helper-table host layouts) and test_rr_guard_dll modes wrapper, overlay, forward, helper, heaptable,
    helpertable (stay active, RR answered by WrongGPU, NGX provider ours, runtime loaded), wrapper --yield (off),
    route-other --yield (passing) and route-refused (off by the host's answer). The existing first, inline,
    relay, execonly, hostsplit, late, late-replace, route-other and route-inline modes now expect "stays
    active" plus the one line.
  • 2, host recovery assumed the API table lives in the host image: fixed by the design change (src/hook_dll.cpp: the
    host guess is used for the wording only; the re-run is removed). Tests: heaptable, helpertable, hostsplit.
  • 3, guard-page protection can change between the check and the read: the documentation's claim is fixed in
    HOOK-MODE.md, src/rr_guard.h and the test comments (the race is described, not claimed away). Re-querying cached
    regions and a test for it are split out to the follow-up.
  • 4, incomplete scanning, fail-open cases: not changed, because with the default setting these gaps can only leave a
    module unnamed, never switch RR off. Split out to the follow-up (region-crossing reads, a second jump inside the
    interface, the 1,024-module cap, ordinal imports, bound FirstThunk, enumeration failure as inconclusive).
  • 5, scanner robustness: e_lfanew, data directories and RVAs are now checked against SizeOfImage before any pointer
    arithmetic (src/rr_guard.{h,cpp} PeView; src/hook_dll.cpp guard_thunks, guard_import_slots, the delay-load
    walk; process_env), and jump targets are integer arithmetic. Tests: test_rr_guard (the real exe; synthetic headers
    with a negative, too-small, absurd and out-of-image e_lfanew; directories past or wrapping SizeOfImage; too few
    directories; PE32; no signature). Module references and an overall time budget are split out to the follow-up.
  • 6, logging and test limits: the log lock is now documented as best effort after a timeout (src/log_append.h,
    HOOK-MODE.md). The "misleading off line left in the log" case is gone with the re-run. The other points are split
    out to the follow-up: a lock-timeout test, marker creation failure, the host's loader-lock context, what the stress
    loop proves, CI cost, a stricter parser warning.

Follow-up issue (items 3, 4, the old patch walk of 5, and 6): drafted for the maintainer to file.

Review findings, third review (head 7ef3a34)

  • 1, the PE walk read outside the validated image and directory, with no aggregate bound: fixed in
    src/rr_guard.{h,cpp} and src/hook_dll.cpp.
    • Strings: names are read with PeView::str, each byte checked against the image's extent; a name without its NUL
      inside the image is skipped, never read past (was Reader::str with up to 96 bytes from the first checked byte).
    • Directory: import_slots reads only the descriptors the import directory's declared size holds (the walk moved
      from hook_dll.cpp to rr_guard.cpp so the unit test can drive it).
    • Real extent: mapped_extent (VirtualQuery over the committed regions of the module's allocation) is measured
      before any header is read; e_lfanew is checked against it before the NT headers are read; the extent is
      min(SizeOfImage, mapping), so a forged larger SizeOfImage does not widen it.
    • Module references: ModuleRef (GetModuleHandleExW from address, FreeLibrary at the end of the scope) around
      GetProcAddress / GetModuleFileNameW (process_env) and around each module's import walk and the export scan;
      a module unloaded meanwhile counts as nothing found.
    • Budget: Budget (200000 entries, 100 ms, the time looked at every 64 entries) counts every module, descriptor and
      name-table entry of the load scan. Over it, the scan decides nothing, logs hook: coexistence check at load: stopped after <n> entries (<t> ms), over its budget ...; inconclusive, WrongGPU RR stays active, and RR stays
      active in every mode (fails open; the process marker still stops a second copy).
    • Tests (test_rr_guard): an import name at the image's last byte with no NUL inside the image and readable bytes
      after it (skipped, not read); names ending at the last byte; an import directory smaller than its descriptors (only
      the declared ones) and smaller than one descriptor (none); another DLL's name; a SizeOfImage larger than the
      mapping; NT headers past the mapping; mapped_extent; the budget by entries (the walk stops, stays over) and by
      time; the budget line's exact words.
    • HOOK-MODE.md ("Another module's PE headers", "The load scan's budget") now claims only this: the extent bounds
      where the walk reads, it does not make the memory stable.
  • 2, a refused provider registration was reported as a competing RR plugin: fixed. line_ngx_refused (was
    line_ngx_other): the host refused WrongGPU's NGX RR provider registration; the NGX route stays off (the game-interface route is decided on its own). The host API has no distinct signal for an occupied slot, so none is
    claimed. Tests: test_rr_guard (exact words, no "plugin is active", no "another provider"); test_rr_guard_dll
    new mode provider-refused (the host refuses with no provider installed: the line, no other plugin claimed, no provider
    anywhere, the game-interface route stays ours), and provider now expects the same line.
  • Can follow, the wording of take and yield: done in HOOK-MODE.md and here. take never switches off because of
    a named module (own copy and host refusal still apply); yield reacts to any named module outside the recognised
    images and cannot establish who owns it.
  • Can follow, not changed (follow-up): the own-copy line after initialisation, line_inconclusive beside an own-copy
    finding, the loader-lock statement, marker creation failure, the forward test's real loader forwarding.
  • Hygiene: the host product's name in hook_dll.cpp is the existing integration's (its entry point and API); the new
    guard names and depends on no third-party product.

Tested (CPU only; counts from the saved run outputs)

  • python clean/rr_f/proxy/tools/build.py --out <dir> (all CPU tests; the probe and hook tests use the software D3D12
    adapter, WARP), on 334c93c: 201 test programs, 1801388 checks, 0 failures; 141 test_rr_guard_dll mode runs (32
    release and 15 probe modes for each of 2.7, 2.8 and 2.14, including the new provider-refused), 0 failures; owncopy
    stress (five copies logging at once) 200/200, 0 torn lines; test_rr_guard 595 checks, 0 failures (577 before);
    Python 33 tests OK (1 skipped).
  • tools/ci/run_proxy_core_tests.py on that build: plugin CPU tests 6 run, 0 failed.
  • CI runs all of this: build.py --no-tests still builds and runs every test_rr_guard_dll mode for 2.7, 2.8 and
    2.14 (release and probe) and the 200-run stress; run_proxy_core_tests.py runs test_rr_guard.
  • The load scan's measured cost in the guard runs stays at about 0.1 ms (coexistence check at load: 0.10-0.13 ms),
    far below the budget.
  • Public gates on 334c93c: secrets, personal data, licence and chunks pass; no leak-scan hit and no flagged number in a
    file of this pull request (a first try named the new mode ngx-refused and wrote a test table on one line; both
    matched leak patterns and were changed before the push).

Not tested

  • In a game, with and without a second RR plugin or another module on the path (needs the maintainer's GPU test).

… active

When another Ray Reconstruction plugin already holds the game's RR calls, or a
second copy of WrongGPU-RR.asi is loaded, WrongGPU's RR plugin patches nothing,
leaves Model M alone and writes one line to wronggpu-rr.log saying why. A plugin
that loads later is found at the game's first call; WrongGPU's handlers then pass
every call on unchanged. rr_other_plugin=take in wronggpu-rr.ini lets a player
choose WrongGPU's RR on purpose. Every read of memory the plugin does not own is
guarded; a read that fails counts as another plugin (the safe side).

Two copies of the plugin write one log: each line is one append call under a
process-wide lock, so lines never tear.

The guard is read-only and generic (src/rr_guard.h/.cpp, HOOK-MODE.md "Another
Ray Reconstruction plugin"). Tests: test_rr_guard (safe reads, jump forms,
classification, one decision under 32 threads) and test_rr_guard_dll with a
stand-in other plugin in every mode, for interface 2.7, 2.8 and 2.14, release and
probe builds, plus a 200-run two-copy log stress. CI runs test_rr_guard.

Fixes #22

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Review of the RR plugin guard, done in this commit:

- Only a positive finding switches WrongGPU RR off: an address that ends
  in another named module (directly or through decoded hook jumps), or in
  a second copy of WrongGPU RR. Unreadable memory, code outside every
  module that does not jump on, the exe's own code and a jump chain longer
  than the hop limit are now inconclusive: counted, logged once with a
  "hook: coexistence check ...: inconclusive" line, and RR stays active.
  Execute-only pages count as readable for the code read (the copy is
  still guarded by the structured-exception handler).
- The module holding the host's API table counts as the host too. When a
  separate loader called InitializeASI and the load check took the real
  host's own patches for another plugin, OptiPluginInit runs the load
  check again with that module as the host (nothing was patched before).
  New test mode hostsplit: a separate DLL calls InitializeASI.
- The two-copies log test now makes every copy log at once: four more
  copies run InitializeASI / OptiPluginInit from threads while 16 game
  threads make the first call; no line may be torn.
- The exit summary at DLL_PROCESS_DETACH only tries the log's
  process-wide lock (no wait under the loader lock); the comment says so.
- A second copy of WrongGPU RR writes no exit summary.
- The hook build's probe log starts a new empty file also when the old
  one could not be moved aside.
- The hop limit and the docs agree: at most 4 hook jumps are followed, a
  fifth is too many (tested both ways).
- g_take, the host modules and the pass-through targets are atomics.
- The off modes check that the RR runtime is not loaded (and the clean
  mode that it is).
- HOOK-MODE.md: what counts as a finding, the inconclusive cases, the
  known fail-open cases, the new log line and test modes.
- Removed the Model M guard tools (tests/guard_inject.cpp,
  tests/guard_scene.cpp, tools/guard_modelm.py) and every reference.
- The file-proxy build's log change (proxy_dll.cpp) is taken out of this
  pull request; it is not needed by the guard.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 13, 2026 20:28
@phantoslayer21
phantoslayer21 marked this pull request as draft November 13, 2026 21:05
… is inconclusive

WrongGPU RR now switches itself off only on evidence that is positive by contract: a second
copy of WrongGPU RR, or the host's plugin API refusing our registration (NGX provider slot
taken, game-interface routes refused). A named module on the RR call path (a game's wrapper
DLL, an overlay, a host helper, a forwarded export's implementation DLL, or another RR plugin)
is inconclusive: RR stays active as in 0.6.0 and one line names the module and the place
("another module hooks the game's RR calls: <module> (...)").

- rr_other_plugin = off (default) | take | yield. take goes in front of a module found at load
  or under our host routes and never switches RR off; yield keeps RR off whenever a named
  module is on the path. The policy is one table, rr_guard::decide.
- The host guess (caller of InitializeASI, module of the API table) only shapes the wording;
  the load-check re-run is removed, so no misleading "stays off" line can remain.
- The late check reports only exports that changed since the load check.
- Another module's PE headers: e_lfanew, data directories and every RVA the walk follows are
  checked against SizeOfImage before an address is formed (PeView); jump targets are integer
  arithmetic.
- Docs: the guard-page race and the log lock's best effort after a timeout are described
  instead of claimed away.
- Tests: test_rr_guard covers the decide table for six layouts without a second RR provider,
  the own-copy cases and the PE bounds; test_rr_guard_dll adds wrapper, wrapper --yield,
  overlay, forward, helper, heaptable, helpertable, route-other --yield and route-refused, and
  the existing modes now expect "stays active" plus the one line.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 13, 2026 21:42
@phantoslayer21
phantoslayer21 marked this pull request as draft November 14, 2026 00:07
…GX registration claims no other plugin

Third review. The load scan reads another module's headers only within the image's real extent (min of SizeOfImage and the mapping, measured first), reads names byte by byte inside it, reads import descriptors only within the directory's declared size, holds a module reference around module APIs, and stops after 200000 entries or 100 ms (inconclusive, RR stays active). The NGX refusal line says only that the host refused (its API gives one false for every refusal). take / yield wording in HOOK-MODE.md.

Fixes #22

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 merged commit e6a98fa into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the 22-rr-guard branch November 14, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray Reconstruction plugin: stay off when another Ray Reconstruction plugin is already active

1 participant