Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp463727ybl; Tue, 28 Jan 2020 06:22:22 -0800 (PST) X-Google-Smtp-Source: APXvYqzX9sp0uS5nRhXtSThxTr/CWq1K0c/79wkr3nJLFEpbWzDjMVqyxw+MBsinNz9rO6FPx6o9 X-Received: by 2002:a9d:2dea:: with SMTP id g97mr15985655otb.33.1580221342030; Tue, 28 Jan 2020 06:22:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580221342; cv=none; d=google.com; s=arc-20160816; b=hfAk6midVFGvIiKj2kPysdCP4qRIB3gSo7jOuIq3hQK84UV50aI3fF/2rWlgyMRejm Dd5v3kTsMkcM+Pho74MfsRSwsBiA+HqjFloeT64SUTTQYTGbhw86GhL3FwxisrTgS4I8 +j2lBZb7VV28OS3JZFFjKP/lCzTFXjnq+Md7qep22ckmiMIqFsfbg6pEQgl+2WYZUBuM 0u67G+3cepqBlM94uQ0GEe3POt6Lci/hz2/lPo+D1wS2x8TMccdMyR0Kms6edAdbiHrl wNpi6KGKudQ94Z8FVVJduMebUc8ev2FRXcs3a34yCokfAsCl1H0FvokKWz3gwLCeXu6h MT9A== 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=+ZuOonxw9eJjoxd5REyQGQtHmXh2mUG05QFrm4uXrjQ=; b=zTTtU+8xxYfawF6QmUqIveV8hc/E3a+ip7JktDXWWDfDan/+4yYrt3S3BwJ3u3+f6g NuVjjcPXRnBuPZYkqdlQouQ3FQMhjb8iJperA+WYx87W+eIbhsbtrxPsprGHGfhm9PNM 52fkK1u8svmWhq2jRrXQGdUcn4HTKGpylJFgmCeWXEBm6tZL2LIGgNvwt7spNxaBuI0O 9pQ64ggNIzzuBCu7Z/qgMKkwtOtONKwIhHavnvHqVnalo+L72WROQng0jyzbzhmZGPsT /Rqri1ZIKbai90sBo5Wvgle7DFUSwKlEnUX2yig4jTuN+nTIhG8TL2y8/4Fyu7PS7ODB 20Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pO58YtCs; 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 i124si4921833oif.214.2020.01.28.06.22.10; Tue, 28 Jan 2020 06:22:22 -0800 (PST) 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=pO58YtCs; 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 S1731073AbgA1OUR (ORCPT + 99 others); Tue, 28 Jan 2020 09:20:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:45048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731062AbgA1OUQ (ORCPT ); Tue, 28 Jan 2020 09:20:16 -0500 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 BE7F424681; Tue, 28 Jan 2020 14:20:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580221216; bh=NHoTf5rvIIxQ+XdG5L5X27wxDUmDxpGxFArljZZqXAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pO58YtCshLGDg99Oxl5Gd1ISNMHirCJwPKICywwlRxKqrZBkNuUDBOCaXbfiaV4cF MgIhJCdgnJjKo5pwKcBu4BKnxXqjHDNF/t8qHeAjj2vr5bSjMAFFc7PIa0Ifx3HSBB /oK+D23hHRdzlxmwIceH/FSPWLZjvEAkhej7z4c4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 4.9 135/271] media: omap_vout: potential buffer overflow in vidioc_dqbuf() Date: Tue, 28 Jan 2020 15:04:44 +0100 Message-Id: <20200128135902.641259559@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200128135852.449088278@linuxfoundation.org> References: <20200128135852.449088278@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: Dan Carpenter [ Upstream commit dd6e2a981bfe83aa4a493143fd8cf1edcda6c091 ] The "b->index" is a u32 the comes from the user in the ioctl. It hasn't been checked. We aren't supposed to use it but we're instead supposed to use the value that gets written to it when we call videobuf_dqbuf(). The videobuf_dqbuf() first memsets it to zero and then re-initializes it inside the videobuf_status() function. It's this final value which we want. Hans Verkuil pointed out that we need to check the return from videobuf_dqbuf(). I ended up doing a little cleanup related to that as well. Fixes: 72915e851da9 ("[media] V4L2: OMAP: VOUT: dma map and unmap v4l2 buffers in qbuf and dqbuf") Signed-off-by: Dan Carpenter Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/omap/omap_vout.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c index a31b95cb3b09c..77ec70f5fef66 100644 --- a/drivers/media/platform/omap/omap_vout.c +++ b/drivers/media/platform/omap/omap_vout.c @@ -1526,23 +1526,20 @@ static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b) unsigned long size; struct videobuf_buffer *vb; - vb = q->bufs[b->index]; - if (!vout->streaming) return -EINVAL; - if (file->f_flags & O_NONBLOCK) - /* Call videobuf_dqbuf for non blocking mode */ - ret = videobuf_dqbuf(q, (struct v4l2_buffer *)b, 1); - else - /* Call videobuf_dqbuf for blocking mode */ - ret = videobuf_dqbuf(q, (struct v4l2_buffer *)b, 0); + ret = videobuf_dqbuf(q, b, !!(file->f_flags & O_NONBLOCK)); + if (ret) + return ret; + + vb = q->bufs[b->index]; addr = (unsigned long) vout->buf_phy_addr[vb->i]; size = (unsigned long) vb->size; dma_unmap_single(vout->vid_dev->v4l2_dev.dev, addr, size, DMA_TO_DEVICE); - return ret; + return 0; } static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i) -- 2.20.1