Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2564755lkm; Mon, 20 Sep 2021 18:50:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8NMjmrzIePUkySx9QeTCKG948H2b2sK2GHIG8WrtP9/M3lOQv3r+KkH6RcJ2De+78sHJI X-Received: by 2002:a05:6e02:12e1:: with SMTP id l1mr11012936iln.286.1632188924253; Mon, 20 Sep 2021 18:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188924; cv=none; d=google.com; s=arc-20160816; b=mwPRU5X1n2zpEARauAGd0IGizhTY6vGdTXWWvnTMNHTO4SCIHn3XZme3mox6gs27H6 XWW1KyoTaPFf0JGY0Jg/eoTmDp9VHjnzMA7wcixtYzcCBkAAAg1UVQmeZWx8nhABezSQ fIUjHLwxEgMoF7bEEsgMz3ax97YlapAyY4kflZXsmCY+MAa1wmgchqIkjqDE+6xlg/J6 bgCO7Fjjt1/pJaL4Zlgw89gR3ejOY2gVTCsnqO4XSJYQs1dGTxG42G72kBPk+Jo3/ern pakf8q0yAyW6R3oxd60yfb7p1ZJj89/ZD73201BgruQH5ILCo0/97G9B/FVanrW8LxE9 c+dw== 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=xvDNokSIZtsPimVDYuLCj94NxP56wPuFMlZ4txtgLTI=; b=V/LpBHLr4Ubm4fItDEZw7mdbef/Vavge6pmZxdpg3bRol0uXy4d42V1T+XwbLW/lkM 8LThT4Ag8bL6yUM2eGUrLsg0tXIyXDyjyf148VV2iPhzn3exR90ThQfJSbPW/4pwnQ0M VnRDE8qBzr5gA0cuIjp6DZMarmqx8RreKO27q7CZA9av6466PJQagEoDNu6/BQGUIAnN YPvMCPP4EF4sRYZSlsULXXlzykJyYlo/r6LgiuTjp2dQS5mgBv9SBIwKTcMJYEH6BdBc 7GET8AscfkgYiwnSuZ1LcoJeM5YXljhTpi694PpFD8RlwCoMWvQq5BPYGR4NBq3d4w70 zYCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ACafkDWM; 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=pass (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 k64si10126245iof.8.2021.09.20.18.48.33; Mon, 20 Sep 2021 18:48:44 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=ACafkDWM; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349382AbhITRqc (ORCPT + 99 others); Mon, 20 Sep 2021 13:46:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:47400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353283AbhITRoT (ORCPT ); Mon, 20 Sep 2021 13:44:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6B914617E1; Mon, 20 Sep 2021 17:09:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157778; bh=V1jpyBADksnNFG7AcGXy7W11iY7j4YUBEoXq+iGRPY8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ACafkDWMe2KE2uGJn/8j7u+BCkbKR4LthJkPh0T6ji7avpZsCOYA3cPNKqKp7RwKL ygI1zm6winQOl7fSl7OxijngUa6gKnsd4+YZihMhoLDvZ+gb2/XKdk67Y28lwkKxMH HvfrhHFzXEdGQYzB7IrlWKino8UThICsnR5BfefA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laurent Pinchart , Mauro Carvalho Chehab Subject: [PATCH 4.19 148/293] media: uvc: dont do DMA on stack Date: Mon, 20 Sep 2021 18:41:50 +0200 Message-Id: <20210920163938.342669056@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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: Mauro Carvalho Chehab commit 1a10d7fdb6d0e235e9d230916244cc2769d3f170 upstream. As warned by smatch: drivers/media/usb/uvc/uvc_v4l2.c:911 uvc_ioctl_g_input() error: doing dma on the stack (&i) drivers/media/usb/uvc/uvc_v4l2.c:943 uvc_ioctl_s_input() error: doing dma on the stack (&i) those two functions call uvc_query_ctrl passing a pointer to a data at the DMA stack. those are used to send URBs via usb_control_msg(). Using DMA stack is not supported and should not work anymore on modern Linux versions. So, use a kmalloc'ed buffer. Cc: stable@vger.kernel.org # Kernel 4.9 and upper Reviewed-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/uvc/uvc_v4l2.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -900,8 +900,8 @@ static int uvc_ioctl_g_input(struct file { struct uvc_fh *handle = fh; struct uvc_video_chain *chain = handle->chain; + u8 *buf; int ret; - u8 i; if (chain->selector == NULL || (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { @@ -909,22 +909,27 @@ static int uvc_ioctl_g_input(struct file return 0; } + buf = kmalloc(1, GFP_KERNEL); + if (!buf) + return -ENOMEM; + ret = uvc_query_ctrl(chain->dev, UVC_GET_CUR, chain->selector->id, chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL, - &i, 1); - if (ret < 0) - return ret; + buf, 1); + if (!ret) + *input = *buf - 1; - *input = i - 1; - return 0; + kfree(buf); + + return ret; } static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int input) { struct uvc_fh *handle = fh; struct uvc_video_chain *chain = handle->chain; + u8 *buf; int ret; - u32 i; ret = uvc_acquire_privileges(handle); if (ret < 0) @@ -940,10 +945,17 @@ static int uvc_ioctl_s_input(struct file if (input >= chain->selector->bNrInPins) return -EINVAL; - i = input + 1; - return uvc_query_ctrl(chain->dev, UVC_SET_CUR, chain->selector->id, - chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL, - &i, 1); + buf = kmalloc(1, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + *buf = input + 1; + ret = uvc_query_ctrl(chain->dev, UVC_SET_CUR, chain->selector->id, + chain->dev->intfnum, UVC_SU_INPUT_SELECT_CONTROL, + buf, 1); + kfree(buf); + + return ret; } static int uvc_ioctl_queryctrl(struct file *file, void *fh,