Skip to contentSkip to conversation

uvcvideo: Prevent heap overflow in uvc driver

PATCH Superseded Guenter Roeck 2 participants 5 messages May 22, 2017 – Jun 28, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uvcvideo: Prevent heap overflow in uvc driver

From: Robb Glasser <[email protected]>

The size of uvc_control_mapping is user controlled leading to a potential heap overflow in the uvc driver. This adds a check to verify the user provided size fits within the bounds of the defined buffer size.

[groeck: cherry picked from
https://source.codeaurora.org/quic/la/kernel/msm-3.10
commit b7b99e55bc7770187913ed092990852ea52d7892;
updated subject]

---
Fixes CVE-2017-0627.

 drivers/media/usb/uvc/uvc_ctrl.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/media/usb/uvc/uvc_ctrl.c +3 -0
index c2ee6e39fd0c..252ab991396f 100644
@@ -1992,6 +1992,9 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
 	if (!found)
 		return -ENOENT;
 
+	if (ctrl->info.size < mapping->size)
+		return -EINVAL;
+
 	if (mutex_lock_interruptible(&chain->ctrl_mutex))
 		return -ERESTARTSYS;
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 7 lines · Guenter Roeck

From: Robb Glasser <[email protected]>

The size of uvc_control_mapping is user controlled leading to a potential heap overflow in the uvc driver. This adds a check to verify the user provided size fits within the bounds of the defined buffer size.

Quoted 9 lines

[groeck: cherry picked from
https://source.codeaurora.org/quic/la/kernel/msm-3.10
commit b7b99e55bc7770187913ed092990852ea52d7892;
updated subject]

---
Fixes CVE-2017-0627.

Please do not apply this patch. It is buggy.

Guenter

Quoted 17 lines
 drivers/media/usb/uvc/uvc_ctrl.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/media/usb/uvc/uvc_ctrl.c +3 -0
index c2ee6e39fd0c..252ab991396f 100644
@@ -1992,6 +1992,9 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
 	if (!found)
 		return -ENOENT;
 
+	if (ctrl->info.size < mapping->size)
+		return -EINVAL;
+
 	if (mutex_lock_interruptible(&chain->ctrl_mutex))
 		return -ERESTARTSYS;
 
maintainer
#2 lore raw

Hi Guenter,

Quoted 15 lines · On Wednesday 28 Jun 2017 07:36:43 Guenter Roeck wrote:
Quoted 14 lines · Guenter Roeck

From: Robb Glasser <[email protected]>

The size of uvc_control_mapping is user controlled leading to a potential heap overflow in the uvc driver. This adds a check to verify the user provided size fits within the bounds of the defined buffer size.

[groeck: cherry picked from

https://source.codeaurora.org/quic/la/kernel/msm-3.10
commit b7b99e55bc7770187913ed092990852ea52d7892;
updated subject]

Quoted 5 lines
Quoted 3 lines

---
Fixes CVE-2017-0627.

Please do not apply this patch. It is buggy.

I apologize for not noticing the initial patch, even if it looks like it was all for the best. Will you send a new version ?

Quoted 19 lines
Quoted 19 lines
 drivers/media/usb/uvc/uvc_ctrl.c | 3 +++
 1 file changed, 3 insertions(+)
(quoted diff) +0 -0

b/drivers/media/usb/uvc/uvc_ctrl.c index c2ee6e39fd0c..252ab991396f 100644

drivers/media/usb/uvc/uvc_ctrl.c +3 -0
@@ -1992,6 +1992,9 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain
 *chain,
 	if (!found)
 		return -ENOENT;
 
+	if (ctrl->info.size < mapping->size)
+		return -EINVAL;
+
 
 	if (mutex_lock_interruptible(&chain->ctrl_mutex))

return -ERESTARTSYS;

Signature · 3 lines
Regards,

Laurent Pinchart
maintainer
#3 lore raw

Hi Guenter,

Quoted 38 lines · On Wednesday 28 Jun 2017 20:59:17 Laurent Pinchart wrote:
Quoted 15 lines · On Wednesday 28 Jun 2017 07:36:43 Guenter Roeck wrote:
Quoted 14 lines · Guenter Roeck

From: Robb Glasser <[email protected]>

The size of uvc_control_mapping is user controlled leading to a potential heap overflow in the uvc driver. This adds a check to verify the user provided size fits within the bounds of the defined buffer size.

[groeck: cherry picked from

https://source.codeaurora.org/quic/la/kernel/msm-3.10
commit b7b99e55bc7770187913ed092990852ea52d7892;
updated subject]

Quoted 5 lines
Quoted 3 lines

---
Fixes CVE-2017-0627.

Please do not apply this patch. It is buggy.

I apologize for not noticing the initial patch, even if it looks like it was all for the best. Will you send a new version ?

Quoted 13 lines
Quoted 13 lines
 drivers/media/usb/uvc/uvc_ctrl.c | 3 +++
 1 file changed, 3 insertions(+)
(quoted diff) +0 -0

b/drivers/media/usb/uvc/uvc_ctrl.c index c2ee6e39fd0c..252ab991396f 100644

drivers/media/usb/uvc/uvc_ctrl.c +0 -0
@@ -1992,6 +1992,9 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain
 *chain,
 	if (!found)
 		return -ENOENT;
 
Quoted 3 lines
Quoted 3 lines

drivers/media/usb/uvc/uvc_ctrl.c int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 1997

Quoted 3 lines
drivers/media/usb/uvc/uvc_ctrl.c +3 -0
+	if (ctrl->info.size < mapping->size)
+		return -EINVAL;
+

By the way, I believe the right fix should be

	if (mapping->offset + mapping->size > ctrl->info.size * 8)
		return -EINVAL;

Both mapping->offset and mapping->size are 8-bit integers, so there's no risk of overflow in the addition. If we want to safeguard against a possible future bug if the type of the fields change, we could add

	if (mapping->offset + mapping->size < mapping->offset)
		return -EINVAL;
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/media/usb/uvc/uvc_ctrl.c +0 -0
 	if (mutex_lock_interruptible(&chain->ctrl_mutex))
 		return -ERESTARTSYS;
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw
Quoted 50 lines · Laurent Pinchart

Hi Guenter,

Quoted 38 lines · On Wednesday 28 Jun 2017 20:59:17 Laurent Pinchart wrote:
Quoted 15 lines · On Wednesday 28 Jun 2017 07:36:43 Guenter Roeck wrote:
Quoted 14 lines · Guenter Roeck

From: Robb Glasser <[email protected]>

The size of uvc_control_mapping is user controlled leading to a potential heap overflow in the uvc driver. This adds a check to verify the user provided size fits within the bounds of the defined buffer size.

[groeck: cherry picked from

https://source.codeaurora.org/quic/la/kernel/msm-3.10
commit b7b99e55bc7770187913ed092990852ea52d7892;
updated subject]

Quoted 5 lines
Quoted 3 lines

---
Fixes CVE-2017-0627.

Please do not apply this patch. It is buggy.

I apologize for not noticing the initial patch, even if it looks like it was all for the best. Will you send a new version ?

Quoted 13 lines
Quoted 13 lines
 drivers/media/usb/uvc/uvc_ctrl.c | 3 +++
 1 file changed, 3 insertions(+)
(quoted diff) +0 -0

b/drivers/media/usb/uvc/uvc_ctrl.c index c2ee6e39fd0c..252ab991396f 100644

drivers/media/usb/uvc/uvc_ctrl.c +0 -0
@@ -1992,6 +1992,9 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain
 *chain,
 	if (!found)
 		return -ENOENT;
 
Quoted 3 lines
Quoted 3 lines

drivers/media/usb/uvc/uvc_ctrl.c int uvc_ctrl_add_mapping(struct uvc_video_chain *chain, · line 1997

Quoted 3 lines
drivers/media/usb/uvc/uvc_ctrl.c +3 -0
+	if (ctrl->info.size < mapping->size)
+		return -EINVAL;
+

By the way, I believe the right fix should be

	if (mapping->offset + mapping->size > ctrl->info.size * 8)
		return -EINVAL;
Quoted 7 lines

Both mapping->offset and mapping->size are 8-bit integers, so there's no risk of overflow in the addition. If we want to safeguard against a possible future bug if the type of the fields change, we could add

	if (mapping->offset + mapping->size < mapping->offset)
		return -EINVAL;

I currently have this:

@@ -2004,6 +2004,13 @@ int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
goto done;
}

+ /* validate that the user provided bit-size and offset is valid */
+ if ((mapping->size > 32) ||
+ ((mapping->offset + mapping->size) > (ctrl->info.size * 8))) {
+ ret = -EINVAL;
+ goto done;
+ }
+
list_for_each_entry(map, &ctrl->info.mappings, list) {
if (mapping->id == map->id) {
uvc_trace(UVC_TRACE_CONTROL, "Can't add mapping '%s', "

This version originates from Richard Simmons. Copying him to see if he wants to submit it himself.

Guenter