[PR #41] startup trace: a call through a null pointer names its caller (null_call_from) #94

Open
opened 2026-11-26 20:16:46 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/41
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/7189


📝 Commits (3)

  • cd6277c startup trace: a call through a null pointer names its caller
  • 4524c01 registry: no module lookup for an address in the null page
  • d077c5a startup trace: a null transfer is attributed to a call only when the call is proven

📊 Changes

4 files changed (+170 additions, -4 deletions)

View changed files

📝 runtime/README.md (+1 -1)
📝 runtime/shims/registry.cpp (+4 -1)
📝 runtime/shims/startup_trace.h (+83 -2)
📝 runtime/test/startup_trace_test.cpp (+82 -0)

📄 Description

Carried over from old PR 7189 by rafaelpssz in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/7189, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
rafaelpssz: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claimed in the coordination issue: https://github.com/ItsNotRexed/Leonida/issues/7049#issuecomment-7106564862

What and why

A call through a null pointer faults on the instruction fetch at address 0. Until now, --trace logged it as "at":"0x0","access":"execute","address":"0x0","stack":[]. stack_from stops at once because Rip is 0, so the trace couldn't say who made the call. That's the most common shape of a boot stop right now: a console vtable slot past the end of a PC proxy's table, or an unset out-pointer the title calls through.

A call has already pushed its return address. When an access violation is at an address in the first 64 KiB, the handler now:

  • reads the frame on top of the stack from [rsp], as stack_from already does for a leaf function;
  • walks the stack from that frame;
  • names the frame (module+RVA) with one of two fields.

null_call_from is used only when the call is proven. The instruction before the frame must be an indirect call (FF /2, register or memory), and its operand, evaluated with the registers of the fault, must be the faulting address. A fault on the fetch at a call's target comes before any instruction of the target runs, so those registers are still the call's own.

null_transfer_return is used otherwise: a direct call, an indirect call to some other address, or nothing recognizable. A tail jump through null pushes nothing, so the frame on the stack belongs to whoever entered the jumping function. The field says where that code would have returned to and makes no claim about who made the transfer.

One case still reads as a call and is not: a tail jump through the same register the enclosing call went through. The README and the header say so.

Nothing else changes, and the handler still only records. If [rsp] isn't readable, the event is logged as before.

before: {"kind":"exception","code":"0xc0000005","at":"0x0","access":"execute","address":"0x0","stack":[]}
after:  {"kind":"exception","code":"0xc0000005","at":"0x0","access":"execute","address":"0x0",
         "null_call_from":"a.exe+0x1e86853","stack":["a.exe+0x1e86853","a.exe+0x5c5ffc6",...]}

(The addresses above are made-up examples.) On the retail executable this turned the empty event into the caller. Its disassembly is a call through device vtable offset 0x428 = slot 133, which is the stop #6953 fixes. It took one run instead of a debugger session (integration run in #7049).

Changes

  • runtime/shims/startup_trace.h: the null-page case in log_exception, faulting_call_ends_at (the check above), and the header's event examples.
  • runtime/test/startup_trace_test.cpp: the synthetic image makes four transfers to address 0:
    • call rax with rax 0: null_call_from, the instruction after the call, and the stack starts there;
    • call [rip+slot] with a zero slot: null_call_from too;
    • jmp rcx with rcx 0, reached by a direct call: null_transfer_return, no null_call_from;
    • the same jump reached by call rax to a real function: null_transfer_return, no null_call_from.
      The existing in-image read fault gets neither field.
  • runtime/README.md: the field in the startup-trace event table.
  • runtime/shims/registry.cpp: module_offset does no module lookup for an address in the first 64 KiB. Under Wine, GetModuleHandleExW(FROM_ADDRESS, 0) answers with the executable, so a fault at 0 was named exe+(0 - base) (JoaoPauluu's finding and fix).

Tested

Windows 11 Pro 26200, clang-cl/xwin cross build (MSVC 14.44 headers), RelWithDebInfo:

  • startup_trace_test: 42 checks, 0 failed (d077c5a4c).
  • With d077c5a4c's change to startup_trace.h reverted, 4 of the 42 fail: both jumps are attributed to the enclosing call, which is the misattribution the reviewers reported.
  • Before that, without the first change to startup_trace.h, 2 of the then 32 failed: null_call_from … and the null call's stack starts at its caller.
  • Not run for d077c5a4c: MSVC, and the retail executable (the earlier retail result below was for 4524c0136; that call is an indirect call through a vtable slot, the form the new check accepts).
  • gta6rt builds. With the change, a retail --run --trace on my own copy logged null_call_from for the slot-133 call, as described above. No game data here.

Thanks

  • @Pipodi: #6953 and the boot-chain measurements this was used against.
  • @NiiRoZz: #7075/#7076, which got the run far enough to need it.
  • @dadsmallbuk1: tested it on an RTX 5090 with a native MSVC build (ctest -R ^startup_trace$ pass, the six new checks).
  • @illusionart453-max: an independent native MSVC build and run (32/32).
  • @JoaoPauluu: the Wine run that found module_offset(0) naming the null page as the executable, and the guard now in registry.cpp.
  • @TheHoracio: tested on RX 7800 XT.
  • @Jadiac5: tested on RX 9070 XT.
  • @DeSunShine: tested on RTX 4090.
  • @itaskaev2: tested on RTX 4080 SUPER.
  • @SirKingg: an integration check with six other PRs' hunks in a Windows Sandbox, and the tail-jump case: a null tail jump pushes no return address, so the field named the wrong frame.
  • @sds-228: the same finding in review, with the two ways out (verify the instruction, or narrow the field). d077c5a4c does both.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/41 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/7189` --- ### 📝 Commits (3) - [`cd6277c`](https://github.com/ubiquitarianism/leonida/commit/cd6277c2292f2b1675fe5e050fad9a6034612666) startup trace: a call through a null pointer names its caller - [`4524c01`](https://github.com/ubiquitarianism/leonida/commit/4524c01367950c81655c15142a778bd8402c9c9e) registry: no module lookup for an address in the null page - [`d077c5a`](https://github.com/ubiquitarianism/leonida/commit/d077c5a4c766080976d4fc10e8326d84fa6610d6) startup trace: a null transfer is attributed to a call only when the call is proven ### 📊 Changes **4 files changed** (+170 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `runtime/README.md` (+1 -1) 📝 `runtime/shims/registry.cpp` (+4 -1) 📝 `runtime/shims/startup_trace.h` (+83 -2) 📝 `runtime/test/startup_trace_test.cpp` (+82 -0) </details> ### 📄 Description > Carried over from **old PR 7189** by `rafaelpssz` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/7189`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `rafaelpssz`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claimed in the coordination issue: https://github.com/ItsNotRexed/Leonida/issues/7049#issuecomment-7106564862 ### What and why A call through a null pointer faults on the instruction fetch at address 0. Until now, `--trace` logged it as `"at":"0x0","access":"execute","address":"0x0","stack":[]`. `stack_from` stops at once because `Rip` is 0, so the trace couldn't say who made the call. That's the most common shape of a boot stop right now: a console vtable slot past the end of a PC proxy's table, or an unset out-pointer the title calls through. A `call` has already pushed its return address. When an access violation is at an address in the first 64 KiB, the handler now: - reads the frame on top of the stack from `[rsp]`, as `stack_from` already does for a leaf function; - walks the stack from that frame; - names the frame (`module+RVA`) with one of two fields. `null_call_from` is used only when the call is proven. The instruction before the frame must be an indirect call (`FF /2`, register or memory), and its operand, evaluated with the registers of the fault, must be the faulting address. A fault on the fetch at a call's target comes before any instruction of the target runs, so those registers are still the call's own. `null_transfer_return` is used otherwise: a direct call, an indirect call to some other address, or nothing recognizable. A tail jump through null pushes nothing, so the frame on the stack belongs to whoever entered the jumping function. The field says where that code would have returned to and makes no claim about who made the transfer. One case still reads as a call and is not: a tail jump through the same register the enclosing call went through. The README and the header say so. Nothing else changes, and the handler still only records. If `[rsp]` isn't readable, the event is logged as before. ``` before: {"kind":"exception","code":"0xc0000005","at":"0x0","access":"execute","address":"0x0","stack":[]} after: {"kind":"exception","code":"0xc0000005","at":"0x0","access":"execute","address":"0x0", "null_call_from":"a.exe+0x1e86853","stack":["a.exe+0x1e86853","a.exe+0x5c5ffc6",...]} ``` (The addresses above are made-up examples.) On the retail executable this turned the empty event into the caller. Its disassembly is a call through device vtable offset `0x428` = slot 133, which is the stop `#6953` fixes. It took one run instead of a debugger session (integration run in `#7049`). ### Changes - `runtime/shims/startup_trace.h`: the null-page case in `log_exception`, `faulting_call_ends_at` (the check above), and the header's event examples. - `runtime/test/startup_trace_test.cpp`: the synthetic image makes four transfers to address 0: - `call rax` with `rax` 0: `null_call_from`, the instruction after the call, and the stack starts there; - `call [rip+slot]` with a zero slot: `null_call_from` too; - `jmp rcx` with `rcx` 0, reached by a direct call: `null_transfer_return`, no `null_call_from`; - the same jump reached by `call rax` to a real function: `null_transfer_return`, no `null_call_from`. The existing in-image read fault gets neither field. - `runtime/README.md`: the field in the startup-trace event table. - `runtime/shims/registry.cpp`: `module_offset` does no module lookup for an address in the first 64 KiB. Under Wine, `GetModuleHandleExW(FROM_ADDRESS, 0)` answers with the executable, so a fault at 0 was named `exe+(0 - base)` (JoaoPauluu's finding and fix). ### Tested Windows 11 Pro 26200, clang-cl/xwin cross build (MSVC 14.44 headers), RelWithDebInfo: - `startup_trace_test`: 42 checks, 0 failed (`d077c5a4c`). - With `d077c5a4c`'s change to `startup_trace.h` reverted, 4 of the 42 fail: both jumps are attributed to the enclosing call, which is the misattribution the reviewers reported. - Before that, without the first change to `startup_trace.h`, 2 of the then 32 failed: `null_call_from …` and `the null call's stack starts at its caller`. - Not run for `d077c5a4c`: MSVC, and the retail executable (the earlier retail result below was for `4524c0136`; that call is an indirect call through a vtable slot, the form the new check accepts). - `gta6rt` builds. With the change, a retail `--run --trace` on my own copy logged `null_call_from` for the slot-133 call, as described above. No game data here. ### Thanks - `@Pipodi`: `#6953` and the boot-chain measurements this was used against. - `@NiiRoZz`: `#7075`/#7076, which got the run far enough to need it. - `@dadsmallbuk1`: tested it on an RTX 5090 with a native MSVC build (`ctest -R ^startup_trace$` pass, the six new checks). - `@illusionart453-max`: an independent native MSVC build and run (32/32). - `@JoaoPauluu`: the Wine run that found `module_offset(0)` naming the null page as the executable, and the guard now in `registry.cpp`. - `@TheHoracio`: tested on RX 7800 XT. - `@Jadiac5`: tested on RX 9070 XT. - `@DeSunShine`: tested on RTX 4090. - `@itaskaev2`: tested on RTX 4080 SUPER. - `@SirKingg`: an integration check with six other PRs' hunks in a Windows Sandbox, and the tail-jump case: a null tail jump pushes no return address, so the field named the wrong frame. - `@sds-228`: the same finding in review, with the two ways out (verify the instruction, or narrow the field). `d077c5a4c` does both. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#94
No description provided.