feat(libkernel_sys): implement mount, unmount and nmount privilege checks #15037
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15037"
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-02T11:26:46Z.
What
mountandunmount(libkernel_sys) were stubs that threw, andnmount(libkernel) threw too. They now follow FreeBSD 11.4 for a jailed caller. The credential model is the one agreed on #11216: a title runs as jailed uid 0, andprison_priv_checkrefusesPRIV_VFS_MOUNTandPRIV_VFS_UNMOUNTwithoutallow.mount, which the default jail parameters leave off.unmount(path, flags):sys_unmountcallspriv_check(PRIV_VFS_UNMOUNT)before it copies the path in, so every argument (null, an invalid pointer, empty, too long, any flags) givesEPERM.nmount(iov, niov, flags), in the order ofsys_nmount,copyinuio,vfs_buildopts,vfs_sanitizeoptsandvfs_donmount: an odd or short (under 4) count or more than 1024 vectors givesEINVAL; an unreadable vector array, name or value givesEFAULT; names and values (plus 48 bytes per option) over 64 KiB, or a name that is empty or not NUL terminated, giveEINVAL; for a repeated option only the last survives, withvfs_equaloptsported as it is (noprefixes, dotted names,ro/rw); a missing, empty or unterminatedfstypeorfspathgivesEINVALand writesInvalid fstypeorInvalid fspathinto anerrmsgvalue; a type over 16 bytes or a path over 88 bytes givesENAMETOOLONG. Everything else givesEPERM, becausevfs_domountchecks the privilege before it looks the type up.mount(type, path, flags, data):sys_mounthas no privilege check beforecopyinstr(type, MFSNAMELEN), so the type is copied with the 16-byte bound (EFAULT,ENAMETOOLONG) and an empty type givesENOENT. Any other type throws: which file systems are registered and each one's argument copy-in come before theEPERMinvfs_domountand are not modelled.Debt entries are in
docs/dev/debt/libkernel.md(nmount, rewritten) andlibkernel_sys.md(mount and unmount). The jail model is not measured on a console.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, on currentmain.guest_kernel_sys(null,0x10and an unreadable page formount; every path and flag forunmount) andguest_filesystem(CheckNmount: eachEINVAL,EFAULTandENAMETOOLONGboundary, the 64 KiB total at exactly the limit and one over, duplicate andnooptions,errmsgwrites) pass three runs out of three. Onmainthe new test cannot build:mountandunmountare declared with no arguments there.vulkan_validation_gate_reportsandcheck_compile_test_windows_gcc_response_text_mode_is_not_reinterpreted, which fail the same way onmainhere (the Windows Store python stub).python tools/check_conventions.py --base upstream/mainpasses.mount, andmountwith a non-empty type, throw.nmountflags are not read.Overlaps
Export.cpp,GuestKernelSys.cppandlibkernel_sys.mdnear these lines: the lower number goes first, so #15025 first and this PR rebases.tools/pr_overlap.pyfails closed (about 150 older pull requests that conflict withmainthemselves could not be compared); a search of open pull requests formount,unmountandnmountfinds no other implementation (#14894 only mentions thatnmountthrows).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
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T11:53:28Z.
Review: APPROVED
Looks right against FreeBSD 11.4
sys/kern/vfs_mount.c:sys_unmount. For a jailed caller,priv_check(PRIV_VFS_UNMOUNT)comes before thecopyinstrof the path (lines 1198–1205), soEPERMfor every argument follows the source.vfs_domount. TheENAMETOOLONGlength check is followed bypriv_check(PRIV_VFS_MOUNT)for any jailed caller (1110–1112), before theMNT_EXPORTED/MNT_SUIDDIRchecks and before theMNT_UPDATEbranch. So oncevfs_donmount's option checks pass,EPERMis right even forMNT_UPDATE. I'd half expected the update path'snameito come first; it doesn't in 11.4.sys_mount. It doescopyinstr(type, MFSNAMELEN)with no privilege check first, thenvfs_byname_kld. SoEFAULT/ENAMETOOLONGfrom the copy andENOENTfor an empty type are right. Throwing for any other type is the honest choice, sincevfs_byname_kldwould also giveENOENTfor a type that isn't registered, and the registered list isn't modelled.kern_jail.cgatesPRIV_VFS_MOUNT,PRIV_VFS_UNMOUNT,PRIV_VFS_MOUNT_NONUSERandPRIV_VFS_MOUNT_OWNERonallow.mount(3321–3324).Tested on Windows 11, WinLibs GCC 15.2.0, Release, with head
c1b1761e63merged ontomain:guest_kernel_sys,guest_filesystemandpublic_headerspass. A negative control doesn't build:maindeclaresmount/unmountwithout parameters and they throw, so the new test calls don't compile against it.I didn't check the
nmountoption-parsing port (vfs_buildopts,vfs_sanitizeopts,vfs_equalopts) line by line against the source. The tests exercise it, but that part rests on your port. As with the other jail PRs, this follows the source and the #11216 model, not a console run.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T12:04:40Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new mount-option helpers omit the copyright and license notice from the FreeBSD source they closely follow; I also checked the maintainer’s padded-length example against that pinned source.
What I ran
Reviewed head
c1b1761e63d97c1a6b4d739d988ebb731ed64cefagainst base98346b748caaf5e8e533540f3bb9e4ceacf3d7ab; the merge preview against that base was clean. Environment: Linux x86_64, Python 3.11.2, GCC 12.2.0. No build was run.Results
Commands and raw outputs
git diff --check ...exited 0 with no output. The convention checker printed:The ABI audit printed JSON with
"status": "passed"and"findings": [](it also states that it does not prove binary ABI correctness or replace compilation). The stack check reported a clean merge preview for both #15025 and #15037; #15025’s head is not included in #15037, as expected for the declared dependency before it merges.The precheck’s two helper failures were setup failures, not source findings:
Negative control
Findings
Blocking
MountOptionsEqualandSanitizeMountOptionsincore/libs/prx/libkernel/File/src/Stdio.cppclosely reproduce FreeBSD 11.4’svfs_equaloptsandvfs_sanitizeopts, but the new code does not retain the upstream copyright and license notice. The FreeBSD source header requires that notice be retained when redistributing source. Please add aDerived from FreeBSD sys/kern/vfs_mount.c (8c639945a445)attribution and the applicable copyright, conditions, and disclaimer beside the derived helpers, following the repository’sSignalList.cpppattern.Non-blocking
The suggested 32-byte and 128-byte NUL-padded controls would not reach
EPERMon the cited FreeBSD 11.4 path:vfs_getoptreturns the supplied option length, andvfs_donmountrejects lengths overMFSNAMELEN/MNAMELENbefore callingvfs_domount. The current length checks therefore match this source behavior; those controls are not needed to resolve the point.Sources
vfs_mount.cat commit8c639945a44588f6cfdddfb057bb5aad88735da0: license header,vfs_equaloptsandvfs_sanitizeopts,vfs_donmountlength check,vfs_getoptlength behavior.Not verified
No local C++ build, CTest, Linux build, console run, or negative control was performed. Windows CI was in progress and the labels job was queued at the final status check. #15025 has not merged, so the two PRs were not tested as a combined change.
To get this to a good state
Add the upstream attribution and required notice, then update the PR. I will rerun the no-build checks and review the new head; build-dependent checks remain outside this review unless needed to resolve a specific question.
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T15:02:34Z.
Review: APPROVED
@Gruzzberry re-checked at
85d61fc63c.git range-diffofb4ea4da991(my approval) against this head shows one change to this PR's own patch: the FreeBSD notice. The rest is the rebase ontomainb11c7bf84f.core/libs/prx/libkernel/File/src/Stdio.cpp:880has theDerived from FreeBSD sys/kern/vfs_mount.c (8c639945a445)line followed by that file's copyright and licence block. I checked that8c639945a445'svfs_mount.chas the same block.vfs_donmountreturnsENAMETOOLONGforfstypelen > MFSNAMELEN || fspathlen > MNAMELEN, where both lengths are the supplied value sizes fromvfs_getopt(:593,:601). That check runs beforevfs_domount'sstrlencheck (:1107). WithMFSNAMELEN16 andMNAMELEN88, a 32-byte NUL-paddedfstypegetsENAMETOOLONGthere, as it does here (Stdio.cpp:871-872,:993).What I ran: head
85d61fc63c(it already containsmainb11c7bf84f), Windows 11, WinLibs GCC, Release,BUILD_TESTING=ON:guest_kernel_sys,guest_filesystemandpublic_headers: 3 of 3 pass.check_conventions.py --base upstream/mainpasses.pr_overlap.py --branch: 48 open PRs touch the same files, none the same exports.MarcZX10's change request asked for the notice, which is now in. Your comment names them without an @-mention, though. CONTRIBUTING counts a change request as answered only when the reviewer is asked again. An @-mention would let the PR back into the queue.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T03:42:26Z.
Review: COMMENTED
Reviewed — no blocking findings
The change at head
2d4590cb067f0d990fa022a6670ef4521e8a3656adds the described mount privilege checks andnmountargument validation; no blocking defect was found in the reviewed changes.What I ran
Reviewed the prepared diff and targeted implementation and helper ranges through
repo_read.pyat the exact head above. No shell, build, or test command was run; the Windows results in the description are author-reported.Results
Negative control
Could not run a negative control because no build or test command was run.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
No build or tests were run, and Linux, macOS, console behavior, and title execution were not verified. The diff included all eight changed files; no changed files were excluded. The diff hunks were read for all eight files, with targeted source ranges read for
Stdio.cpp,Export.cpp,Api.hpp, and theCopyIovecshelper inGeneral.cpp.To get this to a good state
Nothing is required. Optionally, confirm the author-reported build and tests in CI.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T01:42:07Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: make nmount return errors in FreeBSD’s required-option validation order, including writing
errmsgbefore processing later option payloads.What I ran
Reviewed head
48e4a0695548cebd6a18418ebcb1e8a14336abbfand the prepared diff usingrepo_read.py. No build or tests were run.Results
Findings
Blocking
core/libs/prx/libkernel/File/src/Stdio.cpp:1059processes and copies every option name and value before looking upfstypeandfspathat lines 1084–1087. FreeBSD’svfs_buildoptsvalidates those required options while processing the option pairs, so if a required option is absent or invalid before a later unreadable option value, this implementation returnsEFAULTinstead of the requiredEINVALand skips theerrmsgwrite. Validate required options in the same order as FreeBSD before copying later pairs. The current tests cover missing required options and unreadable values separately, but not this ordering case.Non-blocking
None.
Not verified
No build, tests, console behavior, or title run was verified. The author reports Windows test runs in the PR description; these were not run in this review. All changed files were read:
core/libs/prx/libkernel/File/src/Stdio.cpp,core/libs/prx/libkernel_sys/Export.Discovery.cpp,core/libs/prx/libkernel_sys/Export.cpp,core/libs/prx/libkernel_sys/include/Api.hpp,core/libs/tests/GuestFilesystem.cpp,core/libs/tests/GuestKernelSys.cpp,docs/dev/debt/libkernel.md, anddocs/dev/debt/libkernel_sys.md. The manifest lists no excluded changed files.To get this to a good state
Fix the nmount validation ordering and add a regression test combining an invalid or absent required option with an unreadable later option; then rerun the relevant checks on the new head.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T15:44:08Z.
Review: COMMENTED
The imported FreeBSD license notice in
Stdio.cppis next to the mount parser. Please move the verbatim notice to the top of the file and give it a permalink to the pinned source commit, as the repository requires. The current head also conflicts inGuestKernelSys.cpp.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-04T15:57:16Z.
Review: COMMENTED
Actionable comments
29e94e3a-7f5f-49d1-a562-15d65b498e3cReviewing files that changed from the base of the PR and between
2fbf8b4391and68cb715d8b.core/libs/prx/libkernel/File/src/Stdio.cppcore/libs/prx/libkernel_sys/Export.Discovery.cppcore/libs/prx/libkernel_sys/Export.cppcore/libs/prx/libkernel_sys/include/Api.hppcore/libs/tests/GuestFilesystem.cppcore/libs/tests/GuestKernelSys.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel_sys.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T16:14:35Z.
Review: APPROVED
Reviewed — looks good
The changed mount paths match the stated scope, and the reviewed code shows no verified defect that blocks merging.
What I ran
Reviewed head
68cb715d8b8e2ca8ad5bdc232531fa73f629ec87. Used targetedrepo_read.py searchandrepo_read.py catcalls for source context. I ran no tests or builds.Results
Negative control
Not run; no tests were run for this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
No tests, builds, Linux or macOS runs, console behavior, or title runs were verified. The PR description reports Windows test results; those were not run for this review. Read changed hunks and targeted context in:
core/libs/prx/libkernel/File/src/Stdio.cpp,core/libs/prx/libkernel_sys/Export.Discovery.cpp,core/libs/prx/libkernel_sys/Export.cpp,core/libs/prx/libkernel_sys/include/Api.hpp,core/libs/tests/GuestFilesystem.cpp,core/libs/tests/GuestKernelSys.cpp,docs/dev/debt/libkernel.md, anddocs/dev/debt/libkernel_sys.md. The prepared file list reports no exclusions.To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.