]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: avoid ambiguous controller name matches
authorliupan <490021209@qq.com>
Wed, 6 Jul 2022 19:53:35 +0000 (13:53 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 6 Jul 2022 19:55:03 +0000 (13:55 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 86a57e04a4b8fb0e146f6d109dc7a66fe3c249ed..39fcbe6f69b79cf31f8e0356e97adf93a76c5c25 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -1135,6 +1135,7 @@ STATIC int cgroup_process_v1_mnt(char *controllers[], struct mntent *ent,
        char *strtok_buffer = NULL, *mntopt = NULL;
        int shared_mnt, duplicate;
        int i, j, ret = 0;
+       char c = 0;
 
        for (i = 0; controllers[i] != NULL; i++) {
                mntopt = hasmntopt(ent, controllers[i]);
@@ -1142,6 +1143,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);
 
                /* Check if controllers share mount points */