[pr-fix][memory] hle: a mapping past the top of the address space is refused, not aborted on #411
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!411
Loading…
Reference in a new issue
No description provided.
Delete branch "qnjk/Darner:xmem-unmap-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:
xmemadds two numbers the title supplies and then uses the sum as a map range.map_pagespassesXMemMapPhysicalPages's address and page count, and the page-mapping copies pass their destination and length. A range at the top of the address space wraps that sum;BTreeMap::rangethen panics on a range whose start is above its end, and the panic leaves anextern "system"function, so the process aborts — the test binary dies withthread caused non-unwinding panic. aborting.andSTATUS_STACK_BUFFER_OVERRUN(exit0xc0000409). The comment above the search already saysBTreeMappanics on this shape, but the guard after it only coveredlen == 0.map_pageshas the same shape one step earlier: the page count times the page size can wrap before anything is checked.This change bounds both:
map_pageschecksn.checked_mul(PAGE)andbase.checked_add(len)and answers a range that does not fit with the null it already returns for an unknown page (so the title sees a failed call), andunmapchecks its own sum and returns instead of adding, so no caller — the page-mapping copies included — can handBTreeMap::rangea backwards range. Ranges that fit behave exactly as before, andlen == 0still returns first.How it was tested
41e339c(one commit onf3840d7).cargo test --locked -p darner-hle --lib— 494 passed, 0 failed, 15 ignored, with the new test in the same run.modules::xmem::tests::a_mapping_past_the_top_of_the_address_space_is_refused(xmem.rs:5743): it takes two physical pages fromXMemAllocatePhysicalPages(no adapter and no title, like the neighbouringphysical_pages_map_alias_and_unmap), asksXMemMapPhysicalPagesfor one page at the last page of the address space (usize::MAX & !(PAGE - 1), so address plus page wraps) and asserts null, then assertsXMemMapPhysicalPagesScatterof that page is0, and frees the pages.cargo clippy --locked -p darner-hle --all-targets -- -D warningspasses.usizeis now refused instead of aborting the process.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 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 flakes of #150;darner-shaderfailsemit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders, whose fixture #227 fixes.darner-hle's own suite is green.alias_held'sto < from + len && from < to + len,xmem.rs:2810, andalias_constant'sat = to + k * PAGE,:3124) and inmap_pages'slice::from_raw_parts(pages, n)whenpagesis non-null.unmapcan no longer panic for such a range, but those two can still overflow in a debug build before reaching it; they are a separate change. A page count that sizes aVecbefore validation (:2943) is also deliberately left out.Checklist
mainand passes here.main.docs/asset-policy.md. (cargo xtask policy: 555 files ok.)Checked for overlap
crates/darner-hle/src/modules/xmem.rs. None of their bodies mentionsunmap, a bound on the sum, or a range past the top of the address space. The change is inmap_pagesandunmaponly; conflicts, if any, would be inmap_pages' first lines.