Question: should the path-string syscall wrappers fail with EFAULT on an unreadable path pointer, and if so centrally in the path resolver or per wrapper? #9368
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 xXPBSXx on 2026-10-21T19:30:30Z.
What I found
A bad-pointer sweep over the libkernel and libkernel_sys exports (983 functions, 1771 calls; each pointer parameter replaced in turn by
nullptr,1and0xfffffffffffff000, one child process per call, Ubuntu 24.04 WSL2 GCC 13.3 and Windows 10 MinGW GCC 15.2,main9c437e8) shows thatnullptralready fails with EFAULT almost everywhere, but a non-null pointer into unmapped memory crashes the host (SIGSEGV on Linux, access violation on Windows) in 207 to 208 functions. Many of them arepthread_*and similar user-space functions where FreeBSD does not validate pointers either; 84 syscall-like functions crash on both hosts.For the path arguments, 22 functions crash on Windows (24 on Linux) when the
const char*is unreadable:open,creat,mkdir,rmdir,unlink,chmod,fchmodat,stat,lstat,link,symlink,renameat,utimes,lutimes,pathconf,shm_open,shm_unlinkand thesceKernelStat,sceKernelMkdir,sceKernelRmdir,sceKernelUnlink,sceKernelRename,sceKernelUtimes,sceKernelCheckReachabilityforms.FreeBSD 11.4 copies the path with
copyinstr(sys/kern/vfs_lookup.c:328) and returns EFAULT.Question
Do you want that behaviour, and where?
ResolvePathError_nid_no_patch), one place, but it touches the code every file call goes through; orPathErrorin Stdio.cpp covers 12 of them; thesceKernel*forms have their own entry checks).I tried (2) locally for
PathErroronly: it removes about 20 of the roughly 700 crashing cases on Linux, because thesceKernel*forms and the resolver itself dereference the string before or without it. I have not opened a PR for the path strings, since #8680 was closed for touching Windows path resolution, and will wait for an answer.The first family I have ready is the output structs (
stat/fstat/fstatfs): the wrappers fill a local struct and copy it out through a checked write (GuestCopyOut,process_vm_writevon Linux and aVirtualQuerywalk on Windows), returning EFAULT as FreeBSD'scopyoutdoes. A third question: is a shared helper like that acceptable, or would you rather have each wrapper use the existing guest-memory checks? I will wait for an answer before opening that PR as well.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by AliZedan1A on 2026-10-21T21:05:55Z.
I would keep the copy primitive central, but invoke it per wrapper. A readability probe in
ResolvePathError_nid_no_patchis not sufficient and would still leave host crashes:openat,mkdirat,fstatatandunlinkatbuild a native path directly for relative names, without calling the resolver.symlinkmust copy both strings, but its target is intentionally never resolved.*path, callstrlen, constructstring_view(path)or log the pointer before they reachResolvePathError_nid_no_patch.ResolvePath_nid_no_patchalso has trusted internal callers ("/app0/...", generatedstd::string::c_str()values and library paths). Making that low-level resolver classify every input as guest memory mixes two contracts.copyinstrinstead gives the syscall an owned snapshot.The reusable part should therefore be something equivalent to:
It should use the same checked host-specific read mechanism as the existing
ReadGuest/CopyIovecswork, copy through the first NUL into owned storage, inspect at mostMAXPATHLEN(1024) bytes, returnEFAULTwhen any required byte is unreadable, andENAMETOOLONGwhen no NUL occurs in those 1024 bytes. Reading in page-bounded chunks avoids 1024 system calls while never reading beyond the page containing a terminator. The resolver can then take the copiedstring/string_view; no wrapper should dereference the original pointer afterward.Each syscall wrapper still needs to call that helper where FreeBSD performs its
copyinstr, because validation precedence is part of the ABI. For two-path operations, copy in the kernel order and stop after the first copy error. The same applies to the proposed output-struct work: a sharedCopyGuestOutprimitive is preferable to repeatingprocess_vm_writev/VirtualQuery/ Mach code, but wrappers should decide when it runs and should fill a local object first.A focused regression test should cover, on all three hosts:
ENAMETOOLONG);link,symlinkand rename;*atpaths, proving the non-resolver paths are covered;So my recommendation is option 2 at the wrapper boundary, backed by one shared checked C-string copy helper rather than repeated ad hoc pointer checks. This also separates the path topic cleanly from the broader 207-function bad-pointer sweep.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:02:07Z.
I found one path consumer that still appears outside #9423:
access_nid_postfixincore/libs/prx/libc/src/Filesystem.cppchecks null and then evaluates*pathbefore callingResolvePath_nid_no_patch(path). The current #9474 symlink-target change also leaves that entry path untouched. Unlessaccessis intentionally outside this syscall issue, an unreadable non-null pointer can still fault in the host before it returns guestEFAULT; it may be worth listing as remaining scope or covering in a follow-up. I have not tested this case locally.