]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
api.c: fix segfault while processing cgroup mount points
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 4 May 2022 15:39:42 +0000 (21:09 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 4 May 2022 16:57:13 +0000 (10:57 -0600)
commitdaada06e1c606364d5dd20a717b74f91686ec98d
treeb05cbcb120a4d15ec195ec6ac68ebafa9e8617f7
parent654c12065e033d739359068db533219cbd331a62
api.c: fix segfault while processing cgroup mount points

The cgroup v1 and cgroup v2 mount points get read from /proc/mounts in
cgroup_process_v1_mnt()/cgroup_process_v2_mnt() respectively and gets
populated into cg_mount_table[].  The size of cg_mount_table[] is set
to CG_CONTROLLER_MAX, that's defined as 100 and if the system has more
than CG_CONTROLLER_MAX, unique mount points, it will segfault while
processing them.  Fix this by checking, the mount point count after
processing every mount entry and bailout in case it reaches
CG_CONTROLLER_MAX.

The issue can be reproduced using, following simple bash commands on
cgroup v1:
1. sudo for i in $(seq 0 100); do sudo mkdir /name$i; done
2. sudo for i in $(seq 0 100); do sudo mount -t cgroup -o
   none,name=named$i none /name$i; done
3. sudo cgget -g <controller>:<existing cgroup name>

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c