Skip to content

Commit bba078c

Browse files
Alistair Strachangregkh
authored andcommitted
media: uvcvideo: Fix 'type' check leading to overflow
commit 47bb117 upstream. When initially testing the Camera Terminal Descriptor wTerminalType field (buffer[4]), no mask is used. Later in the function, the MSB is overloaded to store the descriptor subtype, and so a mask of 0x7fff is used to check the type. If a descriptor is specially crafted to set this overloaded bit in the original wTerminalType field, the initial type check will fail (falling through, without adjusting the buffer size), but the later type checks will pass, assuming the buffer has been made suitably large, causing an overflow. Avoid this problem by checking for the MSB in the wTerminalType field. If the bit is set, assume the descriptor is bad, and abort parsing it. Originally reported here: https://groups.google.com/forum/#!topic/syzkaller/Ot1fOE6v1d8 A similar (non-compiling) patch was provided at that time. Reported-by: syzbot <syzkaller@googlegroups.com> Signed-off-by: Alistair Strachan <astrachan@google.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c9b1f85 commit bba078c

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

drivers/media/usb/uvc/uvc_driver.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,11 +1019,19 @@ static int uvc_parse_standard_control(struct uvc_device *dev,
10191019
return -EINVAL;
10201020
}
10211021

1022-
/* Make sure the terminal type MSB is not null, otherwise it
1023-
* could be confused with a unit.
1022+
/*
1023+
* Reject invalid terminal types that would cause issues:
1024+
*
1025+
* - The high byte must be non-zero, otherwise it would be
1026+
* confused with a unit.
1027+
*
1028+
* - Bit 15 must be 0, as we use it internally as a terminal
1029+
* direction flag.
1030+
*
1031+
* Other unknown types are accepted.
10241032
*/
10251033
type = get_unaligned_le16(&buffer[4]);
1026-
if ((type & 0xff00) == 0) {
1034+
if ((type & 0x7f00) == 0 || (type & 0x8000) != 0) {
10271035
uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
10281036
"interface %d INPUT_TERMINAL %d has invalid "
10291037
"type 0x%04x, skipping\n", udev->devnum,

0 commit comments

Comments
 (0)