From patchwork Tue Feb 25 10:15:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 3714701 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 21B2F9F2F7 for ; Tue, 25 Feb 2014 10:16:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 34777201BA for ; Tue, 25 Feb 2014 10:16:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4A7192018E for ; Tue, 25 Feb 2014 10:16:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753145AbaBYKQW (ORCPT ); Tue, 25 Feb 2014 05:16:22 -0500 Received: from smtp-vbr5.xs4all.nl ([194.109.24.25]:1330 "EHLO smtp-vbr5.xs4all.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753275AbaBYKQS (ORCPT ); Tue, 25 Feb 2014 05:16:18 -0500 Received: from tschai.lan (209.80-203-20.nextgentel.com [80.203.20.209]) (authenticated bits=0) by smtp-vbr5.xs4all.nl (8.13.8/8.13.8) with ESMTP id s1PAG76R063553; Tue, 25 Feb 2014 11:16:08 +0100 (CET) (envelope-from hverkuil@xs4all.nl) Received: from test-media.192.168.1.1 (test [192.168.1.27]) by tschai.lan (Postfix) with ESMTPSA id 7E87F2A0258; Tue, 25 Feb 2014 11:16:04 +0100 (CET) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: m.szyprowski@samsung.com, Hans Verkuil Subject: [RFCv1 PATCH 01/13] v4l2-ioctl: add CREATE_BUFS sanity checks. Date: Tue, 25 Feb 2014 11:15:51 +0100 Message-Id: <1393323363-30058-2-git-send-email-hverkuil@xs4all.nl> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1393323363-30058-1-git-send-email-hverkuil@xs4all.nl> References: <1393323363-30058-1-git-send-email-hverkuil@xs4all.nl> X-Virus-Scanned: by XS4ALL Virus Scanner Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil Many drivers do not check anything. At least make sure that the various buffer size related fields are not obviously wrong. Signed-off-by: Hans Verkuil --- drivers/media/v4l2-core/v4l2-ioctl.c | 52 ++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 707aef7..69a1948 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1444,9 +1444,57 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, struct file *file, void *fh, void *arg) { struct v4l2_create_buffers *create = arg; - int ret = check_fmt(file, create->format.type); + const struct v4l2_format *fmt = &create->format; + const struct v4l2_pix_format *pix = &fmt->fmt.pix; + const struct v4l2_pix_format_mplane *mp = &fmt->fmt.pix_mp; + const struct v4l2_plane_pix_format *p; + int ret = check_fmt(file, fmt->type); + unsigned i; + + if (ret) + return ret; - return ret ? ret : ops->vidioc_create_bufs(file, fh, create); + /* Sanity checks */ + switch (fmt->type) { + case V4L2_BUF_TYPE_VIDEO_CAPTURE: + case V4L2_BUF_TYPE_VIDEO_OUTPUT: + if (pix->sizeimage == 0 || pix->width == 0 || pix->height == 0) + return -EINVAL; + /* Note: bytesperline is 0 for compressed formats */ + if (pix->bytesperline && + pix->height * pix->bytesperline > pix->sizeimage) + return -EINVAL; + break; + case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: + case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: + if (mp->num_planes == 0 || mp->width == 0 || mp->height == 0) + return -EINVAL; + for (i = 0; i < mp->num_planes; i++) { + p = &mp->plane_fmt[i]; + + if (p->sizeimage == 0) + return -EINVAL; + /* Note: bytesperline is 0 for compressed formats */ + if (p->bytesperline && + p->bytesperline * mp->height > p->sizeimage) + return -EINVAL; + } + break; + case V4L2_BUF_TYPE_VBI_CAPTURE: + case V4L2_BUF_TYPE_VBI_OUTPUT: + if (fmt->fmt.vbi.count[0] + fmt->fmt.vbi.count[1] == 0) + return -EINVAL; + break; + case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: + case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: + if (fmt->fmt.sliced.io_size == 0) + return -EINVAL; + break; + default: + /* Overlay formats are invalid */ + return -EINVAL; + } + return ops->vidioc_create_bufs(file, fh, create); } static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,