From patchwork Fri Apr 20 10:09:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10352367 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 836C760231 for ; Fri, 20 Apr 2018 10:09:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7399A286EF for ; Fri, 20 Apr 2018 10:09:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67EAE2870D; Fri, 20 Apr 2018 10:09:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY 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 2565C28707 for ; Fri, 20 Apr 2018 10:09:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754437AbeDTKJk (ORCPT ); Fri, 20 Apr 2018 06:09:40 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:47122 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754294AbeDTKJj (ORCPT ); Fri, 20 Apr 2018 06:09:39 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3KA0vtm138363; Fri, 20 Apr 2018 10:09:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2017-10-26; bh=mjsImSB5j9tBncTdTPCQ1Y5rtiYulHjphrvVvqrgWss=; b=tj9r7RRgSHP9HURCpXNF2nrTDjXIY7XDQ5tigTSJQ4z4adH3p2RJwgBGAr+qdnxKVZJp mtYD6f21porKjfkFxIhd4tpUkqGlbXAsuGh/cjyDgycO9MX41BhaZI8TK4wbxm81+ZAW KBm0eaIKl2L0uurorEc0MhHznOOgvQVGCgWJiPq13skCSaNukJnamWLOGh/FKb+wvpMj miuMHa3Ddj2GN3QZhbffZ16qNQCUrcWonyf++zvaoRLjwkU8UI5QdY4ux8TuEhbEMtkC j8W4wK9hB7XKVosL5vjwTYdCrLLe016soW0Oo7cPpuWNkGzGW+0rWWi4hXQRVE5BiACw HQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2hf7amsa4m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Apr 2018 10:09:35 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w3KA9YC3024979 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Apr 2018 10:09:35 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w3KA9Y4p032469; Fri, 20 Apr 2018 10:09:34 GMT Received: from mwanda (/197.254.35.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 20 Apr 2018 03:09:33 -0700 Date: Fri, 20 Apr 2018 13:09:27 +0300 From: Dan Carpenter To: Mauro Carvalho Chehab Cc: Greg Kroah-Hartman , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, kernel-janitors@vger.kernel.org Subject: [PATCH] media: davinci_vpfe: fix some potential overflows Message-ID: <20180420100927.GA30237@mwanda> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8868 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804200098 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 We check "lutdpc->dpc_size" in ipipe_validate_lutdpc_params() but if it's invalid then we would have corrupted memory already when we do the memcpy() before calling it. We don't ever check "gamma->tbl_size" but we should since they come from the user. Signed-off-by: Dan Carpenter diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c index 95942768639c..068b3333e224 100644 --- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.c +++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.c @@ -82,6 +82,8 @@ static int ipipe_set_lutdpc_params(struct vpfe_ipipe_device *ipipe, void *param) lutdpc->en = dpc_param->en; lutdpc->repl_white = dpc_param->repl_white; lutdpc->dpc_size = dpc_param->dpc_size; + if (dpc_param->dpc_size > LUT_DPC_MAX_SIZE) + return -EINVAL; memcpy(&lutdpc->table, &dpc_param->table, (dpc_param->dpc_size * sizeof(struct vpfe_ipipe_lutdpc_entry))); if (ipipe_validate_lutdpc_params(lutdpc) < 0) @@ -591,7 +593,7 @@ ipipe_validate_gamma_entry(struct vpfe_ipipe_gamma_entry *table, int size) static int ipipe_validate_gamma_params(struct vpfe_ipipe_gamma *gamma, struct device *dev) { - int table_size; + unsigned int table_size; int err; if (gamma->bypass_r > 1 || @@ -603,6 +605,8 @@ ipipe_validate_gamma_params(struct vpfe_ipipe_gamma *gamma, struct device *dev) return 0; table_size = gamma->tbl_size; + if (table_size > VPFE_IPIPE_MAX_SIZE_GAMMA) + return -EINVAL; if (!gamma->bypass_r) { err = ipipe_validate_gamma_entry(gamma->table_r, table_size); if (err) {