]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
src/api.c: potential null ptr deref in cg_get_cgroups_from_proc_cgroups
authorMikhail Dmitrichenko <mdmitrichenko@astralinux.ru>
Mon, 8 Dec 2025 10:47:31 +0000 (13:47 +0300)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 8 Jan 2026 14:24:15 +0000 (07:24 -0700)
In function cg_get_cgroups_from_proc_cgroups there is an allocation of memory by calling
malloc(buff_len).
Result of this allocation is not checked,
and in case of OOM it'll lead to null ptr deref.

This commit adds handling of possible null ptr as a result of failed
memory allocation.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko222@gmail.com>
Acked-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 6b0140d6c815db1e74469becc8f7e1e38795824b..f23044a2595beb5857b2f46d956d1a8425e950f8 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -5930,6 +5930,11 @@ STATIC int cg_get_cgroups_from_proc_cgroups(pid_t pid, char *cgrp_list[],
                if (buff_len > 1) {
                        /* Strip off the leading '/' for every cgroup but the root cgroup */
                        cgrp_list[idx] = malloc(buff_len);
+                       if (!cgrp_list[idx]) {
+                               cgroup_err("malloc failed: %s\n", strerror(errno));
+                               fclose(f);
+                               return ECGOTHER;
+                       }
                        snprintf(cgrp_list[idx], buff_len, "%s", &stok_buff[1]);
                } else {
                        /* Retain the leading '/' since we're in the root cgroup */