Skip to content

Commit

Permalink
[media] v4l2-ctrls: fix integer overflow in v4l2_g_ext_ctrls()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Xi Wang authored and Mauro Carvalho Chehab committed Apr 18, 2012
1 parent 30059d9 commit 5f0049b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/media/video/v4l2-ctrls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5f0049b

Please sign in to comment.