Repository navigation
fix(libkernel): fail a kern.proc.env read into a buffer with EINVAL, as a PS5 does - #24480
Conversation
…as a PS5 does
A payload process on a PS5 (firmware 11.60) got EINVAL from every read
of {CTL_KERN, KERN_PROC, KERN_PROC_ENV, pid} into a 4096- or 24576-byte
buffer, for its own pid, pid 1, -1 and 0x7fffffff, while the size query
gave 0 for its own pid and ESRCH for -1 (boykopovar#22788). The EINVAL for -1 puts
the check before the pid lookup. The read returned 0 bytes here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 9638f548ef:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_system_configuration_testsbuilt cleanly. - CTest (
guest_system_configuration):1/1 Test #5837: guest_system_configuration ....... Passed 0.05 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libkernel/System/src/SystemConfiguration.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #5837: guest_system_configuration .......Subprocess aborted***Exception: 0.62 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- SystemConfiguration.cpp: verified that sysctl returns EINVAL (errno 22) when oldValue is non-null for KERN_PROC_ENV (nameLength != 4 || oldValue != nullptr), leaving buffer and length unmodified
- SystemConfiguration.cpp: confirmed that write operations continue to be rejected with EPERM (errno 1) via the existing newValue check before the oldValue check
- SystemConfiguration.cpp: confirmed that size queries (oldValue == nullptr) proceed past this check to return length 0 for the calling process, or ESRCH (errno 3) for other processes
- GuestSystemConfiguration.cpp: verified that tests cover the own PID, calling thread ID, foreign PID, and -1 with both buffer size 16 and 1 byte, checking errno 22 and unchanged buffer/length
- Technical debt documentation: confirmed the changes fragment docs/dev/debt/changes/fix-libkernel-sysctl-proc-thread-id-pathname-env-vmmap.md accurately reflects the measured PS5 11.60 behavior
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The change matches the described kern.proc.env behavior: size queries are preserved, while reads with a buffer fail with EINVAL before process ID validation.
What I ran
Reviewed head 9638f548ef39dfaaf00d1752614021910141113e. I read the prepared description, commits, manifest, diff, and all three changed files in full or around the changed lines. No tests or builds were run during this review.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed code | passed | Behavior and tests inspected |
| Tests during review | not run | Author-reported results not independently verified |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports targeted tests and a Linux full ctest run passing, but these were not run during this review. PS5 behavior and Windows/macOS behavior were not verified. files.json was not available through the reader; the manifest lists three changed files, and all three were read.
To get this to a good state
Nothing is required.
|
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) |
|
On Windows the merge passes Existing runs:
What this run adds.
Code.
Not covered by the measurement. The comment behind the fragment says its probes only read
Negative control and mutation.
Probe. A temporary block at the start of
Tests. The pattern
The 11 tests are:
Host:
AI-assisted: yes |
What
sysctl{CTL_KERN,KERN_PROC,KERN_PROC_ENV, pid} with a buffer returned 0 bytes. A payload process on a PS5 (firmware 11.60) gotEINVALfor every such read in xXPBSXx's probes in #22788 (third probe, lines 9 to 16 and 25 to 28 of its output): its own pid, pid 1, -1 and 0x7fffffff, with a 4096- and a 24576-byte buffer, the length left at the buffer size. The size query gave 0 for its own pid andESRCHfor -1, so the check comes before the pid lookup.EINVALbefore the pid check and leaves the buffer and the length alone. A write keepsEPERMand the size query keeps its answers.CheckEnvSysctlinGuestSystemConfiguration.cppreads into a buffer for the own pid, the calling thread's id, another pid and -1.fix-libkernel-sysctl-proc-thread-id-pathname-env-vmmap.mdalready changes thekern.proc.enventry, so it is edited in place.Tested
Linux (Debian 13, GCC 14.2.0, Release). Head
9638f548ef, the single commit onmainc8f72e905c.main84e16538d4,guest_system_configurationaborts.9638f548ef,ctestoverguest_system_configuration,guest_kernel_sysctl_name_bounds,guest_kernel_sysctl_memory_nodes,guest_sce_netandguest_getrlimit: all pass.ctest(6393 tests,-j 12) on this branch and my other eleven branches of this round, merged ontomain84e16538d4: 6378 passed. The 15 failures also fail onmainin this environment:.gitdirectory, network access or a passwd entry for the user:conventions_git_errors,test_script_registration,web_library_assets,title_run,title_run_identity,guest_kernel_sys_login,guest_net_ctl,guest_getloginandguest_getlogin_no_session;agc_driverGPU cases fail the same way onmain:prepared_shaderswith itsindirect,uncachedanddebugforms, andstorage_file_write;agc_driver_image_table_packed_guardsis unstable onmainas well (2 of 10 runs passed on its own onmain3f4693be43).python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch fix/libkernel-sysctl-proc-env-read-einval: no overlap with open pull requests.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)