From 4674909a6e332c3128511fed132ebfa721c6ca02 Mon Sep 17 00:00:00 2001 From: Kenneth Lakin Date: Mon, 10 Jan 2022 15:15:14 -0800 Subject: [PATCH] Don't panic when cgroup controller multi-mounted This commit removes the calls to 'panic' when more than one mount point for either the cgroupv2 controller or the cgroupv1 memory controller is found. It turns out that it is perfectly legal to have a cgroup controller mounted at multiple points in the filesystem. It is now known that some Linux security software does exactly this. [#180668200] Signed-off-by: Joseph Palermo Co-authored-by: Joseph Palermo --- sigar_linux.go | 4 ++-- sigar_linux_test.go | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/sigar_linux.go b/sigar_linux.go index b290f250d..40cf37de6 100644 --- a/sigar_linux.go +++ b/sigar_linux.go @@ -663,7 +663,7 @@ func determineControllerMounts(sysd1, sysd2 *string) { if mtype == "cgroup2" { if *sysd2 != "" { - panic("Multiple cgroup v2 mount points") + return true } *sysd2 = mpath return true @@ -672,7 +672,7 @@ func determineControllerMounts(sysd1, sysd2 *string) { options := strings.Split(moptions, ",") if stringSliceContains(options, "memory") { if *sysd1 != "" { - panic("Multiple cgroup v1 mount points") + return true } *sysd1 = mpath return true diff --git a/sigar_linux_test.go b/sigar_linux_test.go index 4e21c7d96..fe719a3ba 100644 --- a/sigar_linux_test.go +++ b/sigar_linux_test.go @@ -147,9 +147,25 @@ memory2 /smart/fox/jumped/by/lazy/dog cgroup2 irrelevant,options }) }) - // Note: We cannot test that the system panics when - // the file contains multiple entries for any of the - // controllers. Because, well, panic. + Describe("Multiple Mounts", func() { + var sys1, sys2 string + + BeforeEach(func() { + setupFile(procd+"/self/mounts", ` +device path type options +memory1 /somewhere/over/the/rainbow cgroup dummy,memory,and,other +memory2 /smart/fox/jumped/by/lazy/dog cgroup2 irrelevant,options +memory1 /somewhere/over/the/rainbow/duplicate cgroup dummy,memory,and,other +memory2 /smart/fox/jumped/by/lazy/dog/duplicate cgroup2 irrelevant,options +`) + }) + + It("it extracts the first matching mounts", func() { + determineControllerMounts(&sys1, &sys2) + Expect(sys1).To(Equal("/somewhere/over/the/rainbow")) + Expect(sys2).To(Equal("/smart/fox/jumped/by/lazy/dog")) + }) + }) }) Describe("CPU", func() {