fix(libkernel): saturate oversized select timeouts #3152
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3152"
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 MarcZX10 on 2026-10-10T23:22:18Z.
What
A valid large
timevalcan overflow whenselectconverts its seconds directly into the clock duration, producing a deadline in the past and an immediate timeout. Compute the available range before converting and saturate oversized deadlines atsteady_clock::time_point::max(). Round remaining microseconds to milliseconds without an overflowing addition.The regression checks normal durations, very large and maximum
int64_tseconds, and values at the clock deadline boundary. Oversized valid timeouts can wait effectively indefinitely after saturation; the console behavior for values outside the host clock's range is unknown and is documented in Technical Debt.Tested
Linux, GCC 12.2, Release build on rebased head
71b2a153:cmake --build /tmp/AnyPS5-build-3152-current-release --target guest_sce_net_tests -j2ctest --test-dir /tmp/AnyPS5-build-3152-current-release -R "^guest_sce_net$" --output-on-failure(1/1 passed)python3 tools/check_conventions.py --base upstream/main(passed)git diff --check(passed)Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-10T23:57:51Z.
Windows check (Windows 11, WinLibs GCC 15.2.0 r7, Release), this head (268b8f4a) merged onto
main181420f8:guest_sce_netpasses 3/3 with the PR.On Windows, the new check also passes on
mainwith only the test change applied, so on this host it doesn't distinguish the fix. Presumably the oversized timeout doesn't overflow in the Windowsselectpath, or the test value doesn't reach it there. Linux is where it discriminates.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T00:29:30Z.
Review: COMMENTED
Both of these are the same kind of fix — a libkernel socket call that a valid guest argument can drive into undefined or wrong behaviour — and both are settled by the same authority: POSIX behaviour, for
selectin the first case and for positioned I/O on a descriptor that is not seekable in the second.In #3152 the saturation is done the right way round. The check is a division before the multiply (
seconds > remaining / MicrosecondsPerSecond), so the comparison itself cannot overflow, and the second guard subtracts an already-boundedrequestedfromremaining, which is what keeps the residual check safe as well. Saturating attime_point::max()rather than clamping to some large constant is what makes an oversizedtimevalbehave as an effectively infinite wait rather than a long one — and covering normal durations,int64_tmaximum and the clock boundary is the set that would catch a regression in either direction.In #3151 the two error forms are exactly the POSIX ones.
ESPIPEfor an open guest socket andEBADFfor a closed descriptor, with the POSIX exports settingerrnoand returning −1 while thesceKernelforms return the translated kernel error, is the split a caller compiled against either interface expects. Answering from the guest descriptor before the host sees it is the part that matters, and the old behaviour shows why: the host call was made with the guest's own number, which is not a host descriptor at all, so it came backEBADFfrom a table that does not hold that object.ESPIPEfor an open guest socket is the answer the guest is owed, and it can only come from the guest's own descriptor table.The descriptor split is fixed for the process lifetime, which is what makes the guard sound.
GuestSockets::FirstDescriptoris aconstexpr, the table starts its counter at that value and only ever increments, and a host descriptor below the boundary is never entered into it — so a number cannot cross between the ranges, and the number alone decides which table owns the descriptor. That is worth one line in the entry, because otherwise a reader has to reconstruct it from the allocation code.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T03:36:16Z.
Thanks for the careful review. I added a Technical Debt entry documenting that valid timeouts beyond the remaining host
steady_clockrange saturate attime_point::max()and can therefore wait effectively indefinitely. The console behavior for a valid timeout outside the host clock's representable range is unknown, so I have not claimed that this matches console behavior; the saturation prevents host-side overflow and the immediate timeout it caused.I rebased onto current
main, added the documentation, and reran the focused Release test on Linux (GCC 12.2):guest_sce_netpasses (1/1). The updated head is71b2a153.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T04:42:40Z.
Thanks for checking this on Windows. Agreed: because the new test also passes on unmodified
mainthere, that run does not demonstrate the fix. The PR's Tested section only claims the Linux run, where the overflow occurs; I will treat the Windows result as a platform-scope observation, not regression evidence.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:44:18Z.
Rebased onto current
main(only a TechnicalDebt adjacency conflict with the newpthread_killline; both lines kept). Rebuilt andguest_sce_netpasses on Linux. Earlier checks: each saturation guard inDeadlineAfteris covered by the test, and FreeBSD'stvtosbt_satsaturates the same way. Windows run confirmed by @AchrafReyani. Merging once CI is green.