fix(libkernel): fail sysctl and sysctlbyname with EFAULT on an unreadable or unwritable pointer #11264
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11264"
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 Gruzzberry on 2026-10-25T23:01:31Z.
What
sysctlread itsnamearray and itsoldlenplength and wrote its value and the length back through raw guest pointers, so an unreadable or unwritable one crashed the host instead of failing. FreeBSD 11.4'ssys___sysctlrange-checksnamelen(EINVALoutside 2 to 24), copies the name in (copyin,EFAULT), anduserland_sysctlcopies*oldlenpin (EFAULT) before the lookup, so an unreadable name or length fails withEFAULTahead ofENOENTfor an unknown MIB. After the handler,sysctl_old_usercopies the value out (EFAULTfor an unwritableoldpwhen at least one byte fits;ENOMEMwhen the buffer is short, with*oldlenpset to the bytes copied) andsys___sysctlcopies the length out last (EFAULT).sysctlnow does the same withGuestCopyIn_nid_no_patch(new, the read counterpart ofGuestCopyOut_nid_no_patch) andGuestCopyOut_nid_no_patch, in that order, for the shared copy-out helper and forkern.arandom. Results and errnos for readable pointers are unchanged.sysctlbynamecopies its name in withCopyGuestPath_nid_no_patch(EFAULTfor an unreadable or unterminated name,ENAMETOOLONGfrom 1024 bytes, assysctl_sysctl_name2oiddoes forMAXPATHLEN). FreeBSD's libc runsstrlenon that name in user space (sysctlbynamecallssysctlnametomib), so on a console an unmapped name crashes the process instead; failing withEFAULThere avoids crashing the host, as the null-name check already did.sysctlnametomibstill reads its name andsizedirectly, and a new debt entry records it.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, on currentmain.guest_system_configuration: newCheckSysctlPointerFaultsfor an unreadable0x10and a null name, an unreadableoldlenp(with a readable MIB and with the measured-absent MIB{1, 6}, which pinsEFAULTbeforeENOENT), an unreadableoldpwith the length left unchanged, an unreadableoldpwith a zero length (ENOMEM, no fault), anoldlenpon a read-only page (value copied, thenEFAULT; the same with a nulloldp),namelen1 and 25 with an unreadable name (EINVAL), and, onkern.arandom, an unreadableoldpand an unreadableoldlenp; forsysctlbyname, an unreadable0x10name, a null name, a name whose terminator would lie on an inaccessible page, and an unreadableoldpandoldlenpafter a valid name. Onmainthis test segfaults; with this change it passes, three runs out of three.pr_overlap_encoding,agc_host_import_cut_lifetime,agc_driver_depth_plane_partial_store).guest_libc_cnd_timed_wait,guest_pthread_startandvideo_out_flip_eop_aftergpufailed once underctest -j 12and pass alone three times out of three.python tools/check_conventions.py --base upstream/main: passes.Overlaps
GuestCopyIn_nid_no_patchdeclaration and definition, line for line: proposed on it that it goes first and this PR rebases (the duplicate then drops out).memcpyinCopyOutthat this PR replaces, and #11170 edits the testmainlist: proposed on each that it goes first and this PR rebases.Checklist
main; no other open PR implements the same functionNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:03:35Z.
Review: COMMENTED
The sysctl MIB and output-pointer handling is clearly scoped and the Windows regression cases are useful. One remaining related gap:
sysctlbyname_nid_postfixstill dereferences its guestnamewithstrcmpafter checking only for null, before it reaches the checked sysctl path. An unmapped non-null name therefore still faults the host instead of returning-1withEFAULT. Please either copy/validate the guest string before these comparisons (with a bound and a cross-page regression) or explicitly narrow this PR's scope and track the by-name fault separately. This PR is still a draft; I did not cast a formal vote. Localgit diff --checkandtools/check_conventions.pypass; the hosted policy checks were still running at review time.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:19:36Z.
Review: CHANGES_REQUESTED
The new
sysctlMIB path validates its pointers, but the adjacentsysctlbyname_nid_postfixpath still dereferences a non-null guestnamewithstrcmpbefore reaching the checked copy-out code. An unmapped pointer therefore still faults the host, so the stated unreadable-pointer handling is incomplete for the name-based API. Please copy/validate the guest string with a bounded read before comparing it and add an unmapped/cross-page regression, or narrow the PR title and report to the numeric-MIB API and track thesysctlbynamename-pointer fault as explicit debt. The focused Windows tests are author-reported; hosted relinker and sanitizer checks pass, while full product jobs are skipped. I ran exact-headgit diff --checkandtools/check_conventions.py --base upstream/main; both pass. This blocks approval until the exposed scope is accurate and the raw guest dereference is handled or explicitly tracked.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:57:24Z.
Review: CHANGES_REQUESTED
The prior
sysctlbynamename-pointer issue is addressed at this head: the name now goes throughCopyGuestPath_nid_no_patch, with unmapped, null and cross-page-unterminated regressions. Local exact-head convention and whitespace checks pass.Please correct the dependency checklist before approval. The body says #10975, #10921 and #11170 must go first and this PR will rebase, but the checklist says
Depends on: none. All three are still open. I fetched their current heads andgit merge-treereports conflicts between this PR and #10921 inSystemConfiguration.cpp, and between this PR and #11170 in bothSystemConfiguration.cppandGuestSystemConfiguration.cpp; #10975 also supplies the sameGuestCopyIn_nid_no_patchdeclaration/definition this PR adds. Please list the required first PR in theDepends on: #Nchecklist field (and retain any additional ordering detail separately), or rebase/resolve the overlap and update the checklist to match the resulting merge order. The current conventions job is pending; the local convention check passes.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T05:40:37Z.
Review: DISMISSED
The checklist mismatch from my previous review is fixed, and the exact-head Windows/Linux focused test report is now present. I am keeping changes requested only because this head is 1 ahead / 196 behind current main and depends on the still-open #10975, #10921 and #11170 stack. Please refresh onto current main after the required predecessors land, rerun
guest_system_configurationon that exact head, and I will re-review. I found no new source-code issue in the unchanged diff.