fix(libkernel): resolve sysctl top-level names and fail absent top-level MIBs with ENOENT as measured on a PS5 #11170

Merged
orezraey merged 2 commits from upstream-pr/11170 into main 2026-10-26 12:01:03 +00:00
orezraey commented 2026-10-25 20:27:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-25T20:27:52Z.


What

This aligns the sysctl calls with a retail PS5 (firmware 13.60) for absent top-level nodes and top-level names. Measured with a homebrew probe from a payload process; the source and console log are in this gist (pmibunk).

On the console:

  • A MIB under an absent top-level node, {99, 1}, returns -1 with ENOENT and leaves the buffer and length alone. So do unknown MIBs under known nodes: {1, 9999}, {6, 9999}, {0, 9999}, {1, 14, 9999, pid} and 24 levels starting with {1, 9999}.
  • sysctlnametomib("kern") and ("kern.") return 0 with the single level {1}, while sysctlbyname fails both with EINVAL (a one-level MIB).
  • A 1024-byte name gets ENAMETOOLONG (63) from both calls. Here sysctlbyname gave ENOENT.

Changes:

  • sysctl. A MIB whose top-level number is negative or from 10 to 255 now gets ENOENT, with the buffer and length untouched; a write to one still throws. FreeBSD 11 numbers its static top-level nodes 0 to 9 and its dynamic ones from 256 (CTL_AUTO_START), so 10 to 255 cannot exist there.
  • Still throwing. An unimplemented MIB under a known node, or under a node of 256 or more, still throws instead of returning the ENOENT the console gave for {1, 9999} and the others. A MIB that exists on the console but is not implemented here would otherwise fail silently. The debt entry records the measured ENOENT cases.
  • sysctlnametomib. It maps the ten FreeBSD top-level names (sysctl, kern, vm, vfs, net, debug, hw, machdep, user, p1003_1b) to one level. It also drops one trailing dot from any name, as FreeBSD's name2oid does.
  • sysctlbyname. It fails a name of 1024 bytes or more with ENAMETOOLONG first, drops one trailing dot, and fails a top-level name with EINVAL, as FreeBSD's libc does when it passes the one-level MIB to sysctl.

Before and after

Case PS5 AnyPS5 before AnyPS5 now
sysctl {99, 1} (absent top-level node) -1, ENOENT, buffer untouched throws -1, ENOENT, buffer untouched
sysctlnametomib("kern") and ("kern.") 0, {1} -1, ENOENT 0, {1}
sysctlbyname("kern") EINVAL ENOENT EINVAL
1024-byte name ENAMETOOLONG ENOENT from sysctlbyname ENAMETOOLONG
{1, 9999} and other unknown MIBs under a known node ENOENT throws throws (debt)

Tested

guest_system_configuration passes 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and 3 times out of 3 on Linux (WSL, GCC 16.2). The new CheckUnknownRootsAndTopLevelNames covers:

  • roots 99, 10, 255, -1 and -5: ENOENT with the buffer and length untouched (writes below them and reads below roots of 256 or more still throw in the code, but the test does not require it, since those MIB forms are only unimplemented);
  • the ten top-level names with and without a trailing dot, through both calls;
  • hw.ncpu., kern.., ., kern.anyps5.x and kernel;
  • names of 1024 and 1023 bytes.

tools/check_conventions.py passes. Head 82f9806500 on main 74a55da254.

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
  • 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: #10132 (mine, it edits the sysctl debt entries next to the one this PR rewrites) and #9199 (it rewrites the hw.pagesize debt entry right after the one this PR rewrites); merge order only
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5008379874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11170). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-25T20:27:52Z. --- ### What This aligns the `sysctl` calls with a retail PS5 (firmware 13.60) for absent top-level nodes and top-level names. Measured with a homebrew probe from a payload process; the source and console log are in [this gist](https://gist.github.com/orezraey/a9712a4ba480d71c6bff21d5be6cb6ef) (`pmibunk`). On the console: - A MIB under an absent top-level node, `{99, 1}`, returns -1 with `ENOENT` and leaves the buffer and length alone. So do unknown MIBs under known nodes: `{1, 9999}`, `{6, 9999}`, `{0, 9999}`, `{1, 14, 9999, pid}` and 24 levels starting with `{1, 9999}`. - `sysctlnametomib("kern")` and `("kern.")` return 0 with the single level `{1}`, while `sysctlbyname` fails both with `EINVAL` (a one-level MIB). - A 1024-byte name gets `ENAMETOOLONG` (63) from both calls. Here `sysctlbyname` gave `ENOENT`. Changes: - **`sysctl`.** A MIB whose top-level number is negative or from 10 to 255 now gets `ENOENT`, with the buffer and length untouched; a write to one still throws. FreeBSD 11 numbers its static top-level nodes 0 to 9 and its dynamic ones from 256 (`CTL_AUTO_START`), so 10 to 255 cannot exist there. - **Still throwing.** An unimplemented MIB under a known node, or under a node of 256 or more, still throws instead of returning the `ENOENT` the console gave for `{1, 9999}` and the others. A MIB that exists on the console but is not implemented here would otherwise fail silently. The debt entry records the measured `ENOENT` cases. - **`sysctlnametomib`.** It maps the ten FreeBSD top-level names (`sysctl`, `kern`, `vm`, `vfs`, `net`, `debug`, `hw`, `machdep`, `user`, `p1003_1b`) to one level. It also drops one trailing dot from any name, as FreeBSD's `name2oid` does. - **`sysctlbyname`.** It fails a name of 1024 bytes or more with `ENAMETOOLONG` first, drops one trailing dot, and fails a top-level name with `EINVAL`, as FreeBSD's libc does when it passes the one-level MIB to `sysctl`. **Before and after** | Case | PS5 | AnyPS5 before | AnyPS5 now | |---|---|---|---| | `sysctl` `{99, 1}` (absent top-level node) | -1, `ENOENT`, buffer untouched | throws | -1, `ENOENT`, buffer untouched | | `sysctlnametomib("kern")` and `("kern.")` | 0, `{1}` | -1, `ENOENT` | 0, `{1}` | | `sysctlbyname("kern")` | `EINVAL` | `ENOENT` | `EINVAL` | | 1024-byte name | `ENAMETOOLONG` | `ENOENT` from `sysctlbyname` | `ENAMETOOLONG` | | `{1, 9999}` and other unknown MIBs under a known node | `ENOENT` | throws | throws (debt) | ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> `guest_system_configuration` passes 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and 3 times out of 3 on Linux (WSL, GCC 16.2). The new `CheckUnknownRootsAndTopLevelNames` covers: - roots 99, 10, 255, -1 and -5: `ENOENT` with the buffer and length untouched (writes below them and reads below roots of 256 or more still throw in the code, but the test does not require it, since those MIB forms are only unimplemented); - the ten top-level names with and without a trailing dot, through both calls; - `hw.ncpu.`, `kern..`, `.`, `kern.anyps5.x` and `kernel`; - names of 1024 and 1023 bytes. `tools/check_conventions.py` passes. Head `82f9806500` on `main` `74a55da254`. ### 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) - [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: #10132 (mine, it edits the sysctl debt entries next to the one this PR rewrites) and #9199 (it rewrites the `hw.pagesize` debt entry right after the one this PR rewrites); merge order only - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 20:33:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T20:33:05Z.

Review: COMMENTED


Reviewed exact head 65d87b4ecb25878b36a2368bf42850a93e96ffd3.

I checked the probe source/log and the error paths. The PS5 log directly records {99,1} returning ENOENT without changing output/length, unknown children under known roots, top-level kern/kern. name conversion, and the measured length/name cases. The new early return is limited to absent static roots and preserves the existing exception for unimplemented MIBs at 256+; the existing known-name paths run first. The name normalization removes exactly one trailing dot, so repeated dots remain invalid.

Evidence boundary: the supplied console log probes root 99; the behavior for negative roots and the whole 10–255 range is inferred from the FreeBSD static-root / dynamic-root numbering convention and covered by the new local tests, not independently measured on the PS5.

Checks I ran: local conventions pass; git diff --check upstream/main...HEAD passes; the merge preview against current main is clean. The Windows guest_system_configuration results and console measurements in the PR are author-reported. Hosted product jobs are skipped for this PR, and I could not reproduce a local build in this checkout.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645108714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11170#pullrequestreview-5645108714). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T20:33:05Z. **Review:** COMMENTED --- Reviewed exact head `65d87b4ecb25878b36a2368bf42850a93e96ffd3`. I checked the probe source/log and the error paths. The PS5 log directly records `{99,1}` returning `ENOENT` without changing output/length, unknown children under known roots, top-level `kern`/`kern.` name conversion, and the measured length/name cases. The new early return is limited to absent static roots and preserves the existing exception for unimplemented MIBs at `256+`; the existing known-name paths run first. The name normalization removes exactly one trailing dot, so repeated dots remain invalid. Evidence boundary: the supplied console log probes root 99; the behavior for negative roots and the whole 10–255 range is inferred from the FreeBSD static-root / dynamic-root numbering convention and covered by the new local tests, not independently measured on the PS5. Checks I ran: local conventions pass; `git diff --check upstream/main...HEAD` passes; the merge preview against current `main` is clean. The Windows `guest_system_configuration` results and console measurements in the PR are author-reported. Hosted product jobs are skipped for this PR, and I could not reproduce a local build in this checkout.
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!11170
No description provided.