test(libkernel): audit sysctl kern.proc.* process, pathname, env, and vmmap bounds #22483

Closed
slopgobblercobbler wants to merge 1 commit from upstream-pr/22483 into main
slopgobblercobbler commented 2026-11-17 17:35:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-11-17T17:35:45Z.


What

Audit libkernel sysctl kern.proc.* process, pathname, env, and vmmap bounds per docs/dev/debt/libkernel.md.

  • Added standalone guest test GuestKernelSysctlProcBounds.cpp auditing sysctl queries across kern.proc.*.
  • Audited pathname MIB {1, 14, 12, pid} accepting self pid and -1 returning /app0/eboot.bin, rejecting foreign/negative pids with ESRCH, short buffer ENOMEM, write rejection EPERM, length bounds, sysctlbyname returning EINVAL, and sysctlnametomib resolving to {1, 14, 12} with size queries and short buffer ENOMEM.
  • Audited proc MIB {1, 14, 8} returning 1088-byte kinfo_proc matching self pid, parent pid, and eboot.bin, short buffer ENOMEM, write rejection EPERM, sysctlbyname parity, and sysctlnametomib.
  • Audited pid MIB {1, 14, 1, pid} accepting only self pid, rejecting foreign pids and -1 with ESRCH, write rejection EPERM, and short buffer ENOMEM.
  • Audited env MIB {1, 14, 35, pid} returning 0 bytes, rejecting foreign pids and -1 with ESRCH.
  • Audited vmmap MIB {1, 14, 32, pid} returning packed 144-byte kinfo_vmentry records with valid structSize/type/start/end bounds, rejecting foreign pids with ESRCH.
  • Audited unsupported MIB throwing runtime_error, MIB length bounds 0, 1, 25, null pointer EFAULT, and sysctlnametomib null pointer checks.
  • Registered test executable guest_kernel_sysctl_proc_bounds_tests in core/libs/prx/libkernel/CMakeLists.txt linked against libkernel, libc, and Windows unwind support.

Tested

  • Built and executed standalone test guest_kernel_sysctl_proc_bounds_tests verifying all assertions pass.
  • Verified conventions via python tools/check_conventions.py --base upstream/main --head HEAD (0 findings).
  • Linux verification by PrivacyOnion: guest_kernel_sysctl_proc_bounds_tests built cleanly and passed (1/1 test passed).

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5361858476 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22483). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-17T17:35:45Z. --- ### What Audit `libkernel` `sysctl` `kern.proc.*` process, pathname, env, and vmmap bounds per `docs/dev/debt/libkernel.md`. - Added standalone guest test `GuestKernelSysctlProcBounds.cpp` auditing `sysctl` queries across `kern.proc.*`. - Audited pathname MIB `{1, 14, 12, pid}` accepting self pid and -1 returning `/app0/eboot.bin`, rejecting foreign/negative pids with `ESRCH`, short buffer `ENOMEM`, write rejection `EPERM`, length bounds, `sysctlbyname` returning `EINVAL`, and `sysctlnametomib` resolving to `{1, 14, 12}` with size queries and short buffer `ENOMEM`. - Audited proc MIB `{1, 14, 8}` returning 1088-byte `kinfo_proc` matching self pid, parent pid, and `eboot.bin`, short buffer `ENOMEM`, write rejection `EPERM`, `sysctlbyname` parity, and `sysctlnametomib`. - Audited pid MIB `{1, 14, 1, pid}` accepting only self pid, rejecting foreign pids and -1 with `ESRCH`, write rejection `EPERM`, and short buffer `ENOMEM`. - Audited env MIB `{1, 14, 35, pid}` returning 0 bytes, rejecting foreign pids and -1 with `ESRCH`. - Audited vmmap MIB `{1, 14, 32, pid}` returning packed 144-byte `kinfo_vmentry` records with valid `structSize`/type/start/end bounds, rejecting foreign pids with `ESRCH`. - Audited unsupported MIB throwing `runtime_error`, MIB length bounds 0, 1, 25, null pointer `EFAULT`, and `sysctlnametomib` null pointer checks. - Registered test executable `guest_kernel_sysctl_proc_bounds_tests` in `core/libs/prx/libkernel/CMakeLists.txt` linked against `libkernel`, `libc`, and Windows unwind support. ### Tested - Built and executed standalone test `guest_kernel_sysctl_proc_bounds_tests` verifying all assertions pass. - Verified conventions via `python tools/check_conventions.py --base upstream/main --head HEAD` (0 findings). - Linux verification by PrivacyOnion: `guest_kernel_sysctl_proc_bounds_tests` built cleanly and passed (1/1 test passed). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-17 17:39:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T17:39:23Z.

Review: CHANGES_REQUESTED


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

  • Conventions: tools/check_conventions.py failed.
    (pull request): error: [pr-template] Fill in the pull request template: answer AI-assisted with yes or no
    (pull request): error: [pr-template] Fill in the pull request template: fill Depends on with #N or none
    2 findings, 2 errors; GitHub shows at most 10 error annotations, the job summary lists all
    
  • Build: guest_kernel_sysctl_proc_bounds_tests built cleanly.
  • CTest (guest_kernel_sysctl_proc_bounds):
    1/1 Test #5625: guest_kernel_sysctl_proc_bounds ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5943528070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22483#pullrequestreview-5943528070). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T17:39:23Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `2c970a1054`: - **Conventions**: `tools/check_conventions.py` failed. ``` (pull request): error: [pr-template] Fill in the pull request template: answer AI-assisted with yes or no (pull request): error: [pr-template] Fill in the pull request template: fill Depends on with #N or none 2 findings, 2 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` - **Build**: `guest_kernel_sysctl_proc_bounds_tests` built cleanly. - **CTest** (`guest_kernel_sysctl_proc_bounds`): ``` 1/1 Test #5625: guest_kernel_sysctl_proc_bounds ... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` Requesting changes for the points above.
PrivacyOnion commented 2026-11-20 17:22:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T17:22:54Z.

Review: CHANGES_REQUESTED


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

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_sysctl_proc_bounds_tests built cleanly.
  • CTest (guest_kernel_sysctl_proc_bounds):
    1/1 Test #5993: guest_kernel_sysctl_proc_bounds ...Subprocess aborted***Exception:   0.36 sec
    0% tests passed, 1 tests failed out of 1
    
    The following tests FAILED:
    

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5996704823 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22483#pullrequestreview-5996704823). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T17:22:54Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `26327d4755`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_kernel_sysctl_proc_bounds_tests` built cleanly. - **CTest** (`guest_kernel_sysctl_proc_bounds`): ``` 1/1 Test #5993: guest_kernel_sysctl_proc_bounds ...Subprocess aborted***Exception: 0.36 sec 0% tests passed, 1 tests failed out of 1 ``` ``` The following tests FAILED: ``` Requesting changes for the points above.
MarcZX10 commented 2026-11-20 17:26:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T17:26:14Z.

Review: APPROVED


Reviewed — looks good

Nothing in the reviewed test and registration changes blocks merge; the assertions align with the documented kern.proc.* behavior.

What I ran

Reviewed head 26327d4755395513964e1e8b7050e128ee1deba0 using the pinned repo_read.py reader. No commands or tests were run; reported test results below are author supplied.

Results

Check Result Note
Diff and changed source review passed Both changed files read
Standalone test execution not run Pass reported in PR description
Conventions check not run Zero findings reported in PR description

Findings

Blocking

None.

Non-blocking

None.

Not verified

The test was not built or executed during this review. The author reports a standalone pass and a Linux CI pass; those results were not independently verified. No other changed files were excluded: both files in the manifest were read. files.json was not available through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5996751009 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22483#pullrequestreview-5996751009). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T17:26:14Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the reviewed test and registration changes blocks merge; the assertions align with the documented `kern.proc.*` behavior. ## What I ran Reviewed head `26327d4755395513964e1e8b7050e128ee1deba0` using the pinned `repo_read.py` reader. No commands or tests were run; reported test results below are author supplied. ## Results | Check | Result | Note | |---|---|---| | Diff and changed source review | passed | Both changed files read | | Standalone test execution | not run | Pass reported in PR description | | Conventions check | not run | Zero findings reported in PR description | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The test was not built or executed during this review. The author reports a standalone pass and a Linux CI pass; those results were not independently verified. No other changed files were excluded: both files in the manifest were read. `files.json` was not available through the reader. ## To get this to a good state Nothing is required.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!22483
No description provided.