feat(libkernel_sys): implement setlogin #9693
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9693"
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-22T08:43:42Z.
What
setloginwas a throwing stub in libkernel_sys. FreeBSD 11.4'ssys_setlogincopies the name withcopyinstrinto aMAXLOGNAME(33-byte) buffer. An unreadable name fails withEFAULT, and a name with no NUL in its first 33 bytes fails withEINVAL(fromENAMETOOLONG), without reading past them; in both cases nothing is stored. Otherwise the name becomes the session's login name, whichsys_getloginreturns.CopyGuestString_nid_no_patch(source, maximum, destination), the page-by-page safe guest read from #9423 with the bound as a parameter.CopyGuestPath_nid_no_patchnow calls it with 1024, so path behaviour is unchanged.setlogincopies the name with a bound of 33, ascopyinstrdoes, so a 33-byte name that runs up to an unreadable page fails withEINVALand the byte past it is never read. Only the host copy reachesSetLogin_nid_no_patchinLogin.cpp, which keeps the name for the process behind a mutex.getlogin_rreturns the stored name once one is set, with the existingERANGErule. Before that it returns theLoginNameForTest_nid_no_patchseam from #9171 or the host account name, as onmain.The new debt entry records that
PRIV_PROC_SETLOGINis not modelled and that the name is kept for the process, not per session.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, onmain7a25f87620.guest_getlogin: a null name and the unreadable0x10fail withEFAULTand store nothing. A 33-byte name fails withEINVAL, and so do 33 non-NUL bytes ending at aPAGE_NOACCESSpage. 32 bytes ending at that page fail withEFAULT, and 32 bytes plus a NUL ending there are stored."guest", a 32-byte name and""are each stored and read back throughRequireLogin. Withsetloginswitched back to the unbounded 1024-byte copy, the guard-pageEINVALcheck fails; with this change the test passes 3 runs out of 3.pr_overlap_encoding,agc_host_import_cut_lifetimeandagc_driver_depth_plane_partial_store, which fail the same way onmainhere, plus GPU tests that skip without a Vulkan device.python tools/check_conventions.py --base upstream/main: passes.Overlaps
mainwithout its commit.settimeofday, mine) removes the stub next tosetlogininExport.Discovery.cppandinclude/Api.hpp: #9682 goes first, then this PR rebases.Export.cppL339, and #11025 edits thegetlogin_rdebt entry next to the new one: proposed on each that it goes first and this PR rebases.Checklist
main; no other open PR implements the same functionsNotImplemented_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-22T08:50:21Z.
Review: CHANGES_REQUESTED
The length boundary and session-name storage logic are straightforward, and the current-main conventions check plus
git diff --checkpassed. The author reports the Windowsguest_getloginand full-suite results; the automatic product jobs are skipped, and I could not reproduce the C++ runtime test in this checkout. I found one correctness issue and two repository-readiness issues: 1.SetLogin_nid_no_patchuses rawstrnlenon the guest pointer. FreeBSD's citedcopyinstrreturnsEFAULTfor an inaccessible or unmapped user address; a non-null bad pointer here can fault the host process instead of returning-1/EFAULT. Please copy through a safe guest-memory read path and add an invalid non-null pointer regression. 2. A pairwise merge-tree with open #9682 conflicts inlibkernel_sys/Export.Discovery.cppwhere both remove neighboring stubs. Both PR bodies say the second must rebase, but the contribution rule asks authors to agree on order and record the dependency. Please coordinate with #9682 and update the checklist. This head is also two commits behind currentmain; refresh it and rerun relevant checks after resolving these items.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T09:50:29Z.
Hi @Gruzzberry, a merge-order note: my #9171 (
getlogin) editscore/libs/prx/libkernel/System/src/Login.cppin the same two places as this PR, the include list and the lines just beforegetlogin_r. It adds agetloginwrapper and aLoginNameForTest_nid_no_patchtest seam; nothing else meets. Proposal: neither waits. Whichever merges second keeps both: yoursessionLogincheck and my test-seam check both sit at the top ofReadLogin/getlogin_r, the session login first. Does that work for you? I'll record it in #9171's checklist.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T11:41:11Z.
Holding this as a draft, following the direction on #5239: the open queue is above 700 and no named title needs this change on current
main. I will only mark it ready again with a current-main title ID, its Game bring-up discussion and the log line where it stops on this, or once the queue is below 700. Thanks for the reviews so far; the requested fixes are being made on the branch in the meantime.Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T11:49:41Z.
@DavidSamir agreed, thanks: neither waits on the other, and whichever of #9171 and this PR lands second keeps both, the stored session name checked first in
getlogin_r, then your test seam. I'll record it in this checklist too.Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T12:10:27Z.
Thanks @MarcZX10. Fixed in bbfa656e06:
setloginnow copies the name with #9423'sCopyGuestPath_nid_no_patchbefore anything reads it, so the non-null unreadable address0x10returns -1 withEFAULTand stores nothing. A regression for that case is inguest_getlogin; with the previous head it faulted the process (0xc0000005). The checklist now recordsDepends on: #9423, the order after #9682, and the agreement with @DavidSamir on #9171. The branch is rebased onmain8b3a6ba88and stays a draft under #5239. While testing I found a Windows regression in #9423 itself (agc_driver_storage_file_write) and reported the cause there.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:27:16Z.
Review: DISMISSED
The non-null unreadable-pointer bug from my previous review is addressed: now copies the guest string before passing it to, and the added regression covers. The current-main convention check passes and is clean. I found two remaining items: 1. copies up to 1024 bytes with before enforcing. The cited FreeBSD uses with the 33-byte destination buffer, so when the first 33 bytes are non-NUL it returns without needing to read byte 34. This implementation can instead return if byte 34 lies in unreadable memory, and can read far beyond the maximum accepted login name. Please add a bounded safe guest-string copy for this call (or equivalent) so the 33-byte limit controls the guest read as well as the stored length, and cover a 32-byte non-NUL prefix ending at an unreadable page. The debt entry already acknowledges this behavioral difference. 2. The PR carries #9423, and its current report identifies a reproducible Windows regression in: the new path copy invokes the AGC guest read guard during xdg-open - opens a file or URL in the user's preferred application Synopsis xdg-open { file | URL } xdg-open { --help | --manual | --version } Use 'man xdg-open' or 'xdg-open --manual' for additional info., causing an uncaught source: cannot open
source' (No such file or directory) read: cannot openread' (No such file or directory) guard: cannot open `guard' (No such file or directory) exception. Please coordinate the fix with #9423 and rerun the affected Windows test/full relevant suite on the resulting stack before treating the dependency as ready. I also inspected the current hosted relinker result: Windows has one timeout (20 seconds) among 234 tests; the other 233 passed. That is separate from the changed runtime tests, but the check is currently red. I did not run local C++ tests because no AGC/build tree is configured in this checkout and has no free space. The contributor-reported 1,892-test Windows run and focused runs are useful evidence, but the dependency regression above is explicitly reported as its one exception.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:27:27Z.
Review: COMMENTED
Correction to my preceding review: shell quoting expanded inline code markers in the review body and corrupted part of its wording. The review state and findings are unchanged; please use this readable version. The prior non-null unreadable-pointer issue is addressed: setlogin_nid_postfix now copies the guest string before passing it to SetLogin_nid_no_patch, and the added regression covers address 0x10. Current-main conventions pass and git diff --check is clean. Two items remain: 1. setlogin_nid_postfix copies up to 1024 bytes with CopyGuestPath_nid_no_patch before enforcing MAXLOGNAME. The cited FreeBSD sys_setlogin uses copyinstr with a 33-byte destination buffer. When the first 33 bytes are non-NUL, it returns EINVAL without needing to read byte 34. This implementation can instead return EFAULT if byte 34 is unreadable, and can read beyond the maximum accepted login name. Please add a bounded safe guest-string copy for this call, so the 33-byte limit also bounds guest-memory reads, and cover a 32-byte non-NUL prefix ending at an unreadable page. The debt entry already acknowledges this difference. 2. The PR carries #9423, whose current report identifies a reproducible Windows regression in agc_driver_storage_file_write: path copying invokes the AGC guest read guard during open, causing an uncaught “file source read guard” exception. Please coordinate the fix with #9423 and rerun the affected Windows test and relevant suite on the resulting stack before treating the dependency as ready. The current hosted relinker result also has one unrelated Windows timeout in shader_cache_native_paths (20 seconds) among 234 tests; the other 233 passed. I did not run local C++ tests because this checkout has no configured build tree and the filesystem has no available space. The author-reported Windows guest_getlogin/full-suite results are useful evidence, but the dependency regression above is explicitly reported as the exception.
I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.