Repository navigation
fix(libkernel): refuse undefined bits in the batch type-protect - #24073
oneandonlydean merged 1 commit into
Conversation
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 610498b8f1:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_memory_testsbuilt cleanly. - CTest (
guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable):1/3 Test #5849: guest_mmap_executable ............ Passed 0.01 sec 2/3 Test #5848: guest_mmap_fixed_anonymous ....... Passed 0.01 sec 3/3 Test #5847: guest_memory ..................... Passed 1.77 sec 100% tests passed, 0 tests failed out of 3 - Negative control: with
core/libs/prx/libkernel/DirectMemory/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/3 Test #5849: guest_mmap_executable ............ Passed 0.01 sec 2/3 Test #5848: guest_mmap_fixed_anonymous ....... Passed 0.01 sec 3/3 Test #5847: guest_memory .....................Subprocess aborted***Exception: 0.17 sec 67% tests passed, 1 tests failed out of 3 - Code reading:
- Verified sceKernelMtypeprotect rejects prot with bits outside DefinedProtection (0x3F7) returning SCE_KERNEL_ERROR_EINVAL (0x80020016) before invoking DoMtypeprotect when len > 0.
- Verified sceKernelBatchMap2 OpTypeProtect check in Export.cpp:748 correctly inspects entry.protection and rejects invalid bits with SCE_KERNEL_ERROR_EINVAL while OpProtect masks bits against DefinedProtection.
- Inspected cast safety and range checking: static_cast(static_cast<uint8_t>(entry.protection)) properly zero-extends char to uint8_t and preserves bits for comparison against ~DefinedProtection.
- Verified AGENTS.md compliance: conventions passed, no banned comments added, technical debt fragment created under docs/dev/debt/changes/ with valid format, and GuestMemory.cpp tests assert both return codes and memory state invariants.
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
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 610498b8f114d870d7e8e86c08ef590d97504bc8 using the prepared diff and repo_read.py reader. No commands or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed source | passed | All three changed files read |
| Tests | not run | No test run in this review |
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
- Test results reported in the PR description, including the negative control and pre-push gate, were not run independently.
- Console behavior and the asserted batch-operation behavior were not verified on hardware.
- Excluded files: none listed; all three changed files in the manifest were read.
To get this to a good state
Nothing is required. The optional test suggestion is listed above.
|
@AltewamaPrime I compared this with #19183, which already refuses undefined bits in sceKernelMtypeprotect and records two console runs in which 0x80000000 was accepted, so the INT_MIN case in this test pins an answer the console does not give. Could you drop the sceKernelMtypeprotect part and its test here and leave it to #19183? The batch protect mask at Export.cpp:745 is also the same change as #22051. That leaves the batch type-protect refusal; please use the existing |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
A batch map type-protect entry passed its protection to DoMtypeprotect, whose protection validation throws std::invalid_argument for bits outside 0x3F7, so an undefined bit ended the title instead of returning an error. The entry now answers SCE_KERNEL_ERROR_EINVAL (0x80020016) through the existing UndefinedProtection() helper, before its range is looked at, and leaves the range untouched. The single sceKernelMtypeprotect change and the batch protect masking are left to boykopovar#19183 and boykopovar#22051.
610498b to
751c6fb
Compare
|
Done, rebased on
The debt fragment records that this answer is not console-measured and that the single call it mirrors differs between console runs. Evidence and the negative control are updated in the description. |
MarcZX10
left a comment
There was a problem hiding this comment.
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
| Check | Result | Note |
|---|---|---|
| Source review | passed | All changed files read |
| Tests | not run | Results in the PR description are author-reported |
| Console behavior | not run | Batch behavior is unmeasured |
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_tests and the guest_memory ctest 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, and docs/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.
|
Retested the new head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole tree: the full This run is for this PR alone, not a combined tree. I did not run a negative control (the new test against AI-assisted: yes (Claude Code) |
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 fix(kernel): sceKernelMtypeprotect refuses memory types 10, 127 and -1 and undefined protection bits #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)