fix(libkernel_sys): fail kenv set and unset with EPERM for a jailed caller #15025
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15025"
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-11-02T10:50:30Z.
What
kenv(KENV_SET, ...)andkenv(KENV_UNSET, ...)kept an in-memory environment and succeeded. FreeBSD 11.4'ssys_kenvcallspriv_check(td, PRIV_KENV_SET)orpriv_check(td, PRIV_KENV_UNSET)before it copies the name in, andprison_priv_checkdoes not list either privilege, so a jailed caller reachesdefault: return (EPERM). A title runs as jailed uid 0 (the credential model agreed on #11216).Both operations now fail with
EPERMwithout touching the name argument, so a null or0x10name givesEPERMtoo, as the source order says.KENV_DUMPstill returns 0 for any arguments, andKENV_GETstill copies the name in first (EFAULT,ENAMETOOLONG) and then givesENOENT. An unknownwhatvalue givesEINVALafter the same name copy-in. The environment is empty and cannot be changed, so the table, its mutex and its entry limit are removed.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, on currentmain(rebased).guest_kernel_sys:SETandUNSETgiveEPERMfor a valid name, a null name, a0x10name and an over-long name, andGETis stillENOENTafterwards;DUMP,GETand the unknownwhatchecks are as listed above. Withmain'sExport.cppthe test aborts; with this change it passes, three runs out of three.vulkan_validation_gate_reportsandresponse_text_mode, which fail onmainin this environment too.python tools/check_conventions.py --base upstream/main: passes.prison_priv_checkand has not been measured on a console; the debt entry indocs/dev/debt/libkernel_sys.mdsays so.Overlaps
tools/pr_overlap.pycould not compare this branch against 12 older pull requests (#5021, #9097, #9297, #9302, #9389, #9713, #11212, #12642, #12925, #13129, #13253, #13256) because each already conflicts withmainon its own. None of their diffs mentionskenvorKernelEnv, so no overlap is known.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 BunnyFl on 2026-11-02T11:20:55Z.
Review: APPROVED
Looks right to me against the cited FreeBSD 11.4 source (
release/11.4.0):sys_kenv,KENV_DUMPreturns before anything else.KENV_SET/KENV_UNSETcallpriv_check(td, PRIV_KENV_SET/UNSET)and return on error before thecopyinstrof the name, so a null or0x10name givingEPERMfollows the source order.KENV_GETcopies the name first (EFAULT/ENAMETOOLONG) and then givesENOENT. An unknownwhatreachesdefault: EINVALafter the copy.kern_jail.chas noPRIV_KENV_*case inprison_priv_check, so a jailed uid 0 falls through toEPERM.Tested on Windows 11, WinLibs GCC 15.2.0, Release, with head
683fa0329cmerged ontomain:guest_kernel_syspasses.libkernel_sys/Export.cppput back tomain's version, it fails in the new SET/UNSET checks (Kernel sys check failed … guest errno 14, whereEPERMwas expected).Non-blocking: DUMP returning 0 and GET returning
ENOENTboth rest on the environment being empty, whichmainalready assumed. On FreeBSD a jailed process can still read the host's kernel environment, so a console could report loader entries here. That, and Sony changes tosys_kenv, aren't settled without a console run. It might be worth one line in the debt entry.