Skip to content

subproc: fall back to SIGKILL when a forwarded signal does not stop the jail - #404

Open
aaronjmars wants to merge 1 commit into
google:masterfrom
aaronjmars:kill-grace-sigkill
Open

aaronjmars wants to merge 1 commit into
google:masterfrom
aaronjmars:kill-grace-sigkill

Conversation

@aaronjmars

Copy link
Copy Markdown

With --forward_signals, killAndReapAll() sends the received signal (for example SIGTERM) to each jailed process and then waits for it in reapProc(nsj, pid, true). If the jailed process handles or ignores that signal, the blocking wait4() is interrupted by the 1s ITIMER_REAL tick, the pid stays in nsj->pids, and the loop sends the same signal again. nsjail then never exits, and the time_limit check in reapProc(nsj) does not run during this loop either.

Repro (standalone ONCE mode):

./nsjail -q -Mo --chroot / --forward_signals -- /bin/bash -c 'trap "" TERM; sleep 60'
# send SIGTERM to nsjail: it keeps re-sending SIGTERM and stays up until the child exits on its own

Fix: forwarded signals get a 5 second grace period, after which killAndReapAll() switches to SIGKILL (with a warning) so shutdown always finishes. Behaviour for a process that exits on the forwarded signal, and for the default SIGKILL path, is unchanged.

Added a Makefile test case that runs the repro under timeout --preserve-status -k 20 -s TERM 1 and expects 143 (128 + SIGTERM) instead of hanging until the 20s kill.

I could not build here (macOS); the same change was checked on Linux against the real binary with the repro above.

…he jail

With --forward_signals, killAndReapAll() sends the received signal (e.g.
SIGTERM) to each jailed process and waits for it. If the process handles
or ignores that signal, wait4() is interrupted by the 1s interval timer,
the pid stays tracked and the loop re-sends the same signal forever, so
nsjail never exits.

Give forwarded signals a 5 second grace period, then send SIGKILL. Add a
Makefile test with a jailed shell that ignores SIGTERM.
@google-cla

google-cla Bot commented Nov 26, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant