From: liupan <490021209@qq.com> Date: Wed, 6 Jul 2022 20:01:29 +0000 (-0600) Subject: api.c: avoid ambiguous controller name matches X-Git-Tag: v2.0.3~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f94ee345a5bb47882e2ec9ea04b3613219e5343;p=thirdparty%2Flibcgroup.git api.c: avoid ambiguous controller name matches calling "hasmntopt" to determine if the controller name exists in "mntopt", may cause errors because of "hasmntopt" only match substring. cpu controller may incorrectly match to cpuset when cpuset mount info appeared before cpu,cpuacct in "/proc/mounts", so we need to validate the last character to make sure the controller name matches exactly. Signed-off-by: liupan <490021209@qq.com> Reviewed-by: Kamalesh Babulal Signed-off-by: Tom Hromatka (cherry picked from commit a18ae861e77f106517df203e30a810ba59b082d9) --- diff --git a/src/api.c b/src/api.c index db1f5a53..fd14372a 100644 --- a/src/api.c +++ b/src/api.c @@ -1074,6 +1074,7 @@ STATIC int cgroup_process_v1_mnt(char *controllers[], struct mntent *ent, char *strtok_buffer = NULL, *mntopt = NULL; int duplicate = 0; int i, j, ret = 0; + char c = 0; for (i = 0; controllers[i] != NULL; i++) { mntopt = hasmntopt(ent, controllers[i]); @@ -1081,6 +1082,11 @@ STATIC int cgroup_process_v1_mnt(char *controllers[], struct mntent *ent, if (!mntopt) continue; + c = mntopt[strlen(controllers[i])]; + + if (c != '\0' && c != ',') + continue; + cgroup_dbg("found %s in %s\n", controllers[i], ent->mnt_opts); /* do not have duplicates in mount table */