fix(libc): reject overflowing mspace resizes #1110
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1110"
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?
Imported from boykopovar/AnyPS5. Originally posted by Sanjaysrinivas on 2026-10-07T12:47:53Z.
What
sceLibcMspaceReallocandsceLibcMspaceReallocalignround sizes to 16 bytes before checking whether an existing chunk can hold them. NearSIZE_MAX, that rounding wraps to zero: both exports return the original pointer as success and replace its requested-size metadata with a value the allocation cannot hold. A later relocating resize uses that metadata as a copy length.Reject rounding overflow with guest ENOMEM before either fast path updates the chunk. This follows the overflow check already present in
Allocate, without changing normal allocation, zero-size or alignment handling.Extend the existing Mspace regression to reject
SIZE_MAXthroughSIZE_MAX - 15for both resize exports, checking errno, original contents, usable capacity and usage/peak statistics. Its existing relocating growth immediately afterward also verifies the allocation remains usable.Tested
Earlier focused validation of the unchanged contribution patch:
Ubuntu 24.04 under WSL2, GCC 13.3.0, x86-64:
mspaceandguest_reallocalignpass three consecutive runs each. Five neighboring native save tests also pass.Mspace.cppand regression pass with AddressSanitizer and UndefinedBehaviorSanitizer,-Wall -Wextra -Werror -pthread, and a local thread-local errno provider.git diff --checkpasses.With the full repository configured and built with
BUILD_TESTING=ON:No affected retail title or exploitation is claimed. Local validation helpers and investigation notes are excluded from the patch. Full-build results and remaining platform limits are recorded below.
PR overlap (earlier checks)
Direct per-file three-way merge checks confirm a conflict with the whole-tree formatting PR #1128 in
core/libs/prx/libc/src/Mspace.cpp. That PR does not implement this bug fix. #1128 currently conflicts with upstream inStdioExtras.cpp, so the repository overlap tool skips its pairwise conflict check; its empty result does not clear this overlap. This PR merges cleanly into upstream1e5bb880; merging it and #1128 will require rebasing whichever lands second.Earlier local validation after rebase
Rebased onto upstream
mainatcea1ef13. Tested head:bc1f7e694e02f4bd63fa718295860a71dfe7a07b.Ubuntu 24.04 under WSL2, GCC 13.3, Release; the contribution patch is preserved and its tree matches the checked merge result.
git diff --checkpassed.BUILD_TESTING=ON.Title/homebrew execution remains untested. The GitHub-hosted fork checks below are separate from these local results.
Independent fork CI
Build run 37676602286 passed on exact PR head
131e05a26bea1775cbb990224501aa255c7389d7.Rebased onto upstream
mainat4764e59c37b1fc6c89284fdecaef5a5718b6119e. The unchanged contribution's source tree matches the checked automatic merge result; conventions andgit diff --checkpassed.Both jobs completed the full Release CMake build with
BUILD_TESTING=ON, thelibstarget and the full CTest suite with--timeout 120 --repeat until-fail:3.guest_force_tls_destructorregression passed in all three Linux repetitions.These fork checks do not replace upstream workflow approval or maintainer review. No title/homebrew execution or RDNA hardware measurement is claimed.
Checklist
mainat4764e59c; no other open PR implements the same fixImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T06:46:39Z.
Checked the overflow guard in both resize exports against
Allocate, ranmspaceon the merge with current main (passes; fails with the Mspace.cpp change reverted), CI green on this head. Merging.