Skip to content

fix(libkernel): return kern.rng_pseudo in 64-byte blocks as measured on a PS5 - #7542

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
ionut27001:fix/libkernel-rng-pseudo-block
Oct 20, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
ionut27001:fix/libkernel-rng-pseudo-block

Conversation

@ionut27001

@ionut27001 ionut27001 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What

sysctlbyname("kern.rng_pseudo") now returns its random bytes in blocks of 64, sized the way a payload process on a PS5 (firmware 12.70) sees them. The 64 random bytes are drawn only for a read that passes both a buffer and a length.

Call Payload process, firmware 12.70 main before this PR
size query (null buffer; presets 0, 1, 64, 77, 100, 4096) 0, length 64 throws
buffer of 64 bytes or more (tried up to 65536) 0, 64 bytes written, length 64 0, the whole buffer filled, length unchanged
buffer smaller than 64 bytes (0, 1, 16, 63) -1 with ENOMEM; that many bytes written, length unchanged 0, the whole buffer filled
buffer with a null length -1 with ENOMEM, nothing written throws
null buffer and null length 0 throws
errno on success kept kept

Each such read takes a new 64-byte block from the host's std::random_device; a write returns EPERM before any byte is drawn. After eight consecutive 64-byte reads on the console, the eight buffers were pairwise different (p24; their return values were not logged and the buffers were not prefilled), and in p16 two reads both returned 0 with length 64 and differed. The block goes out through CopyOut, so every case in the table follows from it. A write still returns EPERM; the probes never write a sysctl, so the console's answer to a write is unknown.

Changes in docs/dev/debt/libkernel.md:

  • The entry said that the console's per-call maximum and its answer to a size query were unknown. It now records the measured sizes.
  • It also says that on the console, MIB {1, 50} from sysctlnametomib answers the same way, while here sysctlnametomib for the name and sysctl {1, 50} still throw.

How the console was measured

  • Setup:
    • The console runs firmware 12.70 and is jailbroken.
    • The probes are ELF payloads built with ps5-payload-dev/sdk v0.44 and clang 18.1.8.
    • They were started through a payload manager, so they ran in a payload process, not in a title.
  • Provenance: the resolve lines of p10 and p16 show that their sysctlbyname (and p16's sysctl and sysctlnametomib) are the ones libkernel_sys.sprx exports; p13 resolves sysctl and sysctlnametomib, and p24 prints no resolve lines. All probes link sysctlbyname the same way.
  • Buffers and counters:
    • The buffers behind last_changed and the changed_in_* counts were prefilled with 0xAA.
    • last_changed is one past the last byte that changed.
    • changed_in_asked counts the changed bytes among the requested ones, and changed_in_64 among the first 64.
  • errno: preset to 77 where the line says errno=77 or errno_after=77.
  • Files: sources and the full logs are in the attached rng-probes.zip.
Console output (excerpt, lines copied unchanged)
p10: meta fw=0x12700001 pid=121 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 18 2026 01:17:42
p13: meta fw=0x12700001 pid=125 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 18 2026 01:52:02
p16: meta fw=0x12700001 pid=128 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 18 2026 02:01:38
p24: meta fw=0x12700001 pid=136 sdk=v0.44 compiler=Clang 18.1.8 built=Oct 18 2026 02:48:52

p16: resolve sym=sysctlbyname module=libkernel_sys.sprx same_as_called=yes
p16: resolve sym=sysctl module=libkernel_sys.sprx same_as_called=yes

p13: case rng_size_query preset=0 ret=0 errno=0 len=64
p13: case rng_size_query preset=4096 ret=0 errno=0 len=64
p24: case rng_errno_size preset=100 ret=0 errno=77 len=64
p13: case rng_read asked=64 ret=0 errno=0 len=64 last_changed=64
p24: case rng_errno_read asked=65 ret=0 errno=77 len=64 changed_in_64=64 last_changed=64
p24: case rng_errno_read asked=4096 ret=0 errno=77 len=64 changed_in_64=64 last_changed=64
p24: case rng_read_65536 ret=0 errno=0 len=64 last_changed=64
p16: case rng_zero_read ret=-1 errno=12 len=0 last_changed=0
p24: case rng_short round=0 asked=1 ret=-1 errno=12 len=1 changed_in_asked=1 last_changed=1
p24: case rng_short round=0 asked=16 ret=-1 errno=12 len=16 changed_in_asked=16 last_changed=16
p24: case rng_short round=0 asked=63 ret=-1 errno=12 len=63 changed_in_asked=63 last_changed=63
p16: case rng_null_oldlenp ret=-1 errno=12 last_changed=0
p24: case rng_errno_null_both ret=0 errno=77
p16: case rng_two_reads ret_a=0 ret_b=0 len_a=64 len_b=64 equal=0
p24: case rng_eight_reads equal_pairs=0

p24: case nametomib2 name=kern.rng_pseudo ret=0 errno=77 count=2 m0=1 m1=50 m2=-1431655766
p16: case rng_mib_read asked=63 ret=-1 errno=12 len=63 last_changed=63
p16: case rng_mib_read asked=128 ret=0 errno=0 len=64 last_changed=64
p16: case rng_mib_size preset=5 ret=0 errno=0 len=64
p24: case rng_mib_null_oldlenp ret=-1 errno=12 last_changed=0
p24: case rng_mib_null_both ret=0 errno=77

The pNN: prefix names the probe; the rest of each line is copied unchanged.

Overlaps:

Tested

Build: Windows 11 x86-64, full build with WinLibs MinGW-w64 GCC 15.2.0 (posix-seh, ucrt, r7) and -DBUILD_TESTING=ON.

Rebase (not re-tested): after #6833 landed, this branch was rebased onto main bbb4546. The only conflict was in docs/dev/debt/libkernel.md, where #6833 changed the sysconf line right after this PR's kern.rng_pseudo line; the resolution keeps both. The code and test changes are the same as before the rebase, and the tests above were not run again on the new base.

Tests: with this branch on top of main 9f25d0b, guest_system_configuration and the other guest_* tests pass: 464 of 465 pass and guest_video_out_wqhd_detection_no_vulkan is skipped on this machine. The branch was then rebased onto main 5bf2e13 without conflicts, since upstream changed none of its code or test files, and guest_system_configuration passes there too.

Old code, new test: with SystemConfiguration.cpp reverted to main and the new test kept, guest_system_configuration aborts.

Console: behaviour measured on a PS5 (firmware 12.70), as described above.

Not tested: Linux, and no title. The only caller the debt entry names, mbedTLS in the ProsperoLight boilerplate, asks for 64-byte blocks, and a 64-byte request still gets 64 bytes.

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

🤖 Generated with Claude Code

@MarcZX10

Copy link
Copy Markdown
Contributor

I'm preparing a separate PR for measured kern.rng_pseudo MIB {1,50} support and its sysctlnametomib mapping. The overlap checker flags nearby insertion points in SystemConfiguration.cpp and GuestSystemConfiguration.cpp; the behavior is separate, but rebasing may need small conflict resolutions. Which PR should land first, or are you comfortable with this one landing first?

@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 7554 docs/dev/debt/libkernel.md L19

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

Update: the separate numeric kern.rng_pseudo MIB PR is now open as #7554. It handles the measured {1,50} access shape, distinct from this PR’s 64-byte name-query block behavior. The changes are independent; whichever lands second may need a small rebase conflict resolution.

@ionut27001

Copy link
Copy Markdown
Contributor Author

Either order is fine. The real conflict is the kern.rng_pseudo debt line, which both PRs rewrite: this one describes the 64-byte sysctlbyname behaviour and says sysctlnametomib and sysctl {1, 50} throw, while #7554 keeps the old sysctlbyname text. Whichever lands second should merge them (name path from here, MIB path from #7554, without the "throw" clause). I'll do it on my side if #7554 lands first. One note on #7554, since it cites these logs: the probes only called the two-word MIB {1, 50}, so ENOTDIR for a trailing component was not measured.

@MarcZX10

Copy link
Copy Markdown
Contributor

Thanks for catching the probe scope. I corrected #7554’s description: it now attributes the trailing-component ENOTDIR result to current generic leaf-MIB handling and explicitly says that longer MIB was not measured on PS5. Your note about resolving the shared debt line after merge still applies.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
…on a PS5

In a payload process on a PS5 (firmware 12.70),
sysctlbyname("kern.rng_pseudo") answers a size query with 64 and gives
at most 64 bytes per call, up to a 65536-byte buffer. A buffer smaller
than 64 bytes gets as many bytes as its length and a null length gets
none, both with -1 and ENOMEM; a null buffer with a null length returns
0, and errno is kept when the call succeeds. Here the whole buffer was
filled, a size query threw and the length was never changed. The 64
random bytes are now drawn only for a read that passes both a buffer
and a length.

AI-assisted: yes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ionut27001
ionut27001 force-pushed the fix/libkernel-rng-pseudo-block branch from 6df22de to dca67ae Compare October 19, 2026 12:00
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit 9299e6f into boykopovar:main Oct 20, 2026
11 of 12 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked CopyOut against each row of the console table (size query, 64+ bytes, short buffer, null length, null/null, errno kept), the test (fails on main: whole buffer filled / throws) and the debt entry; 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