Skip to content
Permalink
Browse files
8253435: Cgroup: 'stomping of _mount_path' crash if manually mounted …
…cpusets exist

Reviewed-by: sgehwolf, bobv
  • Loading branch information
Volker Simonis committed Sep 28, 2020
1 parent 8e338f6 commit 0054c15f60cce6470be05d29bfacbdb74cfb7bc9
@@ -302,8 +302,22 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
cg_infos[MEMORY_IDX]._root_mount_path = os::strdup(tmproot);
cg_infos[MEMORY_IDX]._data_complete = true;
} else if (strcmp(token, "cpuset") == 0) {
assert(cg_infos[CPUSET_IDX]._mount_path == NULL, "stomping of _mount_path");
cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount);
if (cg_infos[CPUSET_IDX]._mount_path != NULL) {
// On some systems duplicate cpuset controllers get mounted in addition to
// the main cgroup controllers most likely under /sys/fs/cgroup. In that
// case pick the one under /sys/fs/cgroup and discard others.
if (strstr(cg_infos[CPUSET_IDX]._mount_path, "/sys/fs/cgroup") != cg_infos[CPUSET_IDX]._mount_path) {
log_warning(os, container)("Duplicate cpuset controllers detected. Picking %s, skipping %s.",
tmpmount, cg_infos[CPUSET_IDX]._mount_path);
os::free(cg_infos[CPUSET_IDX]._mount_path);
cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount);
} else {
log_warning(os, container)("Duplicate cpuset controllers detected. Picking %s, skipping %s.",
cg_infos[CPUSET_IDX]._mount_path, tmpmount);
}
} else {
cg_infos[CPUSET_IDX]._mount_path = os::strdup(tmpmount);
}
cg_infos[CPUSET_IDX]._root_mount_path = os::strdup(tmproot);
cg_infos[CPUSET_IDX]._data_complete = true;
} else if (strcmp(token, "cpu") == 0) {
@@ -60,6 +60,8 @@
private Path cgroupv1CgInfoNonZeroHierarchy;
private Path cgroupv1MntInfoNonZeroHierarchyOtherOrder;
private Path cgroupv1MntInfoNonZeroHierarchy;
private Path cgroupv1MntInfoDoubleCpuset;
private Path cgroupv1MntInfoDoubleCpuset2;
private String mntInfoEmpty = "";
private Path cgroupV1SelfCgroup;
private Path cgroupV2SelfCgroup;
@@ -102,11 +104,14 @@
"41 30 0:37 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:13 - cgroup none rw,seclabel,devices\n" +
"42 30 0:38 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:14 - cgroup none rw,seclabel,cpuset\n" +
"43 30 0:39 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:15 - cgroup none rw,seclabel,blkio\n" +
"44 30 0:40 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:16 - cgroup none rw,seclabel,freezer";
"44 30 0:40 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:16 - cgroup none rw,seclabel,freezer\n";
private String mntInfoHybridRest = cgroupv1MountInfoLineMemory + mntInfoHybridStub;
private String mntInfoHybridMissingMemory = mntInfoHybridStub;
private String mntInfoHybrid = cgroupV2LineHybrid + mntInfoHybridRest;
private String mntInfoHybridFlippedOrder = mntInfoHybridRest + cgroupV2LineHybrid;
private String mntInfoCgroupv1MoreCpusetLine = "121 32 0:37 / /cpusets rw,relatime shared:69 - cgroup none rw,cpuset\n";
private String mntInfoCgroupv1DoubleCpuset = mntInfoCgroupv1MoreCpusetLine + mntInfoHybrid;
private String mntInfoCgroupv1DoubleCpuset2 = mntInfoHybrid + mntInfoCgroupv1MoreCpusetLine;
private String cgroupsNonZeroHierarchy =
"#subsys_name hierarchy num_cgroups enabled\n" +
"cpuset 3 1 1\n" +
@@ -157,6 +162,12 @@ private void setup() {

cgroupV2MntInfoMissingCgroupv2 = Paths.get(existingDirectory.toString(), "mnt_info_missing_cgroup2");
Files.writeString(cgroupV2MntInfoMissingCgroupv2, mntInfoHybridStub);

cgroupv1MntInfoDoubleCpuset = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_double_cpuset");
Files.writeString(cgroupv1MntInfoDoubleCpuset, mntInfoCgroupv1DoubleCpuset);

cgroupv1MntInfoDoubleCpuset2 = Paths.get(existingDirectory.toString(), "mnt_info_cgroupv1_double_cpuset2");
Files.writeString(cgroupv1MntInfoDoubleCpuset2, mntInfoCgroupv1DoubleCpuset2);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -174,6 +185,16 @@ private boolean isValidCgroup(int value) {
return value == CGROUPS_V1 || value == CGROUPS_V2;
}

public void testCgroupv1MultipleCpusetMounts(WhiteBox wb, Path mountInfo) {
String procCgroups = cgroupv1CgInfoNonZeroHierarchy.toString();
String procSelfCgroup = cgroupV1SelfCgroup.toString();
String procSelfMountinfo = mountInfo.toString();
int retval = wb.validateCgroup(procCgroups, procSelfCgroup, procSelfMountinfo);
Asserts.assertEQ(CGROUPS_V1, retval, "Multiple cpuset controllers, but only one in /sys/fs/cgroup");
Asserts.assertTrue(isValidCgroup(retval));
System.out.println("testCgroupv1MultipleCpusetMounts PASSED!");
}

public void testCgroupv1NoMounts(WhiteBox wb) {
String procCgroups = cgroupv1CgInfoZeroHierarchy.toString();
String procSelfCgroup = cgroupV1SelfCgroup.toString();
@@ -246,6 +267,8 @@ public static void main(String[] args) throws Exception {
test.testCgroupV1HybridMntInfoOrder(wb);
test.testCgroupv1MissingMemoryController(wb);
test.testCgroupv2NoCgroup2Fs(wb);
test.testCgroupv1MultipleCpusetMounts(wb, test.cgroupv1MntInfoDoubleCpuset);
test.testCgroupv1MultipleCpusetMounts(wb, test.cgroupv1MntInfoDoubleCpuset2);
} finally {
test.teardown();
}

1 comment on commit 0054c15

@bridgekeeper

This comment has been minimized.

Copy link

@bridgekeeper bridgekeeper bot commented on 0054c15 Sep 28, 2020

Please sign in to comment.