Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
MarcZX10:codex/libkernel-rng-pseudo-mib
Oct 20, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
MarcZX10:codex/libkernel-rng-pseudo-mib

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

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

@MarcZX10

Copy link
Copy Markdown
Contributor Author

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 18, 2026
@MarcZX10
MarcZX10 force-pushed the codex/libkernel-rng-pseudo-mib branch from 9e68861 to bb1f502 Compare October 18, 2026 20:25
@MarcZX10

Copy link
Copy Markdown
Contributor Author

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.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 18, 2026

@jotitadev jotitadev 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 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)

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
@MarcZX10
MarcZX10 force-pushed the codex/libkernel-rng-pseudo-mib branch 2 times, most recently from bb1f502 to df30c16 Compare October 19, 2026 14:45
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
@MarcZX10
MarcZX10 force-pushed the codex/libkernel-rng-pseudo-mib branch from 02dd70e to 7e7ba58 Compare October 19, 2026 15:51
@MarcZX10

Copy link
Copy Markdown
Contributor Author

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 adriadam10 self-assigned this Oct 19, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
@adriadam10
adriadam10 force-pushed the codex/libkernel-rng-pseudo-mib branch from 7e7ba58 to a414976 Compare October 20, 2026 10:10
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 20, 2026
@adriadam10
adriadam10 force-pushed the codex/libkernel-rng-pseudo-mib branch from a414976 to 99e87ce Compare October 20, 2026 10:33
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 20, 2026
@adriadam10
adriadam10 merged commit d3633bd into boykopovar:main Oct 20, 2026
10 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

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 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.

3 participants