fix(libkernel): check signal dispositions before taking the pending lock in sigsuspend #26206
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26206"
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 GeremC on 2026-11-23T13:10:01Z.
What
A thread that changes a signal's disposition while another thread is in
sigsuspendcan deadlock both. ThreadSanitizer found the lock-order inversion inguest_signals, and the new test hangs on every run without the fix.libkernel's signal code takes two locks in opposite orders:signal_nid_postfixandsigaction_nid_postfixholdregistration, then callDiscardPendingIfIgnored, which takespending.lockwhen the new disposition ignores the signal.WaitForDeliverableSignal(used bysigsuspend) holdspending.lockand callsTakePendingUnblocked, which callsDeliverable→CaughtByGuest/TerminatesWithoutHandler→Dispositionfor each unblocked signal.Dispositiontakesregistration.The fix computes
Deliverablefor every unblocked signal beforeWaitForDeliverableSignaltakespending.lock, and passes the result toTakePendingUnblocked. Every other path already takes the locks in the orderregistration, thenpending.lock, or one at a time.A disposition can now change between that check and the take. That changes nothing a guest can see:
DiscardPendingIfIgnored, underpending.lock, so the take finds nothing.SIG_IGNmakesDeliverPendingSignalreturn false, and the wait loops.signal()does not notifypending.changedeither.The new
guest_signal_disposition_while_suspendedtest:SIGUSR1and callssigsuspendwith an empty mask 2,000 times.SIGUSR1withpthread_killeach time the previous one has been handled.SIGUSR2betweenSIG_IGNandSIG_DFL.EINTRand run the handler.Tested
Linux Mint 22.3 (Ubuntu 24.04 base), GCC 13.3, Release,
BUILD_TESTING=ON.main: timed out at 20 s in 5 of 5 runs. In gdb:sigsuspendthread waits onregistrationinWaitForDeliverableSignal;pending.lockinDiscardPendingIfIgnored←signal_nid_postfix;-DANYPS5_ENABLE_TSAN=ON, run undersetarch -Rbecause GCC 13's libtsan aborts withunexpected memory mappingon this kernel's mmap randomization):main,guest_signalsfails withlock-order-inversion (potential deadlock)betweenDiscardPendingIfIgnored←signal_nid_postfixandDisposition←Deliverable←TakePendingUnblocked←WaitForDeliverableSignal←sigsuspend_nid_postfix.guest_signalsand the new test pass 3 of 3 runs with no ThreadSanitizer report.ctest -R 'signal|sig|alarm|timer|kqueue|equeue|pthread_kill': 55/55 passed.ctest -R '^guest_': 2862/2862 passed.python3 tools/check_conventions.py --base origin/mainpasses. #25999 is the only open PR that touchesSignals.cpp. It changes other functions, and the two branches merge without conflict (git merge-tree).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_014W1f1RvDMX4BmYudy9J2Vj
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-23T13:14:48Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
7bb7e2d18f:tools/check_conventions.pypassed.guest_signal_disposition_while_suspended_testsbuilt cleanly.guest_signal_disposition_while_suspended):core/libs/prx/libkernel/System/src/Signals.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T10:23:52Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
7bb7e2d18fa8e721ea502d8d328735915b5fdffbfrom the prepared diff and targeted source reads. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests or build were run. The author reports Linux Mint 22.3/GCC 13.3 results, including 2,862 guest tests, but these were not independently verified. The reviewed files were
core/libs/prx/libkernel/CMakeLists.txt,core/libs/prx/libkernel/System/src/Signals.cpp, andcore/libs/tests/GuestSignalDispositionWhileSuspended.cpp; all changed files listed in the manifest were read. No files were excluded in the manifest.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T10:38:16Z.
Review: COMMENTED
The GuestSignalDispositionWhileSuspended fixture coverage passed on Linux with the exact implementation from this head. The fixture exercises the disposition change while the target thread is suspended.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.