]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
cx231xx-cards: fix NULL-deref at probe
authorJohan Hovold <johan@kernel.org>
Mon, 13 Mar 2017 12:53:56 +0000 (09:53 -0300)
committerBen Hutchings <ben@decadent.org.uk>
Sat, 26 Aug 2017 01:13:59 +0000 (02:13 +0100)
commit 0cd273bb5e4d1828efaaa8dfd11b7928131ed149 upstream.

Make sure to check the number of endpoints to avoid dereferencing a
NULL-pointer or accessing memory beyond the endpoint array should a
malicious device lack the expected endpoints.

Fixes: e0d3bafd0258 ("V4L/DVB (10954): Add cx231xx USB driver")
Cc: Sri Deevi <Srinivasa.Deevi@conexant.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
[bwh: Backported to 3.2: adjust filename, context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/media/video/cx231xx/cx231xx-cards.c

index d0f475ec986b79d75288af6fa3f2bd250e8f4b83..21f23b6328046f410755fb1eb8bd0911d4a4493e 100644 (file)
@@ -1159,6 +1159,9 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        uif = udev->actconfig->interface[dev->current_pcb_config.
                       hs_config_info[0].interface_info.video_index + 1];
 
+       if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
+               return -ENODEV;
+
        dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0].
                        endpoint[isoc_pipe].desc.bEndpointAddress);
 
@@ -1176,8 +1179,12 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        }
 
        for (i = 0; i < dev->video_mode.num_alt; i++) {
-               u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
-                               desc.wMaxPacketSize);
+               u16 tmp;
+
+               if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1)
+                       return -ENODEV;
+
+               tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.wMaxPacketSize);
                dev->video_mode.alt_max_pkt_size[i] =
                    (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
                cx231xx_info("Alternate setting %i, max size= %i\n", i,
@@ -1189,6 +1196,9 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
                                       hs_config_info[0].interface_info.
                                       vanc_index + 1];
 
+       if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
+               return -ENODEV;
+
        dev->vbi_mode.end_point_addr =
            le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
                        bEndpointAddress);
@@ -1207,8 +1217,12 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        }
 
        for (i = 0; i < dev->vbi_mode.num_alt; i++) {
-               u16 tmp =
-                   le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
+               u16 tmp;
+
+               if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1)
+                       return -ENODEV;
+
+               tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
                                desc.wMaxPacketSize);
                dev->vbi_mode.alt_max_pkt_size[i] =
                    (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
@@ -1221,6 +1235,9 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
                                       hs_config_info[0].interface_info.
                                       hanc_index + 1];
 
+       if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
+               return -ENODEV;
+
        dev->sliced_cc_mode.end_point_addr =
            le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc.
                        bEndpointAddress);
@@ -1239,7 +1256,12 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
        }
 
        for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
-               u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
+               u16 tmp;
+
+               if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1)
+                       return -ENODEV;
+
+               tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
                                desc.wMaxPacketSize);
                dev->sliced_cc_mode.alt_max_pkt_size[i] =
                    (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
@@ -1254,6 +1276,11 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
                                               interface_info.
                                               ts1_index + 1];
 
+               if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1) {
+                       retval = -ENODEV;
+                       goto err_video_alt;
+               }
+
                dev->ts1_mode.end_point_addr =
                    le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].
                                desc.bEndpointAddress);
@@ -1272,7 +1299,14 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
                }
 
                for (i = 0; i < dev->ts1_mode.num_alt; i++) {
-                       u16 tmp = le16_to_cpu(uif->altsetting[i].
+                       u16 tmp;
+
+                       if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1) {
+                               retval = -ENODEV;
+                               goto err_video_alt;
+                       }
+
+                       tmp = le16_to_cpu(uif->altsetting[i].
                                                endpoint[isoc_pipe].desc.
                                                wMaxPacketSize);
                        dev->ts1_mode.alt_max_pkt_size[i] =