fixes: pid reuse attack when kill a exec process#2832
fixes: pid reuse attack when kill a exec process#2832lifubang wants to merge 1 commit intocontainerd:masterfrom
Conversation
4359386 to
f31c097
Compare
Codecov Report
@@ Coverage Diff @@
## master #2832 +/- ##
=======================================
Coverage 43.79% 43.79%
=======================================
Files 100 100
Lines 10741 10741
=======================================
Hits 4704 4704
Misses 5307 5307
Partials 730 730
Continue to review full report at Codecov.
|
|
I see you opened a backport for the release/1.1 branch; I guess this is also needed for the 1.2 branch (and possibly 1.0 branch?) (looking at https://github.com/containerd/containerd/blob/master/RELEASES.md#support-horizon, 1.0 is still supported) |
Random-Liu
left a comment
There was a problem hiding this comment.
This can still happen:
- exec kill pid;
- pid got reused;
- exec kill pid;
- containerd-shim get the exit event, and
setExited.
Do we really need to consider this case? Who are we trying to protect from?
runtime/v1/linux/proc/exec.go
Outdated
There was a problem hiding this comment.
Yes, a not only small, but also big error. I'll push again.
f31c097 to
96eb3bf
Compare
I think this can protect some one who just use lib containerd in their program. And may protect moby when the event queue is blocked or slow for some reasons, because
I think the pid reuse attack may happen needs a long time, in a short time it have very very small probability. If we want to fix this situation, we can use |
Thanks, I'll open PR for these versions if this patch is taken by maintainers. |
Perfect, thanks! |
|
@Random-Liu in here https://github.com/containerd/containerd/blob/96eb3bfa5dda628678ec2edc6d6c0b99e0fb119d/runtime/v1/linux/proc/exec.go#L254-L257 , if the pid is reused, the process can't delete anymore. |
96eb3bf to
f489a95
Compare
Signed-off-by: Lifubang <lifubang@acmcoder.com>
|
Because Lines 265 to 288 in f489a95 containerd/services/tasks/local.go Lines 297 to 303 in f489a95 containerd/runtime/v1/linux/task.go Lines 304 to 309 in f489a95 |
Closes containerd#2832 Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Closes containerd#2832 Signed-off-by: Michael Crosby <crosbymichael@gmail.com> (cherry picked from commit 719a2c5) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Closes containerd#2832 Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Because of we use unix.Kill to kill a exec process, but after a exec process has been stopped, the pid in
execProcesshas not been deleted, we also can useexecProcess.Killto kill the process with the same pid.use unix.Kill https://github.com/lifubang/containerd/blob/831a41b9585fc021c1036da17afa1513e7b4f908/runtime/v1/linux/proc/exec.go#L145-L153
don't delete pid in execProcess https://github.com/lifubang/containerd/blob/831a41b9585fc021c1036da17afa1513e7b4f908/runtime/v1/linux/proc/exec.go#L96-L101
can recall execProcess.Kill https://github.com/lifubang/containerd/blob/831a41b9585fc021c1036da17afa1513e7b4f908/runtime/v1/linux/proc/exec_state.go#L153-L155
So, if the pid is reused, the wrong process will be killed.
Signed-off-by: Lifubang lifubang@acmcoder.com