feat(libkernel_sys): implement kldsym argument checks #11231
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11231"
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-25T22:17:20Z.
What
kldsymwas a throwing stub in libkernel_sys. FreeBSD 11.4'ssys_kldsymfirst copies the 32-bytestruct kld_sym_lookupin from the guest (an unreadabledatagivesEFAULT), then fails withEINVALifversionis notsizeof(struct kld_sym_lookup)or the command is notKLDSYM_LOOKUP(1), then copies the symbol name in withcopyinstr(MAXPATHLEN; hereCopyGuestPath_nid_no_patch, so an unreadable pointer givesEFAULTand 1024 bytes or moreENAMETOOLONG), and only then looks the file up: a file id that no file has givesENOENT(linker_find_file_by_id).kldloadnever loads anything here, so the only file assumed to exist is the kernel (id 1, the first the linker numbers): every id other than 0 and 1 getsENOENT, and a lookup in id 0 (every file) or 1 would read a symbol table that nothing here models, so it throwsstd::runtime_error. Modules a console preloads would have ids of their own and are not modelled; the debt entry says so. The structure is read with a newGuestCopyIn_nid_no_patch, the read counterpart ofGuestCopyOut_nid_no_patch, which returns false for a null or unreadable source. The new debt entry records that kernel symbol lookup by titles is unverified.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, on currentmain.guest_kernel_sys: new checks next to thechrootones for a null and an unreadable0x10structure (EFAULT), versions 0, 24, 31 and 33 and commands 0, 2 and -1 (EINVAL, also with a null symbol name, which pins the order against the name copy), a null, an unreadable0x10and a 1024-byte symbol name (EFAULT,EFAULT,ENAMETOOLONG), and a valid structure with file ids -1, INT_MIN, 2, 3, 100 and INT_MAX (ENOENT). With the body reverted to the stub the test aborts (0xc0000409); with this change it passes, three runs out of three.pr_overlap_encoding,agc_host_import_cut_lifetime,agc_driver_depth_plane_partial_store).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).statfs/symlinkat) adds code atExport.cppL534-535 and #10799 editslibkernel_sys.mdL41: proposed on each that it goes first and this PR rebases.getfsstat), #11034 (swapon) and #11216 (kldload), all mine, touch the same debt line,Export.cppL534 and thechroottest region: they were opened first, so they go 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-25T22:19:39Z.
Review: CHANGES_REQUESTED
The current
conventionscheck fails because the checklist parser does not acceptDepends on: after #11216 (...); it requires exactly a dependency marker such asDepends on: #11216(ornone). Please put the primary dependency in that form and keep the additional merge-order details on a separate checklist line or in the PR description. I verified the listed PRs (#10975, #9161, #10799, #11031, #11034 and #11216) are open, so retaining their ordering notes is useful. Localgit diff --checkpasses; I have not run the Windows/Linux product tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:53:24Z.
Review: DISMISSED
The checklist now declares the dependency order and the exact-head convention check passes. I found one remaining behavioral gap against the linked FreeBSD 11.4 implementation: for every nonzero
fileid,sys_kldsymcallslinker_find_file_by_id; if no file is found, it returnsENOENT. This implementation returnsENOENTonly for negative IDs, then throws for every positive ID. Please clarify how this emulator distinguishes a valid loaded module ID from an unavailable positive ID, and add a focused test for an unavailable positive ID returningENOENT. If module IDs are not modeled at all, the current positive-ID path appears to be classifying an ordinary missing-module case as unsupported.