Skip to content

Commit f3ffc64

Browse files
jhovoldgregkh
authored andcommitted
cx231xx-cards: fix NULL-deref at probe
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: e0d3baf ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3208e45 commit f3ffc64

1 file changed

Lines changed: 40 additions & 5 deletions

File tree

drivers/media/usb/cx231xx/cx231xx-cards.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,9 @@ static int cx231xx_init_v4l2(struct cx231xx *dev,
14471447

14481448
uif = udev->actconfig->interface[idx];
14491449

1450+
if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
1451+
return -ENODEV;
1452+
14501453
dev->video_mode.end_point_addr = uif->altsetting[0].endpoint[isoc_pipe].desc.bEndpointAddress;
14511454
dev->video_mode.num_alt = uif->num_altsetting;
14521455

@@ -1460,7 +1463,12 @@ static int cx231xx_init_v4l2(struct cx231xx *dev,
14601463
return -ENOMEM;
14611464

14621465
for (i = 0; i < dev->video_mode.num_alt; i++) {
1463-
u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.wMaxPacketSize);
1466+
u16 tmp;
1467+
1468+
if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1)
1469+
return -ENODEV;
1470+
1471+
tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc.wMaxPacketSize);
14641472
dev->video_mode.alt_max_pkt_size[i] = (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
14651473
dev_dbg(dev->dev,
14661474
"Alternate setting %i, max size= %i\n", i,
@@ -1477,6 +1485,9 @@ static int cx231xx_init_v4l2(struct cx231xx *dev,
14771485
}
14781486
uif = udev->actconfig->interface[idx];
14791487

1488+
if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
1489+
return -ENODEV;
1490+
14801491
dev->vbi_mode.end_point_addr =
14811492
uif->altsetting[0].endpoint[isoc_pipe].desc.
14821493
bEndpointAddress;
@@ -1493,8 +1504,12 @@ static int cx231xx_init_v4l2(struct cx231xx *dev,
14931504
return -ENOMEM;
14941505

14951506
for (i = 0; i < dev->vbi_mode.num_alt; i++) {
1496-
u16 tmp =
1497-
le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1507+
u16 tmp;
1508+
1509+
if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1)
1510+
return -ENODEV;
1511+
1512+
tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
14981513
desc.wMaxPacketSize);
14991514
dev->vbi_mode.alt_max_pkt_size[i] =
15001515
(tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
@@ -1514,6 +1529,9 @@ static int cx231xx_init_v4l2(struct cx231xx *dev,
15141529
}
15151530
uif = udev->actconfig->interface[idx];
15161531

1532+
if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
1533+
return -ENODEV;
1534+
15171535
dev->sliced_cc_mode.end_point_addr =
15181536
uif->altsetting[0].endpoint[isoc_pipe].desc.
15191537
bEndpointAddress;
@@ -1528,7 +1546,12 @@ static int cx231xx_init_v4l2(struct cx231xx *dev,
15281546
return -ENOMEM;
15291547

15301548
for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) {
1531-
u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
1549+
u16 tmp;
1550+
1551+
if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1)
1552+
return -ENODEV;
1553+
1554+
tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].
15321555
desc.wMaxPacketSize);
15331556
dev->sliced_cc_mode.alt_max_pkt_size[i] =
15341557
(tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
@@ -1693,6 +1716,11 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
16931716
}
16941717
uif = udev->actconfig->interface[idx];
16951718

1719+
if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1) {
1720+
retval = -ENODEV;
1721+
goto err_video_alt;
1722+
}
1723+
16961724
dev->ts1_mode.end_point_addr =
16971725
uif->altsetting[0].endpoint[isoc_pipe].
16981726
desc.bEndpointAddress;
@@ -1710,7 +1738,14 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
17101738
}
17111739

17121740
for (i = 0; i < dev->ts1_mode.num_alt; i++) {
1713-
u16 tmp = le16_to_cpu(uif->altsetting[i].
1741+
u16 tmp;
1742+
1743+
if (uif->altsetting[i].desc.bNumEndpoints < isoc_pipe + 1) {
1744+
retval = -ENODEV;
1745+
goto err_video_alt;
1746+
}
1747+
1748+
tmp = le16_to_cpu(uif->altsetting[i].
17141749
endpoint[isoc_pipe].desc.
17151750
wMaxPacketSize);
17161751
dev->ts1_mode.alt_max_pkt_size[i] =

0 commit comments

Comments
 (0)