Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319539pxb; Mon, 20 Sep 2021 18:42:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVoXbaFQ3wJnMKb5Tg0Q9im81JQCjQaV5xVQnH6k+W4rZpmQQ2VF/2dRiSWv5t9UwXogDZ X-Received: by 2002:a5e:c202:: with SMTP id v2mr6227153iop.77.1632188563605; Mon, 20 Sep 2021 18:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188563; cv=none; d=google.com; s=arc-20160816; b=UaIdnvJ9VzId4VcB12ZxzwjooGWCGK91O6MXrzvOvEFqd3khk46bj7NMt9fXJ6nibx I+QulMCYxJbmVPOQvOfWVcbUYbb7Pzc0ChbOccnpiEleY0OhZA70sOqLwVKzVqEHKkXd ri/JVcQoVhx5JGIId+ucJajrf8BhYJ3DyvwdsO9XRFTGBiFWr/loCymMz7VR4f5+mTEs +4I/AOlktXoDiV+cFql2W7vv7bIfVZqM20XULQ+Bc9tIJfxwCEXh6l6/OzfIb1mqBm8v CV4sdq2XnegSILYfMxa7EUyZCWjKrG0EcnnUZBhNMDK6K0NIQNy4S9RgpNykmhoH8eAy RREw== 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=xaPDZ0pc0rVE7wzILsIq/Ava9g41EJ9CC8Mcdru9OfA=; b=HhG/5dowh2W5xJZafhwA+r5s+QbRAiqqs8qajBDb4GvOy6QGeraOQWERhcN0ctljBo LhYFHi3txuzCQJrc39wDTUzoJgnk1TNCfNzLkW3ki65/JsdB1Dd+7qB5p0BuNqgHFHPy 0xoXGE+fVT/85Fp1vogS8RlasfyrxbVIAaN+m2ykv8QaVBhP1uqQaMtB4U/UrloW4UWy 633qbhL5zsb86h/kue82VXSDUMYz2hxez4a57F7Ug3cHNhp+mAP0xoi+3QWqOKOTr++Z v2rsywVWhGMCw33y55cVmcjPNOUGXQJCp4M9l+J9mjX4n1qX1mBwCK+gKevLi2Sn7sPL yLwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CdUVS9nj; 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 m8si12432690ila.156.2021.09.20.18.42.32; Mon, 20 Sep 2021 18:42:43 -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=CdUVS9nj; 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 S244637AbhITQvA (ORCPT + 99 others); Mon, 20 Sep 2021 12:51:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:37492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244181AbhITQtZ (ORCPT ); Mon, 20 Sep 2021 12:49:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DCC1B61244; Mon, 20 Sep 2021 16:47:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156478; bh=eDEWAQUoxcM4ZR2xOMMIfaCNEd2b6OuxB2dSHoiJlSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CdUVS9njLCEI6noOIN+YaHNaNTbm2p9c/6Tev2OuMf4y4hIL7FPQ3m1i2lf8PIFXJ NlkQY0RlP3fT2M99bcLjTQDk/b9X1/SnBIMa1fz5mVOvbV1JxruQ3G5JzID2OxfJwm zXlGcnYVlczlT8/GOlJZnRsqUUAUcfBUDY495XUc= 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.4 077/133] media: uvc: dont do DMA on stack Date: Mon, 20 Sep 2021 18:42:35 +0200 Message-Id: <20210920163915.165067832@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 @@ -866,8 +866,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)) { @@ -875,22 +875,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) @@ -906,10 +911,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,