xmem: guard address-space overflow and BTreeMap::range panics across FFI #678
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!678
Loading…
Reference in a new issue
No description provided.
Delete branch "MasterWolf/Darner:pr/post-merge-xmem-overflow-guards"
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?
Not run in the game (verified via
cargo test,cargo clippy, andcargo buildon8aece83; overflow and range-bound guards covered by unit tests).Contributor role (optional)
What it changes
post-merge: read fromcrates/darner-hle/src/modules/xmem.rs(28a9b42):XMemMapPhysicalPagesnever checksn * PAGEorbase + lenbefore passing(base, len)toshown_already,reach,joins, andunmap. In release builds, wrappingbase + lenproducesbase + 1 > endinphysical.views.range(base + 1..end)(unmap) andbase > endinPlaceholders::forget, which panics unconditionally insideBTreeMap::rangeacrossextern "system" fn(aborting the process).XMemMapPhysicalPagesScattercomparesaddress(i + run) as usize == address(i) as usize + run * PAGEwithout checked arithmetic, andmapped_pages/reach/joins/Physical::wantedhave uncheckedat + size/from..torange arithmetic.This PR:
n.checked_mul(PAGE)andbase.checked_add(len)at entry toXMemMapPhysicalPages(returningnull_mut()with a warning on overflow, keepingn == 0returningaddress).saturating_add/checked_addand guardedrange(start..end)(start < end) inreach,unmap,Placeholders::forget,Placeholders::split,mapped_pages,shown_already,joins, andPhysical::wanted.checked_mul+checked_add(next_page_address) inXMemMapPhysicalPagesScatter.usize::MAXboundaryreach/unmap/placeholders, wrapped scatter coalescing, and invertedmapped_pagesranges.How it was tested
8aece83(onpost-merge28a9b42)cargo test --offline -p darner-hle --lib modules::xmem—5 passed; 0 failed(0.00s)cargo clippy --offline -p darner-hle --testsand--features diagnostics --tests --no-deps— passed (0warnings indarner-hle)cargo build --offline -p darner— passed (12.09s)cargo build,cargo test,cargo clippyChecklist
cargo clippy, andcargo build).post-merge.Checked for overlap
[pr-fix][memory] xmem: guard address-space overflow and BTreeMap::range panics across FFIto xmem: guard address-space overflow and BTreeMap::range panics across FFIView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.