fix(libkernel): support kern.rng_pseudo MIB access #7554

Merged
MarcZX10 merged 2 commits from upstream-pr/7554 into main 2026-10-20 11:06:58 +00:00
MarcZX10 commented 2026-10-18 13:35:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T13:35:06Z.


What

Add the measured kern.rng_pseudo numeric MIB {1, 50} to sysctl and map the name through sysctlnametomib. The PS5 firmware 12.70 payload probe output and sources attached to #7542 show that this numeric path matches the name-based call: a size query reports 64 bytes, reads return up to 64 bytes, a short buffer or a non-null buffer without a length returns ENOMEM, and a null buffer with a null length succeeds. Successful reads preserve errno.

Writes through this MIB were not measured, so they throw. The current generic leaf-MIB handling returns ENOTDIR for a trailing component after {1, 50}. The PS5 response to that longer MIB was not measured, so this is not claimed as console behavior.

The overlap checker reports nearby insertions in #6220, #7070 and #7541, plus the kern.rng_pseudo debt line changed in #7542. These PRs implement separate behavior; I asked their authors to coordinate merge order in comments. This change does not depend on their code.

Tested

Linux: g++ -std=c++20 -fsyntax-only passed for SystemConfiguration.cpp and GuestSystemConfiguration.cpp. A smoke harness compiled and ran the changed implementation, covering name-to-MIB mapping, size query, a 64-byte read, short buffer/ENOMEM, null pointer cases, errno preservation and the trailing-component error.

Not run: the full project build and guest_system_configuration CTest. CMake configuration could not complete in the fresh worktree because the SDL2 submodule is not initialized and this host lacks SDL's XRandR development support.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4909518597 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7554). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T13:35:06Z. --- ### What Add the measured `kern.rng_pseudo` numeric MIB `{1, 50}` to `sysctl` and map the name through `sysctlnametomib`. The PS5 firmware 12.70 payload probe output and sources attached to [#7542](https://github.com/boykopovar/AnyPS5/pull/7542) show that this numeric path matches the name-based call: a size query reports 64 bytes, reads return up to 64 bytes, a short buffer or a non-null buffer without a length returns `ENOMEM`, and a null buffer with a null length succeeds. Successful reads preserve `errno`. Writes through this MIB were not measured, so they throw. The current generic leaf-MIB handling returns `ENOTDIR` for a trailing component after `{1, 50}`. The PS5 response to that longer MIB was not measured, so this is not claimed as console behavior. The overlap checker reports nearby insertions in #6220, #7070 and #7541, plus the `kern.rng_pseudo` debt line changed in #7542. These PRs implement separate behavior; I asked their authors to coordinate merge order in comments. This change does not depend on their code. ### Tested **Linux:** `g++ -std=c++20 -fsyntax-only` passed for `SystemConfiguration.cpp` and `GuestSystemConfiguration.cpp`. A smoke harness compiled and ran the changed implementation, covering name-to-MIB mapping, size query, a 64-byte read, short buffer/`ENOMEM`, null pointer cases, `errno` preservation and the trailing-component error. **Not run:** the full project build and `guest_system_configuration` CTest. CMake configuration could not complete in the fresh worktree because the SDL2 submodule is not initialized and this host lacks SDL's XRandR development support. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-18 14:06:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T14:06:56Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7541 core/libs/prx/libkernel/System/src/SystemConfiguration.cpp L389-390

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 5021 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestSystemConfiguration.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6658 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6977 docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7332 docs/dev/debt/libkernel.md
PR 7437 docs/dev/debt/libkernel.md
PR 7464 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7530 docs/dev/debt/libkernel.md
PR 7605 docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250863216 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7554#issuecomment-6250863216). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T14:06:56Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 7541](https://www.github.com/boykopovar/AnyPS5/pull/7541) | `core/libs/prx/libkernel/System/src/SystemConfiguration.cpp` [L389-390](https://github.com/boykopovar/AnyPS5/blob/01e5f8f199168a5da99b1e846fd70fcf715b986f/core/libs/prx/libkernel/System/src/SystemConfiguration.cpp#L389-L390) | | | 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 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestSystemConfiguration.cpp` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libkernel.md` | | [PR 6519](https://www.github.com/boykopovar/AnyPS5/pull/6519) | `docs/dev/debt/libkernel.md` | | [PR 6658](https://www.github.com/boykopovar/AnyPS5/pull/6658) | `docs/dev/debt/libkernel.md` | | [PR 6740](https://www.github.com/boykopovar/AnyPS5/pull/6740) | `docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `docs/dev/debt/libkernel.md` | | [PR 7049](https://www.github.com/boykopovar/AnyPS5/pull/7049) | `docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `docs/dev/debt/libkernel.md` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `docs/dev/debt/libkernel.md` | | [PR 7437](https://www.github.com/boykopovar/AnyPS5/pull/7437) | `docs/dev/debt/libkernel.md` | | [PR 7464](https://www.github.com/boykopovar/AnyPS5/pull/7464) | `docs/dev/debt/libkernel.md` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `docs/dev/debt/libkernel.md` | | [PR 7530](https://www.github.com/boykopovar/AnyPS5/pull/7530) | `docs/dev/debt/libkernel.md` | | [PR 7605](https://www.github.com/boykopovar/AnyPS5/pull/7605) | `docs/dev/debt/libkernel.md` |
MarcZX10 commented 2026-10-18 14:41:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T14:41:49Z.


Thanks for checking the evidence scope. I updated the description to say the trailing-component ENOTDIR is the current generic leaf-MIB behavior, not a PS5-measured result; the probe only covered the exact {1, 50} MIB. The implementation and smoke test scope are unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251216030 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7554#issuecomment-6251216030). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T14:41:49Z. --- Thanks for checking the evidence scope. I updated the description to say the trailing-component `ENOTDIR` is the current generic leaf-MIB behavior, not a PS5-measured result; the probe only covered the exact `{1, 50}` MIB. The implementation and smoke test scope are unchanged.
MarcZX10 commented 2026-10-18 20:25:26 +00:00 (Migrated from github.com)

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


Rebased onto current main (d17f456eac). The conflict was the new {1,50} handler versus the newer IsLeafMib handling; the rebased code keeps the 64-byte kern.rng_pseudo read and preserves ENOTDIR for a descendant MIB.

Validation on head bb1f502653:

  • Focused Linux smoke exercised the {1,50} size query, short-buffer ENOMEM, sysctlnametomib mapping, descendant ENOTDIR, and rejection of unverified writes: passed.
  • g++ -std=c++20 -fsyntax-only for SystemConfiguration.cpp: passed.
  • git diff --check and tools/check_conventions.py --base upstream/main: passed.
  • Full guest_system_configuration CTest not run: full CMake configuration is blocked by missing SDL2/XRandR development dependencies in this environment.

The rebased commit retains the existing MarcZX100 author identity. Hosted PR checks have not appeared yet.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254733974 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7554#issuecomment-6254733974). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T20:25:26Z. --- Rebased onto current `main` (`d17f456eac`). The conflict was the new `{1,50}` handler versus the newer `IsLeafMib` handling; the rebased code keeps the 64-byte `kern.rng_pseudo` read and preserves `ENOTDIR` for a descendant MIB. Validation on head `bb1f502653`: - Focused Linux smoke exercised the `{1,50}` size query, short-buffer `ENOMEM`, `sysctlnametomib` mapping, descendant `ENOTDIR`, and rejection of unverified writes: passed. - `g++ -std=c++20 -fsyntax-only` for `SystemConfiguration.cpp`: passed. - `git diff --check` and `tools/check_conventions.py --base upstream/main`: passed. - Full `guest_system_configuration` CTest not run: full CMake configuration is blocked by missing SDL2/XRandR development dependencies in this environment. The rebased commit retains the existing MarcZX100 author identity. Hosted PR checks have not appeared yet.
jotitadev commented 2026-10-18 20:39:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T20:39:23Z.

Review: COMMENTED


Reviewed head bb1f50265. One problem in the new test: one check fails at random.

core/libs/tests/GuestSystemConfiguration.cpp:399:

Require(length == 63 && shortBuffer[62] != 0xaa && shortBuffer[63] == 0xaa);

shortBuffer[62] is the last byte copied from std::random_device, so it equals 0xaa with probability 1/256. When it does, guest_system_configuration aborts. The implementation is correct in that case.

I checked it with a standalone copy of the new {1, 50} handler and CopyOut, plus this check, built with Apple clang on arm64 (M2 Max, macOS 27.2). It failed 3995 times in 1,000,000 runs (0.40%, against 1/256 = 0.39%).

The test only needs to show that bytes were copied into the first 63 positions, so something like this would do:

Require(length == 63 && std::any_of(shortBuffer, shortBuffer + 63, [](unsigned char byte) { return byte != 0xaa; }) && shortBuffer[63] == 0xaa);

The other random checks in CheckPseudoRandomMibSysctl (changed over 64 bytes, and the memcmp of two reads) fail with probability around 256^-64. Those are fine.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5564840621 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7554#pullrequestreview-5564840621). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-18T20:39:23Z. **Review:** COMMENTED --- Reviewed head `bb1f50265`. One problem in the new test: one check fails at random. `core/libs/tests/GuestSystemConfiguration.cpp:399`: ```cpp Require(length == 63 && shortBuffer[62] != 0xaa && shortBuffer[63] == 0xaa); ``` `shortBuffer[62]` is the last byte copied from `std::random_device`, so it equals `0xaa` with probability 1/256. When it does, `guest_system_configuration` aborts. The implementation is correct in that case. I checked it with a standalone copy of the new `{1, 50}` handler and `CopyOut`, plus this check, built with Apple clang on arm64 (M2 Max, macOS 27.2). It failed 3995 times in 1,000,000 runs (0.40%, against 1/256 = 0.39%). The test only needs to show that bytes were copied into the first 63 positions, so something like this would do: ```cpp Require(length == 63 && std::any_of(shortBuffer, shortBuffer + 63, [](unsigned char byte) { return byte != 0xaa; }) && shortBuffer[63] == 0xaa); ``` The other random checks in `CheckPseudoRandomMibSysctl` (`changed` over 64 bytes, and the `memcmp` of two reads) fail with probability around 256^-64. Those are fine. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-19 15:51:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T15:51:56Z.


Fixed on rebased head 7e7ba5836c. The short-buffer test now scans all 63 copied bytes for a value differing from the 0xaa sentinel and still checks the byte at index 63 remains untouched, avoiding the prior 1-in-256 false failure. Rebased onto current main (d047690c63) without conflicts; the original implementation commit remains authored by MarcZX100, and the test follow-up is authored by MarcZX10. g++ -std=c++20 -fsyntax-only -Icore/libs core/libs/tests/GuestSystemConfiguration.cpp, the conventions checker, and git diff --check pass. I could not run the full CMake target here: SDL2 lacks its CMake source and XRandR development support is unavailable. Hosted checks for the updated head are pending.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6271338351 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7554#issuecomment-6271338351). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T15:51:56Z. --- Fixed on rebased head `7e7ba5836c`. The short-buffer test now scans all 63 copied bytes for a value differing from the `0xaa` sentinel and still checks the byte at index 63 remains untouched, avoiding the prior 1-in-256 false failure. Rebased onto current `main` (`d047690c63`) without conflicts; the original implementation commit remains authored by MarcZX100, and the test follow-up is authored by MarcZX10. `g++ -std=c++20 -fsyntax-only -Icore/libs core/libs/tests/GuestSystemConfiguration.cpp`, the conventions checker, and `git diff --check` pass. I could not run the full CMake target here: SDL2 lacks its CMake source and XRandR development support is unavailable. Hosted checks for the updated head are pending.
adriadam10 commented 2026-10-20 11:07:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T11:07:31Z.


Rebased onto current main: the only conflict was the kern.rng_pseudo entry in docs/dev/debt/libkernel.md after #7542. I kept main's text and updated its last sentence, since sysctlnametomib and sysctl {1, 50} no longer throw (a write through the MIB still does). The code is unchanged. Re-checked the {1, 50} handler, the sysctlnametomib mapping, the leaf entry and the test; the libkernel tests pass on the rebased head; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289476266 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7554#issuecomment-6289476266). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T11:07:31Z. --- Rebased onto current `main`: the only conflict was the `kern.rng_pseudo` entry in `docs/dev/debt/libkernel.md` after #7542. I kept main's text and updated its last sentence, since `sysctlnametomib` and `sysctl` {1, 50} no longer throw (a write through the MIB still does). The code is unchanged. Re-checked the `{1, 50}` handler, the `sysctlnametomib` mapping, the leaf entry and the test; the libkernel tests pass on the rebased head; merged.
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!7554
No description provided.