-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(jailer): Make "init" in new PID NS a session leader #5045
fix(jailer): Make "init" in new PID NS a session leader #5045
Conversation
62cd720
to
65c152b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5045 +/- ##
==========================================
- Coverage 83.20% 83.16% -0.05%
==========================================
Files 245 245
Lines 26631 26645 +14
==========================================
Hits 22159 22159
- Misses 4472 4486 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
65c152b
to
04e9b0d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wohooo, nice find on the "init is special" thing!
I wonder if its worth it to skip the two syscalls (getpid, getsid) on the --daemonize
path (because there we statically know we dont run into session leader issues), but probably not worth it.
04e9b0d
to
c136b5a
Compare
Good question. Inserting a single branch (whether |
https://man7.org/linux/man-pages/man7/pid_namespaces.7.html > A process in an ancestor namespace can send signals to the "init" > process of a child PID namespace only if the "init" process has > established a handelr for that signal. Firecracker (i.e. the "init" process of the new PID namespace) sets up handlers for some signals including SIGHUP and jailer exits soon after spawning firecracker into the new PID namespace. If the jailer process is a session leader and its exit happens after firecracker configures the signal handlers, SIGHUP will be sent to firecracker and be caught by the handler unexpectedly. In order to avoid the above issue, if jailer is a session leader, creates a new session and makes the child process (i.e. firecracker) become the leader of the new session to not get SIGHUP on the exit of jailer. Note that this is the case only if `--daemonize` is not passed. This is because we use the double fork method to daemonize, making itself not a session leader. Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
c136b5a
to
ea283ef
Compare
should we add an integration test to check all the combinations of |
Changes & Reasons
https://man7.org/linux/man-pages/man7/pid_namespaces.7.html
Firecracker (i.e. the "init" process of the new PID namespace) sets up handlers for some signals including SIGHUP and jailer exits soon after spawning firecracker into the new PID namespace. If the jailer process is a session leader and its exit happens after firecracker configures the signal handlers, SIGHUP will be sent to firecracker and be caught by the handler unexpectedly.
In order to avoid the above issue, if jailer is a session leader, creates a new session and makes the child process (i.e. firecracker) become the leader of the new session to not get SIGHUP on the exit of jailer.
Note that this is the case only if
--daemonize
is not passed. This is because we use the double fork method to daemonize, making itself not a session leader.Testing
We cannot test this reliably in unit tests / integration tests because it's race condition between firecracker's signal handler configuration and jailer's exit.
Inserting sleep before the jailer exits to make the situation reliably happen as follows, I confirmed the fix works.
License Acceptance
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md
.PR Checklist
tools/devtool checkstyle
to verify that the PR passes theautomated style checks.
how they are solving the problem in a clear and encompassing way.
in the PR.
CHANGELOG.md
.[ ] If a specific issue led to this PR, this PR closes the issue.[ ] When making API changes, I have followed theRunbook for Firecracker API changes.
integration tests.
[ ] I have linked an issue to every newTODO
.rust-vmm
.