Skip to contentSkip to conversation

v4l2-ctrls: fix integer overflow in v4l2_g_ext_ctrls()

PATCH New Xi Wang 1 participant 2 messages Apr 6, 2012 Media (V4L/DVB)

lore
Share & tools
lore

Xi Wang

author
#0 lore raw

PATCH 1/2 v4l2-ctrls: fix integer overflow in v4l2_g_ext_ctrls()

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.

---
 drivers/media/video/v4l2-ctrls.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/media/video/v4l2-ctrls.c +2 -1
index 18015c0..f355fd5 100644
@@ -1996,7 +1996,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;
 	}
Signature · 1 line
1.7.5.4
author
#1 lore raw

PATCH 2/2 v4l2-ctrls: fix integer overflow in try_set_ext_ctrls()

A large cs->count from userspace may overflow the allocation size, leading to memory corruption. try_set_ext_ctrls() can be reached from subdev_do_ioctl() or __video_do_ioctl().

Use kmalloc_array() to avoid the overflow.

---
 drivers/media/video/v4l2-ctrls.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/media/video/v4l2-ctrls.c +2 -1
index f355fd5..6f38a5d 100644
@@ -2219,7 +2219,8 @@ static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler *hdl,
 		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)
 			return -ENOMEM;
 	}
Signature · 1 line
1.7.5.4