Skip to content

Commit 1e4a114

Browse files
Harden monit-access-helper.sh cgroupv2 mount point detection
Restrict the inspection of /proc/self/mounts to cgroupv2 device (1st column) in addition to existing cgroup fstype (column 3). Also fail fast in case of multiple detected mount points. Fix #585
1 parent 2d3933d commit 1e4a114

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

stemcell_builder/stages/bosh_monit/assets/monit-access-helper.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ permit_monit_access() {
2929
# cgroupv2 (unified hierarchy)
3030
# Create a sub-cgroup under the current process's cgroup and move into it.
3131
# The iptables rules match on this cgroup path.
32-
cgroup_mount="$(awk '$3 == "cgroup2" { print $2 }' /proc/self/mounts)"
32+
cgroup_mount="$(awk '$1 == "cgroup2" && $3 == "cgroup2" { print $2 }' /proc/self/mounts)"
33+
nb_matching_cgroup_mounts=$(echo "$cgroup_mount" | wc -l)
3334
current_cgroup="$(grep '^0::' /proc/self/cgroup | cut -d: -f3)"
34-
if [ -z "${cgroup_mount}" ] || [ -z "${current_cgroup}" ]; then
35+
if [ -z "${cgroup_mount}" ] || [ "${nb_matching_cgroup_mounts}" -ne 1 ] || [ -z "${current_cgroup}" ]; then
3536
echo "permit_monit_access: unable to resolve cgroup v2 mount or path" >&2
3637
return 1
3738
fi

0 commit comments

Comments
 (0)