[pr-fix][startup] loader: a write site past the end of the address space is not read #371
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
hle
input
INTEL
lighting
linux-proton
memory
MULDER
needs-info
needs-logs
needs-rebase
NVIDIA
performance
post-merge
pr-diagnostics
pr-docs
pre-merge
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
relevance
high
relevance
low
relevance
medium
relevance
very-high
rendering
report
roadmap-proposal
saves
series-s
shaders
startup
status
blocked-by-rework
status
needs-test-report
status
needs-triage
status
ready-for-review
status
stale
status
superseded
status
wip
tools
ui
upstream
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
TrustNo1/Darner!371
Loading…
Reference in a new issue
No description provided.
Delete branch "qnjk/Darner:loader-write-sites-overflow"
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?
Contributor role (optional)
What it changes
The problem on main:
write_sites::applyreads a file name and a hexadecimal offset from a text file (DARNER_WRITE_SITES=<file>) and bounds the offset with a plain addition:(
crates/darner-loader/src/write_sites.rs:242and:245).usize::from_str_radixaccepts anyusize, so a line such ast.dll ffffffffffffffffoverflows that addition. In the dev and test profiles the guard panics (attempt to add with overflow). In therelease,diagandfastprofiles, which inheritrelease's overflow settings,offset + 16wraps to15, the guard15 > sizeis false,base + offsetwraps tobase - 1, and sixteen bytes are read one page below the image and then run throughstub/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'sheap_sitessibling already bounds its site withchecked_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), mirroringheap_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 onf3840d7).Commands and results:
cargo test --locked -p darner-loader --lib— 93 passed, 0 failed.write_sites::tests::an_offset_past_the_end_of_the_address_space_is_not_readwas also run against the same tree with only the guard put back tooffset + 16: it fails there withpanicked at crates/darner-loader/src/write_sites.rs:247: attempt to add with overflow, and passes with the change. The test needs no fixture: itVirtualAllocs 64 KiB and passes a two-line list naming the image atusize::MAXandusize::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:
cargo clippy --workspace --all-targets --locked -- -D warnings: passes.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.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-gpustands 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-dependentwatch::tests::ask_once_by_res_splits_reservations_without_refusalsandtexture::ahead::tests::drain_waits_until_then_callbacks_have_runflakes that #150 is about;darner-shaderfailsemit::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_SITESnames a file or isautoand the build has known sites; for the title image on this machine the known list is empty, sodarner run <exe> --console series-xstill maps and binds it with0 missingfor the executable and each title DLL without reachingapply. 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_SITESfile; that file was not produced or applied against a real title, and there is no gameplay run.Checklist
apply; the new test fails onmainand passes here, and the guard is arithmetic only.main.docs/asset-policy.md. (cargo xtask policy: 555 files ok.)Checked for overlap
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 mentionsDARNER_WRITE_SITESorwrite_sites.`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.