diff options
author | Haogang Chen <haogangchen@gmail.com> | 2011-11-29 16:32:25 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-12-11 08:23:54 -0500 |
commit | 806e23e95f94a27ee445022d724060b9b45cb64a (patch) | |
tree | 785b64a9a8b6fe3e64414760dd8229fb171563a6 /drivers/media/video/uvc | |
parent | 66847ef013cc4ed3ae519360e7e4cbf531465ae8 (diff) |
[media] uvcvideo: Fix integer overflow in uvc_ioctl_ctrl_map()
There is a potential integer overflow in uvc_ioctl_ctrl_map(). When a
large xmap->menu_count is passed from the userspace, the subsequent call
to kmalloc() will allocate a buffer smaller than expected.
map->menu_count and map->menu_info would later be used in a loop (e.g.
in uvc_query_v4l2_ctrl), which leads to out-of-bound access.
The patch checks the ioctl argument and returns -EINVAL for zero or too
large values in xmap->menu_count.
Signed-off-by: Haogang Chen <haogangchen@gmail.com>
[laurent.pinchart@ideasonboard.com Prevent excessive memory consumption]
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: stable@kernel.org
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/uvc')
-rw-r--r-- | drivers/media/video/uvc/uvc_v4l2.c | 9 | ||||
-rw-r--r-- | drivers/media/video/uvc/uvcvideo.h | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c index b1dc3e507fc1..2ae4f880ea05 100644 --- a/drivers/media/video/uvc/uvc_v4l2.c +++ b/drivers/media/video/uvc/uvc_v4l2.c | |||
@@ -58,6 +58,15 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, | |||
58 | break; | 58 | break; |
59 | 59 | ||
60 | case V4L2_CTRL_TYPE_MENU: | 60 | case V4L2_CTRL_TYPE_MENU: |
61 | /* Prevent excessive memory consumption, as well as integer | ||
62 | * overflows. | ||
63 | */ | ||
64 | if (xmap->menu_count == 0 || | ||
65 | xmap->menu_count > UVC_MAX_CONTROL_MENU_ENTRIES) { | ||
66 | ret = -EINVAL; | ||
67 | goto done; | ||
68 | } | ||
69 | |||
61 | size = xmap->menu_count * sizeof(*map->menu_info); | 70 | size = xmap->menu_count * sizeof(*map->menu_info); |
62 | map->menu_info = kmalloc(size, GFP_KERNEL); | 71 | map->menu_info = kmalloc(size, GFP_KERNEL); |
63 | if (map->menu_info == NULL) { | 72 | if (map->menu_info == NULL) { |
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h index e9c19f53e4a1..67f88d85bb16 100644 --- a/drivers/media/video/uvc/uvcvideo.h +++ b/drivers/media/video/uvc/uvcvideo.h | |||
@@ -114,6 +114,7 @@ | |||
114 | 114 | ||
115 | /* Maximum allowed number of control mappings per device */ | 115 | /* Maximum allowed number of control mappings per device */ |
116 | #define UVC_MAX_CONTROL_MAPPINGS 1024 | 116 | #define UVC_MAX_CONTROL_MAPPINGS 1024 |
117 | #define UVC_MAX_CONTROL_MENU_ENTRIES 32 | ||
117 | 118 | ||
118 | /* Devices quirks */ | 119 | /* Devices quirks */ |
119 | #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 | 120 | #define UVC_QUIRK_STATUS_INTERVAL 0x00000001 |