diff options
Diffstat (limited to 'executor')
| -rw-r--r-- | executor/common_linux.h | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/executor/common_linux.h b/executor/common_linux.h index c4ebf850f..7014f156d 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -3429,6 +3429,7 @@ static void mount_cgroups(const char* dir, const char** controllers, int count) { if (mkdir(dir, 0777)) { debug("mkdir(%s) failed: %d\n", dir, errno); + return; } // First, probe one-by-one to understand what controllers are present. char enabled[128] = {0}; @@ -3461,24 +3462,11 @@ static void mount_cgroups(const char* dir, const char** controllers, int count) } } -static void setup_cgroups() +static void mount_cgroups2(const char** controllers, int count) { - // We want to cover both cgroup and cgroup2. - // Each resource controller can be bound to only one of them, - // so to cover both we divide all controllers into 3 arbitrary groups. - // One group is then bound to cgroup2/unified, and 2 other groups - // are bound to 2 cgroup hierarchies. - // Note: we need to enable controllers one-by-one for both cgroup and cgroup2. - // If we enable all at the same time and one of them fails (b/c of older kernel - // or not enabled configs), then all will fail. - const char* unified_controllers[] = {"+cpu", "+memory", "+io", "+pids"}; - const char* net_controllers[] = {"net", "net_prio", "devices", "blkio", "freezer"}; - const char* cpu_controllers[] = {"cpuset", "cpuacct", "hugetlb", "rlimit"}; - if (mkdir("/syzcgroup", 0777)) { - debug("mkdir(/syzcgroup) failed: %d\n", errno); - } if (mkdir("/syzcgroup/unified", 0777)) { debug("mkdir(/syzcgroup/unified) failed: %d\n", errno); + return; } if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) { debug("mount(cgroup2) failed: %d\n", errno); @@ -3491,19 +3479,41 @@ static void setup_cgroups() // by a previous run of e.g. syz-execprog. if (rmdir("/syzcgroup/unified") && errno != EBUSY) fail("rmdir(/syzcgroup/unified) failed"); + return; } if (chmod("/syzcgroup/unified", 0777)) { debug("chmod(/syzcgroup/unified) failed: %d\n", errno); } - int unified_control = open("/syzcgroup/unified/cgroup.subtree_control", O_WRONLY); - if (unified_control != -1) { - unsigned i; - for (i = 0; i < sizeof(unified_controllers) / sizeof(unified_controllers[0]); i++) - if (write(unified_control, unified_controllers[i], strlen(unified_controllers[i])) < 0) { - debug("write(cgroup.subtree_control, %s) failed: %d\n", unified_controllers[i], errno); - } - close(unified_control); + int control = open("/syzcgroup/unified/cgroup.subtree_control", O_WRONLY); + if (control == -1) + return; + int i; + for (i = 0; i < count; i++) + if (write(control, controllers[i], strlen(controllers[i])) < 0) { + debug("write(cgroup.subtree_control, %s) failed: %d\n", controllers[i], errno); + } + close(control); +} + +static void setup_cgroups() +{ + // We want to cover both cgroup and cgroup2. + // Each resource controller can be bound to only one of them, + // so to cover both we divide all controllers into 3 arbitrary groups. + // One group is then bound to cgroup2/unified, and 2 other groups + // are bound to 2 cgroup hierarchies. + // Note: we need to enable controllers one-by-one for both cgroup and cgroup2. + // If we enable all at the same time and one of them fails (b/c of older kernel + // or not enabled configs), then all will fail. + const char* unified_controllers[] = {"+cpu", "+memory", "+io", "+pids"}; + const char* net_controllers[] = {"net", "net_prio", "devices", "blkio", "freezer"}; + const char* cpu_controllers[] = {"cpuset", "cpuacct", "hugetlb", "rlimit"}; + if (mkdir("/syzcgroup", 0777)) { + // Can happen due to e.g. read-only file system (EROFS). + debug("mkdir(/syzcgroup) failed: %d\n", errno); + return; } + mount_cgroups2(unified_controllers, sizeof(unified_controllers) / sizeof(unified_controllers[0])); mount_cgroups("/syzcgroup/net", net_controllers, sizeof(net_controllers) / sizeof(net_controllers[0])); mount_cgroups("/syzcgroup/cpu", cpu_controllers, sizeof(cpu_controllers) / sizeof(cpu_controllers[0])); write_file("/syzcgroup/cpu/cgroup.clone_children", "1"); |
