From patchwork Thu Dec 28 13:09:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 10134635 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 0AE6660212 for ; Thu, 28 Dec 2017 13:09:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F06502D57B for ; Thu, 28 Dec 2017 13:09:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2AF82D5D9; Thu, 28 Dec 2017 13:09:25 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A37B2D57B for ; Thu, 28 Dec 2017 13:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753404AbdL1NJY (ORCPT ); Thu, 28 Dec 2017 08:09:24 -0500 Received: from osg.samsung.com ([64.30.133.232]:48194 "EHLO osg.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752885AbdL1NJX (ORCPT ); Thu, 28 Dec 2017 08:09:23 -0500 Received: from localhost (localhost [127.0.0.1]) by osg.samsung.com (Postfix) with ESMTP id E2052267B1; Thu, 28 Dec 2017 05:09:22 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at dev.s-opensource.com X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from osg.samsung.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nQfiJdEauo3g; Thu, 28 Dec 2017 05:09:21 -0800 (PST) Received: from smtp.s-opensource.com (179.176.121.132.dynamic.adsl.gvt.net.br [179.176.121.132]) by osg.samsung.com (Postfix) with ESMTPSA id 981902679F; Thu, 28 Dec 2017 05:09:21 -0800 (PST) Received: from mchehab by smtp.s-opensource.com with local (Exim 4.89) (envelope-from ) id 1eUXvy-0002mx-ST; Thu, 28 Dec 2017 11:09:18 -0200 From: Mauro Carvalho Chehab To: Linux Media Mailing List Cc: Mauro Carvalho Chehab , Mauro Carvalho Chehab , Inki Dae , Junghak Sung , Seung-Woo Kim , Satendra Singh Thakur Subject: [PATCH 2/2] media: dvb_vb2: limit reqbufs size to a sane value Date: Thu, 28 Dec 2017 11:09:17 -0200 Message-Id: <250e67e6e82643336d047e41780fbb72dc33687d.1514466421.git.mchehab@s-opensource.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <60dd6554070454d7f76c9d6d65f4ec8fc370b994.1514466421.git.mchehab@s-opensource.com> References: <60dd6554070454d7f76c9d6d65f4ec8fc370b994.1514466421.git.mchehab@s-opensource.com> In-Reply-To: <60dd6554070454d7f76c9d6d65f4ec8fc370b994.1514466421.git.mchehab@s-opensource.com> References: <60dd6554070454d7f76c9d6d65f4ec8fc370b994.1514466421.git.mchehab@s-opensource.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is not a good idea to let users to request a very high buffer size. So, add an upper limit. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb-core/dvb_vb2.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c index ccb99cfed2b3..d9fafeeb0d04 100644 --- a/drivers/media/dvb-core/dvb_vb2.c +++ b/drivers/media/dvb-core/dvb_vb2.c @@ -19,6 +19,8 @@ #include "dvbdev.h" #include "dvb_vb2.h" +#define DVB_V2_MAX_SIZE (4096 * 188) + static int vb2_debug; module_param(vb2_debug, int, 0644); @@ -330,6 +332,12 @@ int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req) { int ret; + /* Adjust size to a sane value */ + if (req->size > DVB_V2_MAX_SIZE) + req->size = DVB_V2_MAX_SIZE; + + /* FIXME: round req->size to a 188 or 204 multiple */ + ctx->buf_siz = req->size; ctx->buf_cnt = req->count; ret = vb2_core_reqbufs(&ctx->vb_q, VB2_MEMORY_MMAP, &req->count);