diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2022-07-15 09:56:50 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2022-07-15 16:03:50 +0200 |
| commit | 7021866f78604fecd47103377cc583118b66e13e (patch) | |
| tree | 4695552bcd21a95c2bd1fae93489e97cdd5297ad /executor/common_linux.h | |
| parent | 5d921b0849eb1958da5e91793b7795131d28b54c (diff) | |
executor: prevent ENOSPC if cgroup mount fails
Remove /syzcgroup/* if cgroup mount fails. See #3241 for context.
Fixes #3241
Diffstat (limited to 'executor/common_linux.h')
| -rw-r--r-- | executor/common_linux.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/executor/common_linux.h b/executor/common_linux.h index f8731456c..faa8654e3 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -3442,14 +3442,19 @@ static void mount_cgroups(const char* dir, const char** controllers, int count) strcat(enabled, ","); strcat(enabled, controllers[i]); } - if (enabled[0] == 0) + if (enabled[0] == 0) { + if (rmdir(dir) && errno != EBUSY) + failmsg("rmdir failed", "dir=%s", dir); return; + } // Now mount all at once. if (mount("none", dir, "cgroup", 0, enabled + 1)) { // In systemd/stretch images this is failing with EBUSY // (systemd starts messing with these mounts?), // so we don't fail, but just log the error. debug("mount(%s, %s) failed: %d\n", dir, enabled + 1, errno); + if (rmdir(dir) && errno != EBUSY) + failmsg("rmdir failed", "dir=%s enabled=%s", dir, enabled); } if (chmod(dir, 0777)) { debug("chmod(%s) failed: %d\n", dir, errno); @@ -3477,6 +3482,15 @@ static void setup_cgroups() } if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) { debug("mount(cgroup2) failed: %d\n", errno); + // For all cases when we don't end up mounting cgroup/cgroup2 + // in /syzcgroup/{unified,net,cpu}, we need to remove the dir. + // Otherwise these will end up as normal dirs and the fuzzer may + // create huge files there. These files won't be cleaned up + // after tests and may easily consume all disk space. + // EBUSY usually means that cgroup is already mounted there + // by a previous run of e.g. syz-execprog. + if (rmdir("/syzcgroup/unified") && errno != EBUSY) + fail("rmdir(/syzcgroup/unified) failed"); } if (chmod("/syzcgroup/unified", 0777)) { debug("chmod(/syzcgroup/unified) failed: %d\n", errno); |
