From patchwork Thu Nov 10 05:24:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu-Cheng Li X-Patchwork-Id: 9420649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 995D26048E for ; Thu, 10 Nov 2016 05:25:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 851EA28F52 for ; Thu, 10 Nov 2016 05:25:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75BED28F87; Thu, 10 Nov 2016 05:25:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 046C628F52 for ; Thu, 10 Nov 2016 05:25:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c4hrK-0004z7-6W; Thu, 10 Nov 2016 05:25:10 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c4hr1-0004T2-Db for linux-mediatek@lists.infradead.org; Thu, 10 Nov 2016 05:24:52 +0000 Received: by mail-pf0-x230.google.com with SMTP id 189so140060278pfz.3 for ; Wed, 09 Nov 2016 21:24:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/OeWjoTQ0tO4XCq1vAFV8oJYsqQU4iXms1fnDjTAmWA=; b=IfV8ClkLm/4HKHPGj4l0Rm48Sp3hM3OB572sNe/DtLD7bGEhi7q5ihQDrXSSvD0Jlv 6B/CR3g6/gUWKJJOxWILIrD9cJJ6ipy1iduocpUa3SP+jpgdgC8j+T1QnFrYkK0KWM3J bX685R9dpjGbDsgqhcBJ0oY5Nq8tUOqC91AmA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/OeWjoTQ0tO4XCq1vAFV8oJYsqQU4iXms1fnDjTAmWA=; b=YyFRRs8HklBozfLb8Z3NH6+SbBkPKQgU6U8tim84f/z4QEdkvt6bbS5w3EBaDcGl40 1v616OdDu64MlfmX8GpZ86yEy5IJWeRBusjCCtXRwELSHmFZDMo3r778tsNatVmWxPHQ 4nT4uN3r7Loxl5uKVPjqpzjBeh/DuOE5XX1DPAs3LmSAL3y3Q5s+07LWiYIiA5vT/4vY VwBfgad1t+gwNAtcyyKZ4AG5k94mIwIJyIpcejVEkQOm/Uu63vLSteYKDAn0YkhcPslq vWOL8BRWvzXK1EdoMdwVGnzptmt3pESgTaTNhsSYyHBNuFveWqqpH4V9ujY4yk0RphMq urpw== X-Gm-Message-State: ABUngvfIDt/ihz68pg5T1JF0mPWs4LsHgtRkSQHwU653RVZ579OP8IOtVoUsukDoEmAxyKpz X-Received: by 10.98.208.70 with SMTP id p67mr6505927pfg.15.1478755469875; Wed, 09 Nov 2016 21:24:29 -0800 (PST) Received: from wuchengli-z840.tpe.corp.google.com ([172.30.210.26]) by smtp.gmail.com with ESMTPSA id 3sm3216403pam.21.2016.11.09.21.24.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Nov 2016 21:24:29 -0800 (PST) From: Wu-Cheng Li To: pawel@osciak.com, tiffany.lin@mediatek.com, andrew-ct.chen@mediatek.com, mchehab@kernel.org, matthias.bgg@gmail.com, djkurtz@chromium.org, dan.carpenter@oracle.com Subject: [PATCH v1] mtk-vcodec: add index check in decoder vidioc_qbuf. Date: Thu, 10 Nov 2016 13:24:05 +0800 Message-Id: <1478755445-23494-2-git-send-email-wuchengli@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1478755445-23494-1-git-send-email-wuchengli@chromium.org> References: <1478755445-23494-1-git-send-email-wuchengli@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161109_212451_611871_7BEBA763 X-CRM114-Status: UNSURE ( 8.95 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wu-Cheng Li , linux-kernel@vger.kernel.org, Wu-Cheng Li , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wu-Cheng Li vb2_qbuf will check the buffer index. If a driver overrides vidioc_qbuf and use the buffer index, the driver needs to check the index. Signed-off-by: Wu-Cheng Li --- drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c index 0520919..0746592 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c @@ -533,6 +533,10 @@ static int vidioc_vdec_qbuf(struct file *file, void *priv, } vq = v4l2_m2m_get_vq(ctx->m2m_ctx, buf->type); + if (buf->index >= vq->num_buffers) { + mtk_v4l2_debug(1, "buffer index %d out of range", buf->index); + return -EINVAL; + } vb = vq->bufs[buf->index]; vb2_v4l2 = container_of(vb, struct vb2_v4l2_buffer, vb2_buf); mtkbuf = container_of(vb2_v4l2, struct mtk_video_dec_buf, vb);