lkml.org 
[lkml]   [2017]   [May]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.11 121/197] [media] cx231xx-cards: fix NULL-deref at probe
    Date
    4.11-stable review patch.  If anyone has any objections, please let me know.

    ------------------

    From: Johan Hovold <johan@kernel.org>

    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>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    drivers/media/usb/cx231xx/cx231xx-cards.c | 45 ++++++++++++++++++++++++++----
    1 file changed, 40 insertions(+), 5 deletions(-)

    --- a/drivers/media/usb/cx231xx/cx231xx-cards.c
    +++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
    @@ -1426,6 +1426,9 @@ static int cx231xx_init_v4l2(struct cx23

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

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

    @@ -1439,7 +1442,12 @@ static int cx231xx_init_v4l2(struct cx23
    return -ENOMEM;

    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);
    dev_dbg(dev->dev,
    "Alternate setting %i, max size= %i\n", i,
    @@ -1456,6 +1464,9 @@ static int cx231xx_init_v4l2(struct cx23
    }
    uif = udev->actconfig->interface[idx];

    + if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
    + return -ENODEV;
    +
    dev->vbi_mode.end_point_addr =
    uif->altsetting[0].endpoint[isoc_pipe].desc.
    bEndpointAddress;
    @@ -1472,8 +1483,12 @@ static int cx231xx_init_v4l2(struct cx23
    return -ENOMEM;

    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);
    @@ -1493,6 +1508,9 @@ static int cx231xx_init_v4l2(struct cx23
    }
    uif = udev->actconfig->interface[idx];

    + if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1)
    + return -ENODEV;
    +
    dev->sliced_cc_mode.end_point_addr =
    uif->altsetting[0].endpoint[isoc_pipe].desc.
    bEndpointAddress;
    @@ -1507,7 +1525,12 @@ static int cx231xx_init_v4l2(struct cx23
    return -ENOMEM;

    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);
    @@ -1676,6 +1699,11 @@ static int cx231xx_usb_probe(struct usb_
    }
    uif = udev->actconfig->interface[idx];

    + if (uif->altsetting[0].desc.bNumEndpoints < isoc_pipe + 1) {
    + retval = -ENODEV;
    + goto err_video_alt;
    + }
    +
    dev->ts1_mode.end_point_addr =
    uif->altsetting[0].endpoint[isoc_pipe].
    desc.bEndpointAddress;
    @@ -1693,7 +1721,14 @@ static int cx231xx_usb_probe(struct usb_
    }

    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] =

    \
     
     \ /
      Last update: 2017-05-24 00:14    [W:4.238 / U:0.056 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site