Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3289165ybb; Tue, 31 Mar 2020 02:11:06 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtuJSlaRpUpzptzqQ5wOZ/QOoPfvXb+zA74eZF3A6sPyqExSJODeCTXVPbTjQkoz1ti6SUw X-Received: by 2002:a9d:4b98:: with SMTP id k24mr2356295otf.26.1585645866840; Tue, 31 Mar 2020 02:11:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585645866; cv=none; d=google.com; s=arc-20160816; b=wH78548D3Gqk7Y3US6HhH6nM78BltCyyIfLYBky2U8Dy6bMReqYWbz3StWd+dp0fyA MTD+07Tp1Txs+0Rv11hznQalD7STe7ENHn/igeUfAVdu0b/gRrPB8Ikj97HdjWbea6kq 83VsvAI47C0wPQ3PhW81bomcgWlxECF+A+ldFOjAHTQheMAzeQPKbZs4kFGSSjNEehsj VE6dcSYdjsSMvZBc2GHT7B7YQ4Tiw3fHfFqdV8u+5KCXWqUOS+Bv17AqCKv8IEYdnpLL zvOcxdd3xf9mHbfCPO0jC7PyrNCCuhmWstdjDZQgDlXooDWRoGJekhKduTnR323I4Wqo d+Zg== 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=ff+eEgIrFgMePZqIJ6ldvDlQ5ikna2H05zRB8cZjNn0=; b=MWxksP9NsaSxncKzKf3wmvBfSt+P1DMxaasAk/k1nQpqbwDNTwkSb/yyVhkKX0avdg lYxAobj3s7+LKsfGXkWoIzCsFBNDDJIl6vp1y46iaUP4ootNZru1baw7Q/lHI1cokCGa hgPhrnfwkjWLYbDiFZMSFPzhZc9EZ5CBzQURq19TTQrNjqcZztdZs2nxSnwSCwx2L4fG o6KwiAyhnbGIy72fjFDEFIUZWIlCDN4XgM/4PNdaWxSDfIyR0Wm8+Yq/iOd2F9sTwQeC vNG+d4V3DJG+kMeqqQ3WkvF7zH8LNKnbpPlN29aypgC2u3gKWanr2auUAAVYKEk5x2tJ CnlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hC8ImQDm; 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 b22si9403727ots.245.2020.03.31.02.10.55; Tue, 31 Mar 2020 02:11:06 -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=hC8ImQDm; 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 S1731547AbgCaJKA (ORCPT + 99 others); Tue, 31 Mar 2020 05:10:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:53484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731541AbgCaJJ6 (ORCPT ); Tue, 31 Mar 2020 05:09:58 -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 1AF3820675; Tue, 31 Mar 2020 09:09:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585645797; bh=TIixybRB4YOuIydEg4jkisdfemupE0rM2og/2zbTMQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hC8ImQDmMhNer3h38nAV9E2fflhPsxkpVrxwwxdkFNQV7lJVSqfJ8+NiQRhNiYr+r 54nMdNyMshuJjFb1X8Ax/2Xnt0I+CPOzw0GIEvr4/HEC1UcCfp/Wnn8o5GpRsaY02t WCzFaiaMRyyaw+4ne+/BibjRGoGu4cWTqDhYL2EM= 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 168/170] media: stv06xx: add missing descriptor sanity checks Date: Tue, 31 Mar 2020 10:59:42 +0200 Message-Id: <20200331085440.496909357@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 485b06aadb933190f4bc44e006076bc27a23f205 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 checks in stv06xx_start() and pb0100_start() are not redundant as the driver is mixing looking up altsettings by index and by number, which may not coincide. Fixes: 8668d504d72c ("V4L/DVB (12082): gspca_stv06xx: Add support for st6422 bridge and sensor") Fixes: c0b33bdc5b8d ("[media] gspca-stv06xx: support bandwidth changing") Cc: stable # 2.6.31 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/stv06xx/stv06xx.c | 19 ++++++++++++++++++- drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) --- a/drivers/media/usb/gspca/stv06xx/stv06xx.c +++ b/drivers/media/usb/gspca/stv06xx/stv06xx.c @@ -282,6 +282,9 @@ static int stv06xx_start(struct gspca_de return -EIO; } + if (alt->desc.bNumEndpoints < 1) + return -ENODEV; + packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); err = stv06xx_write_bridge(sd, STV_ISO_SIZE_L, packet_size); if (err < 0) @@ -306,11 +309,21 @@ out: static int stv06xx_isoc_init(struct gspca_dev *gspca_dev) { + struct usb_interface_cache *intfc; struct usb_host_interface *alt; struct sd *sd = (struct sd *) gspca_dev; + 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(sd->sensor->max_packet_size[gspca_dev->curr_mode]); @@ -323,6 +336,10 @@ static int stv06xx_isoc_nego(struct gspc struct usb_host_interface *alt; struct sd *sd = (struct sd *) gspca_dev; + /* + * Existence of altsetting and endpoint was verified in + * stv06xx_isoc_init() + */ alt = &gspca_dev->dev->actconfig->intf_cache[0]->altsetting[1]; packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); min_packet_size = sd->sensor->min_packet_size[gspca_dev->curr_mode]; --- a/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c +++ b/drivers/media/usb/gspca/stv06xx/stv06xx_pb0100.c @@ -185,6 +185,10 @@ static int pb0100_start(struct sd *sd) alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); if (!alt) return -ENODEV; + + if (alt->desc.bNumEndpoints < 1) + return -ENODEV; + packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); /* If we don't have enough bandwidth use a lower framerate */