Skip to content
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

[CVE-2019-5736]: Server uses more memory if start many runc process at one time #1993

Closed
lifubang opened this issue Feb 23, 2019 · 4 comments

Comments

@lifubang
Copy link
Member

Different from #1980 , If we start 100 runc processes at one time, the server will use about more 900M memory than before, it may cause failure. I don't know whether this is a problem or not?

root@iZ2ze1o61blvco5p5ducnnZ:/opt/busybox# cat runc100.sh 
#!/bin/bash
for i in {1..100}
do
	name="test$i"
	runc create $name &
done
echo "100 runc processes started."

Before fix:

root@iZ2ze1o61blvco5p5ducnnZ:/opt/busybox# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        3896        2256          39        1830        3618
Swap:             0           0           0
root@iZ2ze1o61blvco5p5ducnnZ:/opt/busybox# ./runc100.sh 
100 runc processes started.
root@iZ2ze1o61blvco5p5ducnnZ:/opt/busybox# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        4936        1178          40        1869        2545
Swap:             0           0           0

After fix:

root@iZ2ze1o61blvco5p5ducnnZ:/opt/busybox# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        3896        1980          39        2107        3621
Swap:             0           0           0
root@iZ2ze1o61blvco5p5ducnnZ:/opt/busybox# ./runc100.sh 
100 runc processes started.
root@iZ2ze1o61blvco5p5ducnnZ:/opt/busybox# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        4803         352        1107        2827        1611
Swap:             0           0           0
@cyphar
Copy link
Member

cyphar commented Feb 23, 2019

It's because you're just doing runc create -- which results in a created container but not a started container. A created container has pid1 almost entirely setup and is just waiting for the command to actually start (which is done with runc start) and is blocking within runc init.

Once a container is started there is no memory overhead from the copying because the runc process is no longer around (if you're not using detached mode there is still a runc process around but it's not the copied one).

@lifubang
Copy link
Member Author

Because runc start and runc create is called separately, so in a big server, there will be 100 runc create at a time before runc start? I don't know whether there is a lock when call runc create in docker run or kubernetes.

@cyphar
Copy link
Member

cyphar commented Feb 23, 2019

Yeah, I just looked and containerd uses separate create and start operations. The problem is that even with a tmpfs fallback you would still use that memory -- you can try to write to a filesystem (which is what my current #1984 does) but then you're using storage space. The only solution is to have a smaller binary and that would require an enormous amount of work (effectively a full rewrite of runc init).

EDIT: Sorry, there is another solution which is to create a temporary overlayfs mount. I might actually just implement this because it will solve other problems too (and we can use memfd_create as a separate fallback with a tmpfs as the final fallback).

@cyphar
Copy link
Member

cyphar commented Mar 8, 2019

#1984 also fixed this.

@cyphar cyphar closed this as completed Mar 8, 2019
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

No branches or pull requests

2 participants