Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3289168ybb; Tue, 31 Mar 2020 02:11:07 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv156WFYSkrUf6SzOlGTz7IV8ohXrj5nogJDCopo6gZ4D5iKRtA9txdABCpNCc7ynTSNemM X-Received: by 2002:aca:b308:: with SMTP id c8mr1327463oif.106.1585645867038; Tue, 31 Mar 2020 02:11:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645867; cv=none; d=google.com; s=arc-20160816; b=MmzQ5db/IvCk0YiDTkAtQHWOLqOqqU63y2wAclF8EiYWIgwQD2FJZbR0UDGOWyFrBr THp+iPCf/6lRuBbwuhOU5syIkZ7+fTf++iTKYfEanabtNh4ZhkhnSc6Z1i18Oxar6Gd5 59WwiW3Sm9pyLmTMySYmzglCX4ZtVx2A/3ui+TeVvoI8lZ4cbopE12cwkrerPQz6a8B/ BL6U83W6KPCeeAUO5PQHyRrVHtl/vMTSNdGkjPwHmsqzmCZgCSyCW5BI0ei0JM6kbsLX rCuRHLRYv9J9xclHgs0Q+3zfl7QeaE++I1IPY//mHt7BnGCEOzF+tv5ek5t2cf2Fx7Es sPlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/QZW55elloqhItafjFTiLoKrrvfsvIh0UNBzceZ1HKs=; b=SWzROvJ+EKGzagmDlGDpZlQYoYwVOMC8X1WvtOD46aBrXBeadEZvuBPveP7IJojvJT ROssdaLakKpH90gCLhnAVqnOAtja7VpHhIwuzwYmiaBNr7SjpWLjCkUIs5tK5dHN/cWm 6LKuG8RU7MYekwFWlK2zNu3e3wsXGDXuMAyCQAgjJRIAADdUwky1qyTFQ7qeb4ipQgIy fuP93kJjgcUswLe4UUBasQfmij+OMwskpGn6nO/lCRxyf6wZSu5SkiIOOmSVYPwvKb31 gunz4xdYQhq2ya/k3RmzUFKFLwsjKmboqb2GMpktHH6hcJP0s/UZ4FH8hvVYJGMjXzwg rttQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gBEGZYjM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j69si6645815oib.93.2020.03.31.02.10.55; Tue, 31 Mar 2020 02:11:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gBEGZYjM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731555AbgCaJKC (ORCPT + 99 others); Tue, 31 Mar 2020 05:10:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:53542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730626AbgCaJKA (ORCPT ); Tue, 31 Mar 2020 05:10:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AFD61208E0; Tue, 31 Mar 2020 09:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645800; bh=M2XYznMyPl5ilmTJqLhupO6Wszm9njVFjh1r0tDOHOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gBEGZYjM4NaN84E8nLvy6UAD1Plw3a/Iy6IeIhA9RWQLHbjLJ+19GofFqeh371L/R xPxl3ZDKbviLCAPRjXuLmqF3op2clmsPHMj8qvx9Fw0btO1+6HF2i6behXsAtIyiMm XPr1/1pnDzO6eU9j+xrTlNYZofrUCFI4dg0QrMSk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , Johan Hovold , Hans Verkuil , Mauro Carvalho Chehab Subject: [PATCH 5.5 169/170] media: xirlink_cit: add missing descriptor sanity checks Date: Tue, 31 Mar 2020 10:59:43 +0200 Message-Id: <20200331085440.578410893@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200331085423.990189598@linuxfoundation.org> References: <20200331085423.990189598@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johan Hovold commit a246b4d547708f33ff4d4b9a7a5dbac741dc89d8 upstream. Make sure to check that we have two alternate settings and at least one endpoint before accessing the second altsetting structure and dereferencing the endpoint arrays. This specifically avoids dereferencing NULL-pointers or corrupting memory when a device does not have the expected descriptors. Note that the sanity check in cit_get_packet_size() is not redundant as the driver is mixing looking up altsettings by index and by number, which may not coincide. Fixes: 659fefa0eb17 ("V4L/DVB: gspca_xirlink_cit: Add support for camera with a bcd version of 0.01") Fixes: 59f8b0bf3c12 ("V4L/DVB: gspca_xirlink_cit: support bandwidth changing for devices with 1 alt setting") Cc: stable # 2.6.37 Cc: Hans de Goede Signed-off-by: Johan Hovold Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/gspca/xirlink_cit.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) --- a/drivers/media/usb/gspca/xirlink_cit.c +++ b/drivers/media/usb/gspca/xirlink_cit.c @@ -1442,6 +1442,9 @@ static int cit_get_packet_size(struct gs return -EIO; } + if (alt->desc.bNumEndpoints < 1) + return -ENODEV; + return le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); } @@ -2626,6 +2629,7 @@ static int sd_start(struct gspca_dev *gs static int sd_isoc_init(struct gspca_dev *gspca_dev) { + struct usb_interface_cache *intfc; struct usb_host_interface *alt; int max_packet_size; @@ -2641,8 +2645,17 @@ static int sd_isoc_init(struct gspca_dev break; } + intfc = gspca_dev->dev->actconfig->intf_cache[0]; + + if (intfc->num_altsetting < 2) + return -ENODEV; + + alt = &intfc->altsetting[1]; + + if (alt->desc.bNumEndpoints < 1) + return -ENODEV; + /* Start isoc bandwidth "negotiation" at max isoc bandwidth */ - alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1]; alt->endpoint[0].desc.wMaxPacketSize = cpu_to_le16(max_packet_size); return 0; @@ -2665,6 +2678,9 @@ static int sd_isoc_nego(struct gspca_dev break; } + /* + * Existence of altsetting and endpoint was verified in sd_isoc_init() + */ alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1]; packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); if (packet_size <= min_packet_size)