fix(libkernel): return EFAULT from getlogin_r and SetLogin for invalid memory pointers #13577
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13577"
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 pushkarreddyy on 2026-10-30T18:42:22Z.
What
Fixes #13567.
getlogin_r_nid_postfixandSetLogin_nid_no_patchdirectly read from and wrote to guest memory pointers without guest copy safety checks. When called with non-null unwritable output memory or an unreadable name pointer, the host crashed with a segmentation fault (SIGSEGV).This change:
GuestCopyOut_nid_no_patchingetlogin_r_nid_postfixto safely write the account name to guest output memory, returning14(EFAULT) when unwritable.CopyGuestString_nid_no_patchinSetLogin_nid_no_patchto safely copy the login name from guest memory, returning14(EFAULT) on bad memory.core/libs/tests/GuestGetlogin.cppverifying invalid output pointer handling before and after session login is set.docs/dev/debt/libkernel.md.Tested
python tools/check_conventions.py --base origin/main.core/libs/tests/GuestGetlogin.cppverifying that unwritable pointers return14without modifying guest memory.Checklist
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T21:31:39Z.
Review: COMMENTED
Linux run of head
330e1c1d69, merged ontomain6472c708ae(clean merge). Ubuntu 26.04, i7-8700, GCC 15.2, Release,BUILD_TESTING=ON, Ninja.guest_getloginfails 3/3 on this head, at two separate checks:getlogin_r_nid_postfix(reinterpret_cast<char*>(0x10), 1) == 14. It returns 34. The size check (length > size-> 34) runs beforeGuestCopyOut, and any host account name needs more than 1 byte, so this one doesn't depend on the host OS. The next line (0x10with the full 4096-byte size) already covers EFAULT.*__error_nid_postfix() == 12345, fails: errno is 14 after the0x10call. On Linux,GuestCopyOut_nid_no_patchusesprocess_vm_writev, which sets the host errno to EFAULT, and that is the same errno the guest reads. The existing code already saves and restores errno aroundReadLoginfor this reason; the newGuestCopyOutcalls are outside that window. The Windows path (VirtualQuery+memcpy) doesn't touch errno.Fix I verified: drop the size-1
0x10check and restoreerrnoafter eachGuestCopyOutingetlogin_r_nid_postfix:With that,
guest_getloginpasses 3/3. Reverting onlyLogin.cpptomain(fixed test kept) segfaults 3/3, so the test does catch the original bug.public_headerspasses.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.