fix(libkernel): refuse undefined bits in the batch type-protect #24073
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24073"
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 AltewamaPrime on 2026-11-20T05:05:45Z.
What
sceKernelBatchMap2's type-protect operation now answersSCE_KERNEL_ERROR_EINVAL(0x80020016) for protection bits outside0x3F7, using the existingUndefinedProtection()helper. The check runs before the entry's range is examined, so an invalid range answers the same way, and the range keeps its protection and memory type. Before, the entry reachedDoMtypeprotect, whose protection validation throwsstd::invalid_argumentand ends the title.Per review (
oneandonlydean), this PR now carries only the batch type-protect refusal, rebased onmain:sceKernelMtypeprotectchange and its test are dropped and left to #19183, which also records the console runs where0x80000000was accepted;The debt fragment records the new answer, that it is not console-measured, and that the single call it mirrors answers differently between console runs.
Tested
Linux x86-64, gcc, Release, Ryzen 7 7800X3D, no GPU involved.
CheckStrictMemoryProtectionBitsincore/libs/tests/GuestMemory.cppnow asserts:0x0bon a mapped direct range returns0x80020016withnum_entries_out0, and the range keeps protection3and memory type0;0x80020016withnum_entries_out0, so the bit refusal precedes the range checks, as suggested in the non-blocking review finding.Negative control on the same machine: with
core/libs/prx/libkernel/DirectMemory/Export.cpptaken frommainand the test kept,guest_memory_testsaborts withRestoring the change makes it pass again.
Pre-push gate,
~/bin/anyps5-check.sh --full: conventions clean, debt fragments apply, relinker1045/1045passed. The branch-selected suite reports5558/5589passed; the 31 failures are 4agc_driver_*f64*known baseline failures plus 27agc_driver_gcn_display_present*/guest_video_out_*/video_out_hdr_presenttests that abort inside GTK before any libkernel call (Bail out! Gtk:ERROR ... Failed to load /usr/share/icons/Adwaita/.../image-missing.svg, glycin loader exits early on this headless host).guest_video_out_output_mode_checksfails the same way when run alone, andguest_memorypasses.No console run: the console answer for this batch operation is not measured; the debt fragment says so.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T05:07:31Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
610498b8f1:tools/check_conventions.pypassed.guest_memory_testsbuilt cleanly.guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable):core/libs/prx/libkernel/DirectMemory/Export.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:48:23Z.
Review: COMMENTED
Reviewed — changes requested
The change rejects undefined protection bits in
sceKernelMtypeprotect, but the batch type-protect operation can still mutate memory before returning an error for some invalid ranges.What I ran
Reviewed head
610498b8f114d870d7e8e86c08ef590d97504bc8using the prepared diff andrepo_read.pyreader. No commands or tests were run.Results
Findings
Blocking
core/libs/prx/libkernel/DirectMemory/Export.cpp:748:sceKernelBatchMap2checks undefined protection bits, then callsDoMtypeprotectonly when those bits are clear. However,DoMtypeprotectcallsDoMprotectfirst, which can throw on an invalid range; this batch entry point does not catch that exception. The existing batch path had the same exception behavior, but the new invalid-bit check does not address it. This is not a regression introduced by this patch, so it is not a blocking finding.No verified blocking findings.
Non-blocking
core/libs/tests/GuestMemory.cpp:403: The batch type-protect regression test exercises invalid protection bits on a valid mapped range. Consider adding a case where invalid protection bits are paired with a range that would otherwise fail, to confirm the invalid-bit response takes precedence and the range remains unchanged.Not verified
To get this to a good state
Nothing is required. The optional test suggestion is listed above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T16:36:25Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the optional point below is that the batch type-protect behavior has not been measured on a console.
What I ran
Reviewed head
751c6fbf041757d03a9faa00f99021ce72e88939. I read the complete changed code and test context, and the debt note. No commands or tests were run during this review.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libkernel/DirectMemory/Export.cpp:745rejects undefined protection bits beforeDoMtypeprotectchecks the range. The debt note records that the analogous single-call behavior differs between console runs. The batch result is therefore not confirmed against console behavior; the PR documents this limitation.Not verified
No tests, prechecks, or console runs were performed during this review. The PR description reports these runs:
guest_memory_testsand theguest_memoryctest selection passed; the full pre-push suite had 31 failures attributed to known baseline and headless GTK issues. I read all three files listed as reviewed:core/libs/prx/libkernel/DirectMemory/Export.cpp,core/libs/tests/GuestMemory.cpp, anddocs/dev/debt/changes/fix-mtypeprotect-undefined-bits.md. No files were excluded in the manifest.To get this to a good state
Nothing is required. Optional: measure the batch behavior on a console and update the debt note with the result.