Open majek opened 4 years ago
While we could (and should) fix the second case, the first one happens inside the Go runtime though. gVisor don't have much control over it. When cgroups is supported in gVisor (#190), we could try to prevent panics by limiting the number of PIDs inside the sandbox (or set rlimits). The challenge is to properly account for background goroutines, e.g. netstack, gofer, etc.
I see. I frankly don't mind. I just would like to have an ability to ensure the guest can't launch too many pids.
Would setting RLIMIT_NPROC
work?
@parruda what do you mean? RLIMIT_NPROC
inside the gvisor? Is it supported?
I mentioned it because of:
we could try to prevent panics by limiting the number of PIDs inside the sandbox (or set rlimits)
@majek it seems like it is supported. I don't know Go much so you should double check.
setrlimit
shows as partial support on the docs: https://gvisor.dev/docs/user_guide/compatibility/linux/amd64/RLIMIT_NPROC
is listed on https://godoc.org/gvisor.dev/gvisor/pkg/sentry/limits#pkg-variablesI'm working on porting some stuff to run on CloudRun and setrlimit
is a limitation.
https://github.com/google/gvisor/blob/e3fdd1593217894328d5a917bbc356d0a7d145f0/pkg/sentry/syscalls/linux/sys_rlimit.go#L100 suggests that ProcessCount is not enforced.
I can't find any code that uses it for enforcement, though it's likely I have missed something.
Related: https://github.com/google/gvisor/issues/2489
According to cgroupsv1, fork might return EAGAIN: https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt
Runsc crashes in such case. To reproduce: (1) Run runsc in a cgroup with pids.max set to low value (256?) (2) Run this inside runsc
This
:(){ :|:& };:
is a valid bash command, also known as fork bomb.Runsc in
.boot
log shows a not-nice panic:Another error I saw
Runsc should not panic on a fork bomb, or when the user tries to launch too many pids.