Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp829808pxb; Tue, 3 Nov 2020 13:46:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJytZlpDZExlbxlP9hP+mlszcWrM/lgITVAYDVLPJmRXt6G97jcxUE/Eofuv2g7Lj6aVpoUd X-Received: by 2002:a17:906:6b92:: with SMTP id l18mr22583568ejr.292.1604439966575; Tue, 03 Nov 2020 13:46:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439966; cv=none; d=google.com; s=arc-20160816; b=o2plGbNp591XsoUfe+Y//3XUVXJAUaDX36piGY+aKWpNWIcVtzJR1yOR2QNbrTNL1P HVafiwWIT907iSHdip2PciSp/GgdoARjYq3VrR9DfrS5P0JbYBkADrz0q1U0+C4jWIIt PXKlmioTE7M/mmWTlLy4PUhqwLeSnaX9b5NmRR7ViO0MPNsAsNua+pFptZhpuyuitIba aJo3brdhoqoas/ydl27cdG5h9bhqxiSPxv1DFJHSbNb87ObMjt9Daf1guunk84g6txIp z94UPeXEt+k/U79y79kgJnz5J5oAV41/rGI2NHLmIFDubM178erJaZaCUJA/ieeGyRPe YO0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tB1ORG57bUZ6N28uzLHwO3KFi2IvOA3mVKKz5nxhGpk=; b=uyHEjuAbmecW8Dh6PTxiaRNuBFOElfpoJhLXHrwH9VGx7qlna8n2oaFaHZjL3QW3tg Z0s/22PW8V3Qji0JzbIFNGl2TQHnnzSFQkOrgN2Wv3q9e6tj+DrXsZznR/haSchOlroD sJ9fT1mH3x7vA/BaVXA2As3VS+GThao1JVJmMOgt2M4Hs45eIEt2Aw57TTbEI1lGNbto w0qNiTIw1+GJoxg6ddzFswtzcOBP6kqhYWBpvAntUM4Zj/+tK4EBMvRq4wNNR5U6GpST FJiR7N30mcMVueW5V+jrJETaJFSf5aNf3Ka41AvAT7b/wqad/0lI21FAbopGT0tiDPnd 4slQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LKhrpjPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p19si13557837edu.169.2020.11.03.13.45.43; Tue, 03 Nov 2020 13:46:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LKhrpjPV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732636AbgKCVnY (ORCPT + 99 others); Tue, 3 Nov 2020 16:43:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:54128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732607AbgKCUyn (ORCPT ); Tue, 3 Nov 2020 15:54:43 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 BF871223BD; Tue, 3 Nov 2020 20:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436883; bh=J8KuJl1/K8rhrVW1l2iJSlUTzFLshYrulf04j/Hssg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LKhrpjPVGA8Dq7jFAZVwFEUzQlMnak1229bJCyhz3pdpXw4iGWp/Rxku7JW7vKZTw 3Q14MwbXCz7YQXH8TD083aGcInxSwcEZgTjQNI/wbjaC5RURON2izrT7appPaS9q1s VdA+WjMlZZ3s06n8u99G8UKv0gJTNmitllAJE8cE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Daniel W. S. Almeida" , Laurent Pinchart , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.4 052/214] media: uvcvideo: Fix dereference of out-of-bound list iterator Date: Tue, 3 Nov 2020 21:35:00 +0100 Message-Id: <20201103203255.079107323@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel W. S. Almeida [ Upstream commit f875bcc375c738bf2f599ff2e1c5b918dbd07c45 ] Fixes the following coccinelle report: drivers/media/usb/uvc/uvc_ctrl.c:1860:5-11: ERROR: invalid reference to the index variable of the iterator on line 1854 by adding a boolean variable to check if the loop has found the Found using - Coccinelle (http://coccinelle.lip6.fr) [Replace cursor variable with bool found] Signed-off-by: Daniel W. S. Almeida Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/usb/uvc/uvc_ctrl.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index a30a8a731eda8..c13ed95cb06fe 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1848,30 +1848,35 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain, { struct uvc_entity *entity; struct uvc_control *ctrl; - unsigned int i, found = 0; + unsigned int i; + bool found; u32 reqflags; u16 size; u8 *data = NULL; int ret; /* Find the extension unit. */ + found = false; list_for_each_entry(entity, &chain->entities, chain) { if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT && - entity->id == xqry->unit) + entity->id == xqry->unit) { + found = true; break; + } } - if (entity->id != xqry->unit) { + if (!found) { uvc_trace(UVC_TRACE_CONTROL, "Extension unit %u not found.\n", xqry->unit); return -ENOENT; } /* Find the control and perform delayed initialization if needed. */ + found = false; for (i = 0; i < entity->ncontrols; ++i) { ctrl = &entity->controls[i]; if (ctrl->index == xqry->selector - 1) { - found = 1; + found = true; break; } } -- 2.27.0