Repository navigation
imp: harden signal handling - #245
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #245 +/- ##
==========================================
+ Coverage 84.23% 84.59% +0.36%
==========================================
Files 41 41
Lines 5563 5596 +33
==========================================
+ Hits 4686 4734 +48
+ Misses 877 862 -15
🚀 New features to boost your workflow:
|
grondo
force-pushed
the
imp-signal-hardening
branch
from
November 14, 2026 15:18
218861a to
47c2fc0
Compare
Contributor
Author
|
This has been rebased after #244 |
grondo
force-pushed
the
imp-signal-hardening
branch
2 times, most recently
from
November 14, 2026 16:09
08ad564 to
d7358a0
Compare
Problem: If the IMP child is terminated by a signal that is not forwarded by the IMP, such as SIGSEGV or SIGABRT, the IMP calls imp_raise() to exit with the same signal. However, the signal is blocked by imp_setup_signal_forwarding(), so raise(3) leaves it pending and the IMP hangs forever in pause(2). Unblock the signal in imp_raise() before raising it. Assisted-by: Claude:opus-5.5
Problem: When the job shell is terminated by a signal, imp_raise() terminates the IMP with the same signal. If the signal dumps core, the job user can cause the privileged IMP to dump core at will. Clear the dumpable attribute with PR_SET_DUMPABLE before raising the signal. The IMP still exits with the same signal, so the job shell status is reported correctly. Other IMP crashes are not affected. Assisted-by: Claude:opus-5.5
Problem: imp_raise() calls pause(2) after raising the signal, so if the signal does not terminate the IMP, for example because its default action is to ignore it, the IMP hangs forever. Since the signal is unblocked before raise(3), it is delivered before raise(3) returns. Drop the call to pause(2) and always fall back to exiting with 128+sig if the IMP is still running. Assisted-by: Claude:opus-5.5
Problem: imp_raise() terminates the IMP with a signal, so coverage data is never written and imp_raise() appears uncovered in CI, even though it is exercised by tests. When built with code coverage enabled, call __gcov_dump() before raising the signal, as is already done before execve(2) in run.c. Assisted-by: Claude:opus-5.5
Problem: No test ensures the IMP exits when its child is terminated by a signal that the IMP does not forward. Add a test in which the job shell kills itself with SIGUSR2 and ensure the IMP exits with the same signal. Assisted-by: Claude:opus-5.5
Problem: The IMP's signal handlers may interrupt the main loop at any point, so they are restricted to async-signal-safe functions. This makes it difficult to handle signals that require more work, such as SIGUSR1. Keep all signals blocked in the IMP parent, and only unblock forwarded signals and SIGCHLD while waiting with ppoll(2). Since signals are unblocked atomically by ppoll(2), a signal that arrives before the IMP begins waiting is not lost. Add imp_signal_wait() and imp_waitpid(), and use them in place of usleep(3) and waitpid(2). Have imp_waitpid() disable signal forwarding once the child is reaped, so callers do not need to. Add imp_sigunblock_forwarded() and call it before pam_finish(), so that helpers run by PAM inherit the same signal mask as before. Assisted-by: Claude:opus-5.5
Problem: The IMP SIGUSR1 handler calls functions that are not async-signal-safe, such as fopen(3) and malloc(3), and does not save errno. Set a flag in the handler, and send SIGKILL to the job's container in imp_signal_wait() after the handler returns. Save and restore errno in the handler. Assisted-by: Claude:opus-5.5
grondo
force-pushed
the
imp-signal-hardening
branch
from
November 14, 2026 16:47
d7358a0 to
2d42fbf
Compare
Contributor
✅ Merged into
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR builds on #244 (only the last 6 commits are new here) and addresses issues found while reviewing the IMP's signal handling:
imp_raise()re-raised the signal while it was still blocked, so the IMP waited inpause(2)forever.PR_SET_DUMPABLE. Otherwise, a job shell that dumps core could make the IMP dump core as well whenfs.suid_dumpableis nonzero.ppoll(2).fopen(3)andmalloc(3); it now only sets a flag, and the cgroup SIGKILL is done outside the handler.A new sharness test covers the blocked-signal hang.