From 5e6028b9306a9f5357a0210d931efbb9365fb2d0 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 20 Jul 2022 10:26:22 +0200 Subject: executor: fix mounting of cgroups on read-only fs If root fs is read-only, mkdir(/syzcgroup) will fail and a later rmdir(/syzcgroup/unified) will fail with ENOENT which we don't expect and fail. Return early if mkdir(/syzcgroup) fails. --- pkg/csource/generated.go | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'pkg/csource/generated.go') diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index 3963dc707..fce9fc8ee 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -8135,6 +8135,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; } char enabled[128] = {0}; int i = 0; @@ -8162,34 +8163,42 @@ 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) { - 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); 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() +{ + 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); + 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"); -- cgit mrf-deployment