]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
wrapper: fix segfault in cgroup_set_value_int64()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Thu, 2 Mar 2023 05:04:49 +0000 (10:34 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 2 Mar 2023 15:51:00 +0000 (08:51 -0700)
The second argument passed to cgroup_set_value_int64() is of type char *
and the user might pass NULL in the place of the argument, causing a
segfault.  The reason is, argument values are used without checks, fix
it by checking for NULL pointers before proceeding.

Reproducer:
-----------
 #include <stdlib.h>
 #include <libcgroup.h>

 int main(void)
 {
         struct cgroup_controller *cgc;
         struct cgroup *cgrp;
         int ret;

         ret = cgroup_init();
         if (ret)
                 exit(1);

         cgrp = cgroup_new_cgroup("fuzzer");
         if (!cgrp)
                 exit(1);

         cgc = cgroup_add_controller(cgrp, "cpu");
         if (!cgc)
                 exit(1);

         ret = cgroup_add_value_string(cgc, "cpu.shares", "512");
         if (ret)
                 exit (1);

         cgroup_set_value_int64(cgc, NULL, 512);
         // should not reach here.
         return 0;
 }

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 3d56cb07193682da2df078820427e45b458b5823)

src/wrapper.c

index 324b881ead4cba4963250f611c021eaee317c3d0..677ba2a01ddb68972b8b2df2ff495382ba6d33f1 100644 (file)
@@ -505,7 +505,7 @@ int cgroup_set_value_int64(struct cgroup_controller *controller, const char *nam
        int ret;
        int i;
 
-       if (!controller)
+       if (!controller || !name)
                return ECGINVAL;
 
        for (i = 0; i < controller->index; i++) {