fix(libkernel): fail inet_ntop with EFAULT on an unmapped source or destination #15524
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15524"
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-03T17:44:24Z.
What
__inet_ntopandinet_ntopin libkernel read the address from the guest source pointer and wrote the text, and forAF_INET6the zero padding up tosize, through the guest destination pointer with rawmemcpyandmemset. A non-null pointer that is not mapped, such as 0x10 or an inaccessible page, faulted the host. They now read the address withGuestCopyIn_nid_no_patch(4 bytes forAF_INET, 16 forAF_INET6) and write the text and the padding withGuestCopyOut_nid_no_patchin 4096-byte chunks, and fail with a null result andEFAULTwhen either cannot be accessed.The order of the checks is unchanged and matches FreeBSD 11.4's
inet_ntop.c: an unknown family givesEAFNOSUPPORTbefore either pointer is touched, the source is read next, a result that does not fit givesENOSPCbefore the destination is touched (so a bad destination with a too smallsizestill givesENOSPC), and then the destination is written.ENOSPCandEAFNOSUPPORTalready matched the source and the console measurements pinned inGuestAddressConversion.cpp; nothing about them changes. A null source or destination still throws, as the existing tests and debt entries record, since the console dereferences them.This is a host-safety fix, not console behaviour.
inet_ntopruns entirely in user space on FreeBSD, so a console process faults on a bad pointer and sets no errno;EFAULTwas not measured on a console. The entry is indocs/dev/debt/libkernel.md. Callers such asinet_ntoa_rin libSceLibcInternal andsceNetInetNtopin libSceNet keep their own handling of the result and of their own buffers; this change only makes this function safe.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, on currentmain(rebased after the full suite; the 62 commits it picked up do not touch these files, andguest_addresseswas rerun 3 times out of 3 on the rebased head).guest_addresses: newCheckUnusablePointers, for both__inet_ntopandinet_ntop, covers a source at 0x10, on aPROT_NONEpage and straddling a readable and an unreadable page (4 and 16 byte reads), for both families and sizes 0, 1 and 64 (EFAULT, beforeENOSPC); a destination at 0x10, on aPROT_NONEpage and on a read-only page, with room (EFAULT) and without (ENOSPC); an unknown family with each bad pointer (EAFNOSUPPORT); a result that ends exactly at an unreadable page (success) and one byte short of fitting (ENOSPC, nothing written); anAF_INET6padding that ends exactly at the page (success) and one byte past it (EFAULT, the text already written). Onmainthe test crashes; with this change it passes, three runs out of three. The existing console-measured cases still pass.agc_*timeouts andannotate_moduleunder load); rerun alone, 16 pass and 3 fail.vulkan_validation_gate_reportsandcheck_compile_test_windows_gcc_response_text_mode_is_not_reinterpretedfail because of the WindowsApps Python on this machine, andagc_driver_store_over_untracked, a GPU test, also fails withSignalSets.cppreverted tomainon another branch, so it does not depend on libkernel's socket code.python tools/check_conventions.py --base upstream/main: passes.Overlaps
tools/pr_overlap.pyreports no conflicting file or export. The PRs it lists as sharing files without comparing them (they conflict withmainthemselves) only append todocs/dev/debt/libkernel.md. #12924 addsinet_netof,inet_lnaof,inet_makeaddrandinet_networkto libSceLibcInternal and does not touchAddressConversion.cpp.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 gabichuuuuu on 2026-11-08T21:44:00Z.
Review: COMMENTED
Windows run of head
d017b1e07b, merged ontomain095ff72367in one tree with other open PRs that touch different files (each PR's test is its own file, so they don't interact). Setup: Windows 11, WinLibs GCC 15.2 r7 (x86_64-ucrt-posix-seh, the CI toolchain), Release,BUILD_TESTING=ON.guest_addresseswith--repeat until-fail:5: 5 / 5 pass.main'sAddressConversion.cppand this PR's test: 5 / 5 runs fail.From reading: the source copy is 4 bytes for
AF_INETand 16 forAF_INET6, and theAF_INET6padding is written in 4 KiB chunks, so a largecapacitydoesn't need a large buffer. The debt entry records theEFAULTas a host-safety fallback, which matches FreeBSD's user-spaceinet_ntop.