[pr-fix][startup] loader: a write site past the end of the address space is not read #371

Manually merged
TrustNo1 merged 1 commit from qnjk/Darner:loader-write-sites-overflow into main 2026-12-05 04:50:03 +00:00
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: write_sites::apply reads a file name and a hexadecimal offset from a text file (DARNER_WRITE_SITES=<file>) and bounds the offset with a plain addition:

    if !image.eq_ignore_ascii_case(name) || offset + 16 > size || !seen.insert(offset) {
        continue;
    }
    let at = base + offset;
    

    (crates/darner-loader/src/write_sites.rs:242 and :245). usize::from_str_radix accepts any usize, so a line such as t.dll ffffffffffffffff overflows that addition. In the dev and test profiles the guard panics (attempt to add with overflow). In the release, diag and fast profiles, which inherit release's overflow settings, offset + 16 wraps to 15, the guard 15 > size is false, base + offset wraps to base - 1, and sixteen bytes are read one page below the image and then run through stub/console_insn::near. The SAFETY comment on that read — "sixteen bytes inside the image" — is exactly what the wrapped guard no longer proves. The same file's heap_sites sibling already bounds its site with checked_add (crates/darner-loader/src/heap_sites.rs:1349), so this is a missed hardening, not a deliberate choice.

  • This change makes the guard offset.checked_add(16).is_none_or(|end| end > size), mirroring heap_sites. Nothing else changes; a list whose offsets are inside the image behaves exactly as before.

How it was tested

  • Tested revision: d0a9a46 (one commit on f3840d7).

  • Commands and results:

    • cargo test --locked -p darner-loader --lib — 93 passed, 0 failed.
    • The new test write_sites::tests::an_offset_past_the_end_of_the_address_space_is_not_read was also run against the same tree with only the guard put back to offset + 16: it fails there with panicked at crates/darner-loader/src/write_sites.rs:247: attempt to add with overflow, and passes with the change. The test needs no fixture: it VirtualAllocs 64 KiB and passes a two-line list naming the image at usize::MAX and usize::MAX - 7.
  • Changes a default: no. Nothing is different for any list whose offsets are inside the image.

  • A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim.

  • Gates run on that revision:

    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not green on this machine, and not because of this change. Three pre-existing failures, each covered by an open pull request: darner-gpu stands still in parallel on the test deadlock #224 describes, and serially it finishes 1772 passed and 1 failed (pipeline::make::tests::a_capped_draw_waits_once_then_drops, which passes on its own) beside the order-dependent watch::tests::ask_once_by_res_splits_reservations_without_refusals and texture::ahead::tests::drain_waits_until_then_callbacks_have_run flakes that #150 is about; darner-shader fails emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, whose fixture #227 fixes. Every other crate passes. This change touches no file of either crate.
  • Gameplay, when relevant: no gameplay run. This path only runs when DARNER_WRITE_SITES names a file or is auto and the build has known sites; for the title image on this machine the known list is empty, so darner run <exe> --console series-x still maps and binds it with 0 missing for the executable and each title DLL without reaching apply. The behaviour being changed is the bound on an operator-supplied list, and the unit test covers it directly.

  • Shader wave sizes tested, when relevant: not applicable.

  • Hardware dependence: none. Pure arithmetic guard, no GPU and no timing.

  • Coverage gaps: the reachable trigger is a hand-written DARNER_WRITE_SITES file; that file was not produced or applied against a real title, and there is no gameplay run.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay. For this build the write-site list is empty, so a run of the title does not reach apply; the new test fails on main and passes here, and the guard is arithmetic only.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 555 files ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. No open pull request changes crates/darner-loader/src/write_sites.rs (checked against the file list of all 161 open pull requests), and no open or closed issue or pull request body mentions DARNER_WRITE_SITES or write_sites.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `write_sites::apply` reads a file name and a hexadecimal offset from a text file (`DARNER_WRITE_SITES=<file>`) and bounds the offset with a plain addition: ```rust if !image.eq_ignore_ascii_case(name) || offset + 16 > size || !seen.insert(offset) { continue; } let at = base + offset; ``` (`crates/darner-loader/src/write_sites.rs:242` and `:245`). `usize::from_str_radix` accepts any `usize`, so a line such as `t.dll ffffffffffffffff` overflows that addition. In the dev and test profiles the guard panics (`attempt to add with overflow`). In the `release`, `diag` and `fast` profiles, which inherit `release`'s overflow settings, `offset + 16` wraps to `15`, the guard `15 > size` is false, `base + offset` wraps to `base - 1`, and sixteen bytes are read one page below the image and then run through `stub`/`console_insn::near`. The SAFETY comment on that read — "sixteen bytes inside the image" — is exactly what the wrapped guard no longer proves. The same file's `heap_sites` sibling already bounds its site with `checked_add` (`crates/darner-loader/src/heap_sites.rs:1349`), so this is a missed hardening, not a deliberate choice. - This change makes the guard `offset.checked_add(16).is_none_or(|end| end > size)`, mirroring `heap_sites`. Nothing else changes; a list whose offsets are inside the image behaves exactly as before. ## How it was tested - Tested revision: `d0a9a46` (one commit on `f3840d7`). - Commands and results: - `cargo test --locked -p darner-loader --lib` — 93 passed, 0 failed. - The new test `write_sites::tests::an_offset_past_the_end_of_the_address_space_is_not_read` was also run against the same tree with only the guard put back to `offset + 16`: it fails there with `panicked at crates/darner-loader/src/write_sites.rs:247: attempt to add with overflow`, and passes with the change. The test needs no fixture: it `VirtualAlloc`s 64 KiB and passes a two-line list naming the image at `usize::MAX` and `usize::MAX - 7`. - Changes a default: no. Nothing is different for any list whose offsets are inside the image. - A/B result, for a change of a default (on for everyone) or a speed claim: not applicable — no default changes and no speed claim. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: **not green on this machine, and not because of this change.** Three pre-existing failures, each covered by an open pull request: `darner-gpu` stands still in parallel on the test deadlock #224 describes, and serially it finishes 1772 passed and 1 failed (`pipeline::make::tests::a_capped_draw_waits_once_then_drops`, which passes on its own) beside the order-dependent `watch::tests::ask_once_by_res_splits_reservations_without_refusals` and `texture::ahead::tests::drain_waits_until_then_callbacks_have_run` flakes that #150 is about; `darner-shader` fails `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`, whose fixture #227 fixes. Every other crate passes. This change touches no file of either crate. - Gameplay, when relevant: no gameplay run. This path only runs when `DARNER_WRITE_SITES` names a file or is `auto` *and* the build has known sites; for the title image on this machine the known list is empty, so `darner run <exe> --console series-x` still maps and binds it with `0 missing` for the executable and each title DLL without reaching `apply`. The behaviour being changed is the bound on an operator-supplied list, and the unit test covers it directly. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. Pure arithmetic guard, no GPU and no timing. - Coverage gaps: the reachable trigger is a hand-written `DARNER_WRITE_SITES` file; that file was not produced or applied against a real title, and there is no gameplay run. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay. For this build the write-site list is empty, so a run of the title does not reach `apply`; the new test fails on `main` and passes here, and the guard is arithmetic only. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 555 files ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. No open pull request changes `crates/darner-loader/src/write_sites.rs` (checked against the file list of all 161 open pull requests), and no open or closed issue or pull request body mentions `DARNER_WRITE_SITES` or `write_sites`. - Replaces or overlaps: none found
`write_sites::apply` takes a file name and a hexadecimal offset from a
text file (`DARNER_WRITE_SITES=<file>`) and bounds it with a plain
`offset + 16 > size`. `usize::from_str_radix` accepts any `usize`, so an
offset in `usize::MAX - 15 ..= usize::MAX` overflows that addition: in
the release profiles (release, diag and fast, which inherit it) it wraps
to 15, passes the guard, and `base + offset` wraps to `base - 1`; the
sixteen bytes read there are below the image's first page and the SAFETY
comment on that read ("sixteen bytes inside the image") no longer holds.
In the dev profile the guard itself panics.

`heap_sites` bounds its own site the way this now does, with
`checked_add`, so this is a missed hardening rather than a choice.

The test writes a list naming the image at `usize::MAX` and
`usize::MAX - 7`; it panics on main ("attempt to add with overflow") and
passes here.
TrustNo1 manually merged commit 156b4f817c into main 2026-12-05 04:50:03 +00:00
Sign in to join this conversation.
No reviewers
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
TrustNo1/Darner!371
No description provided.