Skip to content

fix(libkernel): fail kern.proc.pathname with ENOENT, as a PS5 does - #24481

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
brajankw:fix/libkernel-sysctl-proc-pathname-enoent
Nov 28, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
brajankw:fix/libkernel-sysctl-proc-pathname-enoent

Conversation

@brajankw

Copy link
Copy Markdown
Contributor

What

sysctl {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid} returned /app0/eboot.bin for -1 and the calling process, following FreeBSD's sysctl_kern_proc_pathname, and ESRCH for other pids. A payload process on a PS5 (firmware 11.60) got ENOENT in xXPBSXx's first probe in #22788 (lines 4 to 11 of its output) for pid -1, its own pid, pid 1 and 0x7fffffff, for a size query and for 1,024- and 1-byte buffers, with the buffer and the length left alone, and EPERM for a write. ENOENT for a pid that does not exist puts the answer before the pid lookup.

  • The node now fails with ENOENT for any pid and leaves the buffer and length alone. A write keeps EPERM, and a MIB without exactly one pid keeps EINVAL, which was not measured.
  • feat(libkernel): handle sysctl queries for pathname, physmem and cacheline size #3779 added the path for XPSemu (PPSA97358), whose start-up stopped on the throw for this unsupported MIB. QEMU's qemu_init_exec_dir falls back to realpath(argv[0]) when this sysctl fails, as it must on the console. XPSemu was not run here.
  • Whether a title process gets the same answer is not measured; the debt entry says so.
  • Tests: CheckPathnameSysctl and the sysctlnametomib check in GuestSystemConfiguration.cpp.
  • Debt: the kern.proc.pathname entry is replaced.

Tested

Linux (Debian 13, GCC 14.2.0, Release). Head da869b00d5, the single commit on main c8f72e905c.

  • Negative control: with only the test change, on main 84e16538d4, guest_system_configuration aborts.
  • On da869b00d5, ctest over guest_system_configuration, guest_kernel_sysctl_name_bounds, guest_kernel_sysctl_memory_nodes, guest_sce_net and guest_getrlimit: all pass.
  • Full ctest (6393 tests, -j 12) on this branch and my other eleven branches of this round, merged onto main 84e16538d4: 6378 passed. The 15 failures also fail on main in this environment:
    • nine need a .git directory, 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_getlogin and guest_getlogin_no_session;
    • five agc_driver GPU cases fail the same way on main: prepared_shaders with its indirect, uncached and debug forms, and storage_file_write;
    • agc_driver_image_table_packed_guards is unstable on main as well (2 of 10 runs passed on its own on main 3f4693be43).
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch fix/libkernel-sysctl-proc-pathname-enoent: no overlap with open pull requests.
  • Not tested on Windows or macOS. No title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

A payload process on a PS5 (firmware 11.60) got ENOENT from
{CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid} for pid -1, its own pid,
pid 1 and 0x7fffffff, for a size query and for 1,024- and 1-byte
buffers, with the buffer and the length left alone, and EPERM for a
write (boykopovar#22788). ENOENT for a pid that does not exist puts the answer
before the pid lookup. The tree returned /app0/eboot.bin, following
FreeBSD's sysctl_kern_proc_pathname, and ESRCH for other pids. A MIB
without exactly one pid keeps EINVAL, which was not measured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against da869b00d5:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_system_configuration_tests built cleanly.
  • CTest (guest_system_configuration):
    1/1 Test #5837: guest_system_configuration .......   Passed    0.07 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/System/src/SystemConfiguration.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5837: guest_system_configuration .......Subprocess aborted***Exception:   0.53 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified sysctl_nid_postfix kern.proc.pathname handling (nameLength == 4 && name[0] == 1 && name[1] == 14 && name[2] == 12) returns -1 with *__error_nid_postfix() = 2 (ENOENT) for all pid inputs without modifying oldValue or oldLength, consistent with hardware probe observations.
    • Verified validation ordering in sysctl_nid_postfix: length bounds check (nameLength < 2 || nameLength > 24), GuestCopyIn_nid_no_patch for name, newValue check for EPERM (__error_nid_postfix() = 1) and nameLength != 4 check for EINVAL (__error_nid_postfix() = 22) are evaluated before returning ENOENT.
    • Verified technical debt documentation: new fragment docs/dev/debt/changes/fix-libkernel-sysctl-proc-pathname-enoent.md correctly documents the ENOENT behavior and hardware probe source per AGENTS.md requirements.
    • Verified test coverage in core/libs/tests/GuestSystemConfiguration.cpp: CheckPathnameSysctl and CheckNameToMib thoroughly test mibSelf, callerPid, scePthreadGetthreadid, foreign pid, absent pid (0x7fffffff), size query, buffer capacities, write rejection (EPERM), and length/buffer preservation.
    • Verified compliance with AGENTS.md rules: no prohibited comments added, no hardcoded title workarounds, no extra unapproved files.

Looks Good To Me

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The change matches the stated ENOENT behavior for the pathname MIB, preserves validation and write handling, and the inspected code and reported checks support merging.

What I ran

Reviewed head da869b00d5339b5c9edd3ab3a126e100489688ea using the prepared diff.patch, manifest.json, and the pinned repository reader. No tests or build commands were run during this review.

Results

Check Result Note
Changed-code review passed Three changed files read
Tests not run Reported results are author supplied
Full-text coverage passed All manifest files included and read

Findings

Blocking

None.

Non-blocking

None.

Not verified

Did not independently verify the PS5 firmware measurement, run the reported test suite, or test Windows/macOS or a title process. files.json was unavailable in the prepared review folder; the manifest lists three included files, and all three were read.

To get this to a good state

Nothing is required.

@Helldiverr

Copy link
Copy Markdown
Contributor

Reviewed da869b00d5, merged onto main 38d22efc06 as 219f693833, on Windows, which the description lists as untested. I found nothing blocking. On Windows the node fails with ENOENT for every pid in the test, leaves the buffer and the length alone, and keeps EPERM for a write and EINVAL for a MIB without exactly one pid. One debt line elsewhere still describes the old value.

All line numbers here are at the head da869b00d5. The test file is the same at the head and on the merge.

The measurement matches the change. Lines 4 to 11 of the first probe output in #22788 show errno=2 for pid -1, the own pid, pid 1 and 0x7fffffff with a 1,024-byte buffer, for a size query with a NULL buffer (len=0), and for a 1-byte buffer that leaves the length at 1 with nothing written. A write with a non-NULL new value gives errno=1. These are the cases the new code returns (core/libs/prx/libkernel/System/src/SystemConfiguration.cpp:485-496): EPERM for a write (:486-489), EINVAL when the MIB length is not 4 (:490-493), and otherwise ENOENT (:494-495).

Non-blocking: the kern.proc.pid debt entry still refers to the old value. docs/dev/debt/libkernel.md:278 says the record holds ki_comm "(eboot.bin, the base name of the kern.proc.pathname value)". After this change kern.proc.pathname has no value. ki_comm is still eboot.bin (SystemConfiguration.cpp:227), so only the parenthetical is stale. A change for that entry in the same fragment could drop it.

Runs. ctest --test-dir build -R "^guest_(system_configuration|kernel_sysctl_name_bounds|kernel_sysctl_memory_nodes)$" -V

test main merge 1 2 3
guest_system_configuration Passed 0.46 s Passed 0.47 s Passed 0.41 s Passed 0.41 s
guest_kernel_sysctl_name_bounds Passed 0.05 s Passed 0.04 s Passed 0.03 s Passed 0.03 s
guest_kernel_sysctl_memory_nodes Passed 0.07 s Passed 0.06 s Passed 0.03 s Passed 0.03 s

On the merge, tools/check_conventions.py --base 38d22efc06 passes and tools/debt_fold.py --check exits 0.

Negative control. I reverted the SystemConfiguration.cpp change and kept the new test. guest_system_configuration then fails 3/3. Require calls std::abort without a location, so for one more run I changed it to throw with the caller's line, which changes no line numbers. That run fails at the size query in the pid loop (core/libs/tests/GuestSystemConfiguration.cpp:288). With the same change and no mutation, the test passes.

Mutations. Each runs once with the line-reporting Require:

mutation in SystemConfiguration.cpp guest_system_configuration
ESRCH for a pid other than -1 and the caller, as before fails at :288
*oldLength = 0 before the ENOENT return fails at :294
EINVAL instead of ENOENT at :494 fails at :288
length check at :490 disabled fails at :267
write check at :486-489 removed fails at :275

The test line numbers are in core/libs/tests/GuestSystemConfiguration.cpp: :267 is the EINVAL check after sysctlbyname("kern.proc.pathname"), :275 is the write with the 3-element MIB, :288 is the size query and :294 checks that the length and the buffer are untouched.

I did not run XPSemu (PPSA97358), so I have not checked the realpath(argv[0]) fallback the description expects.

Host:

  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2.0 (UCRT, POSIX threads, SEH) r7, Release

AI-assisted: yes

@brajankw
brajankw force-pushed the fix/libkernel-sysctl-proc-pathname-enoent branch 2 times, most recently from 224732c to da869b0 Compare November 24, 2026 13:47
@brajankw

Copy link
Copy Markdown
Contributor Author

@Helldiverr Agreed, the parenthetical is stale, but I left it as it is for now, because fixing it here would make this PR conflict with #22788.

@github-actions

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 18190 core/libs/prx/libkernel/System/src/SystemConfiguration.cpp

@oneandonlydean
oneandonlydean merged commit 9fb1816 into boykopovar:main Nov 28, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants