[media] v4l2-ctrls: fix integer overflow in v4l2_g_ext_ctrls()
authorXi Wang <xi.wang@gmail.com>
Fri, 6 Apr 2012 12:32:36 +0000 (09:32 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 18 Apr 2012 14:09:03 +0000 (11:09 -0300)
A large cs->count from userspace may overflow the allocation size,
leading to memory corruption.  v4l2_g_ext_ctrls() can be reached
from subdev_do_ioctl() or __video_do_ioctl().

Use kmalloc_array() to avoid the overflow.

Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/v4l2-ctrls.c

index 3e0a72dec994ca819daa69b3e87d685ede389b5a..bf62b105b49d3098fdc233a4912d54d65d0a81a8 100644 (file)
@@ -2036,7 +2036,8 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
                return class_check(hdl, cs->ctrl_class);
 
        if (cs->count > ARRAY_SIZE(helper)) {
-               helpers = kmalloc(sizeof(helper[0]) * cs->count, GFP_KERNEL);
+               helpers = kmalloc_array(cs->count, sizeof(helper[0]),
+                                       GFP_KERNEL);
                if (helpers == NULL)
                        return -ENOMEM;
        }