From patchwork Fri Oct 30 00:21:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Huang X-Patchwork-Id: 82854 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A9216A04DD; Fri, 30 Oct 2020 02:22:10 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A6E9CCC69; Fri, 30 Oct 2020 02:21:42 +0100 (CET) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id E17FECC19 for ; Fri, 30 Oct 2020 02:21:38 +0100 (CET) IronPort-SDR: 3E06O3aPy8Uj1+31CmhqbGKmPEEZGApsBcZ1DFDy/eAnuZzlH5OHCdvFULQqWXav2RDf539lhb XySJ7pgbAe5Q== X-IronPort-AV: E=McAfee;i="6000,8403,9789"; a="148397911" X-IronPort-AV: E=Sophos;i="5.77,431,1596524400"; d="scan'208";a="148397911" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2020 18:21:38 -0700 IronPort-SDR: 7uJkFBobTyYFIVf07BkmnNxRJ1L9vgAze44aow7L4wqm0A8HR0f3uOTf1X2DiXd3gU1qhUmM83 gccgRa2laK5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,431,1596524400"; d="scan'208";a="536888796" Received: from unknown (HELO sh_lab5_1.sh.intel.com) ([10.238.175.190]) by orsmga005.jf.intel.com with ESMTP; 29 Oct 2020 18:21:36 -0700 From: Wei Huang To: dev@dpdk.org, rosen.xu@intel.com, qi.z.zhang@intel.com Cc: Wei Huang Date: Thu, 29 Oct 2020 20:21:34 -0400 Message-Id: <1604017294-23479-3-git-send-email-wei.huang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1604017294-23479-1-git-send-email-wei.huang@intel.com> References: <1604017294-23479-1-git-send-email-wei.huang@intel.com> Subject: [dpdk-dev] [PATCH v2 2/2] raw/ifpga: use trusted buffer to free X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In rte_fpga_do_pr, calling function read() may taints argument buffer which turn to an untrusted value as argumen of rte_free(). Fixes: ef1e8ede3da5 ("raw/ifpga: add Intel FPGA bus rawdev driver") Signed-off-by: Wei Huang --- v2: add fixes information to log --- drivers/raw/ifpga/ifpga_rawdev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index f9de167..27129b1 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -786,7 +786,7 @@ rte_fpga_do_pr(struct rte_rawdev *rawdev, int port_id, int file_fd; int ret = 0; ssize_t buffer_size; - void *buffer; + void *buffer, *buf_to_free; u64 pr_error; if (!file_name) @@ -818,6 +818,7 @@ rte_fpga_do_pr(struct rte_rawdev *rawdev, int port_id, ret = -ENOMEM; goto close_fd; } + buf_to_free = buffer; /*read the raw data*/ if (buffer_size != read(file_fd, (void *)buffer, buffer_size)) { @@ -835,8 +836,8 @@ rte_fpga_do_pr(struct rte_rawdev *rawdev, int port_id, } free_buffer: - if (buffer) - rte_free(buffer); + if (buf_to_free) + rte_free(buf_to_free); close_fd: close(file_fd); file_fd = 0;