feat(libkernel): support MIB 1.37 (kern.arandom) in sysctl #3700
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3700"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-11T15:37:46Z.
What
In
libkernel,sysctl_nid_postfixcurrently hard-throws on any MIB other than{6, 3}(HW_NCPU). When running PSBox (PPSA99810) and crypto-seeded engines on Linux, the loader crashes at start-up with:(As observed and confirmed in #3494 by @overlordxrz-source across 14 catalog title runs).
MIB
{1, 37}corresponds to FreeBSD 11's{CTL_KERN, KERN_ARANDOM}(kern.arandom), which is queried byarc4random, LibreSSL/OpenSSL, and game engines to retrieve pseudo-random entropy into caller-supplied buffers.sysctl_nid_postfix:{1, 37}(CTL_KERN, KERN_ARANDOM).newValue != nullptr) withEPERM(1).oldLength == nullptr,kern___sysctlsetsoldlen = 0and the call succeeds returning 0 with no data (matching FreeBSD 11).sysctl_kern_arnd(sys/kern/kern_mib.c), reported size with a null buffer ismin(*oldLength, 256)(0 for*oldLength == 0), rather than a fixed 256.min(*oldLength, 256)viastd::random_device, matchingkern.rng_pseudo, sets*oldLengthto the transferred count, and returns 0.sysctlbyname_nid_postfix:"kern.arandom", delegating to MIB{1, 37}.GuestSystemConfiguration.cpp:oldLengthprobe and read (nullptrlength) succeeding with return 0 and unmodifiederrno."kern.arandom".newValue(EPERM= 1).docs/dev/TechnicalDebt.md.Tested
python tools/check_conventions.py --base origin/mainpasses with 0 findings.git diff --checkpasses with zero whitespace or formatting errors.GuestSystemConfiguration.cppverify: probe size with non-zero input length (64 -> 64, 300 -> 256), probe size with 0 input length (0 -> 0), probe and read witholdLength == nullptrsucceeding with 0, distinct non-repeating entropy streams, buffer size clamping to 256, smaller buffer reads (16 bytes), and write rejection (EPERM= 1).PPSA99810) loader crashsysctl_nid_postfix: unsupported MIB 1.37observed in #3494.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T15:39:54Z.
Review: DISMISSED
Thanks. Build and
guest_system_configurationpass here on the PR merged onto main. Points to fix:SystemConfiguration.cpp:108-111and testGuestSystemConfiguration.cpp:114: the probe is not a fixed 256. FreeBSD 11sysctl_kern_arnd(sys/kern/kern_mib.c) doesread_random(buf, MIN(req->oldlen, sizeof(buf)))andSYSCTL_OUTs that length, so with a null buffer the reported size ismin(*oldLength, 256)(0 for*oldLength == 0). Same for a non-null buffer with a smaller length. Please follow that and change the probe test (use a non-zero input length, add a 0 and a >256 row), and fix the "matching FreeBSD" claim in the description.SystemConfiguration.cpp:104-107: witholdlenp == NULL,kern___sysctlsetsoldlen = 0and the call succeeds with no data, it does not fail withEFAULT. Either follow it, or keepEFAULTand list it in the TechnicalDebt line as a deviation.TestedandChecklistare missing, which is why Conventions fails. Rename "Verification" to### Testedand add the### Checklistsection (no####subheadings inside).Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-11T15:48:12Z.
Thanks for the thorough review and FreeBSD reference, @adriadam10!
All requested points have been addressed in
a640681d9:SystemConfiguration.cppso both null and non-null buffers reportmin(*oldLength, 256)(evaluating to 0 when*oldLength == 0), accurately reflecting FreeBSD 11sysctl_kern_arnd(read_random(buf, MIN(req->oldlen, sizeof(buf)))).GuestSystemConfiguration.cppwith non-zero input length (64 -> 64),>256input length (300 -> 256),0input length (0 -> 0), and a small 16-byte buffer read.oldLength == nullptr):kern___sysctl, whenoldlenp == NULLno data is output and the call succeeds returning 0 (instead ofEFAULT). Added test verification for botholdValue == nullptrand non-nulloldValuewith nulloldLength.docs/dev/TechnicalDebt.mddescription to match.### What,### Tested, and### Checklisttemplate sections.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:16:35Z.
One thing before merging:
SystemConfiguration.cpp:93now checksnewValuebefore the MIB, so an unsupported MIB with a new value returnsEPERMwhere main throwsunsupported MIB. Please keep the check inside the6.3and1.37branches, and rebase the TechnicalDebt line.Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-12T00:32:21Z.
Heads-up from a Windows validation attempt: this branch (
a640681d, basea11c8f7f) no longer merges ontomainbab7b328.SystemConfiguration.cppconflicts with #3779 (merged as22cecd5a:hw.physmem,kern.proc.pathname,machdep.cacheline_size, each with its ownnewValuecheck) because this PR moves thenewValue/EPERMcheck before every MIB, andTechnicalDebt.mdconflicts between neighbouring bullets. Worth a rebase: after #3798, Cloud Play (PPSA99600) also stops on this exact MIB (what(): sysctl_nid_postfix: unsupported MIB 1.37), in addition to ProsperoLichess (PPSA99009), so two catalog titles wait on it.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-12T02:03:32Z.
Hi @adriadam10 and @screamm,
Thank you for the heads-up!
The requested rebase onto latest origin/main (
d371ed307) is now complete on commit 4fa752ef4:ewValue/EPERM validation.
Ready for review and merge to unblock ProsperoLichess (PPSA99009) and Cloud Play (PPSA99600). Thank you!
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T03:02:14Z.
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.
main)docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712docs/dev/TechnicalDebt.mdL712Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T03:21:07Z.
guest_system_configurationaborts on Linux at this head (5d8bfd96), both alone and merged ontomaind146ec1b.mainitself passes. Thelinux/windowsCI jobs are skipped here, so CI didn't catch it.The failing check is
Require(*__error_nid_postfix() == 13);atGuestSystemConfiguration.cpp:229, the last line ofCheckArandomSysctl.errnois still 1 there, from the expectedEPERMof the write case at line 221, and nothing sets it back to 13 before line 229 (found by printing the line inRequire; Ubuntu 24.04, GCC 13).Setting
*__error_nid_postfix() = 13;right after the line-221 check should fix it, the same waymain()resets it between checks.I'll post PSBox (PPSA99810) results for this PR on Linux and Windows separately. On
main, PSBox's next stop is nowkern.arandom.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T05:27:28Z.
PSBox (PPSA99810) results for this PR, with #3494 now on
main:maind146ec1b, Windows 11 (MinGW GCC 15.2): it creates its swapchain, then throwssysctl_nid_postfix: unsupported MIB 1.37.DisplayWindow(the runner has no display).guest_system_configurationfails at the same line 229 as on Linux (0xC0000409), so theerrnoreset above is needed on both. With that one line added locally it passes 5/5 on Linux. No warnings inSystemConfiguration.cpporGuestSystemConfiguration.cpp.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-12T06:39:26Z.
Hi @babyhuey,
Thank you so much for the thorough verification across Linux and Windows 11 with PSBox Cloud Gaming (PPSA99810)!
The fix is now in on commit \
d8b42473d:2ccbd376f).Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-12T07:22:30Z.
Confirmed on
d8b42473, merged ontomain2ca6198e(9fce2f4f):guest_system_configurationpasses 5/5 (--repeat until-fail:5) on Linux and Windows 11, with no warnings in the PR's files.DisplayWindow.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-12T07:46:32Z.
Calling on @adriadam10 and @oneandonlydean for final review and merge into \main\ when ready:
All requested checks are verified and ready for merge into \main! Thank you!