-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix: may kill other process when container has been stopped #1934
Conversation
Yeah, that's obviously a bug. But I think a better solution would be to compare against As an aside, there was a kernel patch sent recently which would help avoid this problem entirely in a race-free way by holding open a file descriptor to |
It's a good news for taking us more security kernel patch. Thanks for all of you.
In Line 45 in 322760b
|
I refactor the code refer to runc/libcontainer/container_linux.go Lines 193 to 202 in 1a40f04
And add a lock. I think we need a lock here. |
8f30cb5
to
26cf626
Compare
This is what I was proposing. diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go
index 7d2c684484bc..bd4c2bc9fd16 100644
--- a/libcontainer/container_linux.go
+++ b/libcontainer/container_linux.go
@@ -371,6 +371,14 @@ func (c *linuxContainer) start(process *Process) error {
}
func (c *linuxContainer) Signal(s os.Signal, all bool) error {
+ // Make sure that the init process hasn't been recycled in the meantime.
+ initStartTime, err := c.initProcess.startTime()
+ if err != nil {
+ return newSystemErrorWithCause(err, "fetching init process start time")
+ }
+ if initStartTime != c.initProcessStartTime {
+ return fmt.Errorf("init process PID has been recycled")
+ }
if all {
return signalAllProcesses(c.cgroupManager, s)
} This should be enough to fix the issue (though maybe doing a stopped check is also reasonable). |
072f8b1
to
2ac93b0
Compare
Thank you for your review. I remove the lock now. |
The current patch is missing the hunk I suggested. I can push a patch for it if you like. |
@cyphar I still think we should doing a stopped check. If use a stopped check, we can reduce a system call and also reduce this error if pid is not reused.
|
Sorry, let me clarify. I think we should do both ("saving a syscall" doesn't really make much sense IMHO). But yeah, while testing I also noticed that you never hit the |
Never mind, |
I've added this to 1.0 because it's actually a spec violation. |
9464763
to
87a1889
Compare
Signed-off-by: Lifubang <lifubang@acmcoder.com>
@cyphar I update the code, because if the container use hosts pid namespace, we should let |
You can see: runc/libcontainer/state_linux.go Lines 41 to 47 in 87a1889
|
Signed-off-by: Lifubang lifubang@acmcoder.com
If a container A has been stopped, and after a long time, the host start a new process B whose process id is just equal to container A's process id.
When
runc kill A 9
again, process B will be killed.So, we need to check container's status when we want to kill it.