From patchwork Fri Aug 16 12:13:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Harris, James R" X-Patchwork-Id: 57729 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DB5DE1BF15; Fri, 16 Aug 2019 21:18:51 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id A45F41BF0D for ; Fri, 16 Aug 2019 21:18:50 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Aug 2019 12:18:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,394,1559545200"; d="scan'208";a="377512502" Received: from jrharri1-skx.ch.intel.com (HELO [127.0.1.1]) ([143.182.137.73]) by fmsmga006.fm.intel.com with ESMTP; 16 Aug 2019 12:18:49 -0700 From: Jim Harris To: dev@dpdk.org, anatoly.burakov@intel.com Date: Fri, 16 Aug 2019 05:13:42 -0700 Message-ID: <156595762238.18723.10089009448135563310.stgit@jrharri1-skx> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] vfio: free mp_reply msgs in failure cases 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" The code checks both rte_mp_request_sync() return code and that the number of messages in the reply equals 1. If rte_mp_request_sync() succeeds but there was more than one message, those messages would get leaked. Found via code review by Anatoly Burakov of patches that used the vhost code as a template for using rte_mp_request_sync(). Signed-off-by: Jim Harris Acked-by: Anatoly Burakov --- lib/librte_eal/linux/eal/eal_vfio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/librte_eal/linux/eal/eal_vfio.c b/lib/librte_eal/linux/eal/eal_vfio.c index 501c74f23..d9541b122 100644 --- a/lib/librte_eal/linux/eal/eal_vfio.c +++ b/lib/librte_eal/linux/eal/eal_vfio.c @@ -264,7 +264,7 @@ vfio_open_group_fd(int iommu_group_num) int vfio_group_fd; char filename[PATH_MAX]; struct rte_mp_msg mp_req, *mp_rep; - struct rte_mp_reply mp_reply; + struct rte_mp_reply mp_reply = {0}; struct timespec ts = {.tv_sec = 5, .tv_nsec = 0}; struct vfio_mp_param *p = (struct vfio_mp_param *)mp_req.param; @@ -320,9 +320,9 @@ vfio_open_group_fd(int iommu_group_num) RTE_LOG(ERR, EAL, " bad VFIO group fd\n"); vfio_group_fd = 0; } - free(mp_reply.msgs); } + free(mp_reply.msgs); if (vfio_group_fd < 0) RTE_LOG(ERR, EAL, " cannot request group fd\n"); return vfio_group_fd; @@ -554,7 +554,7 @@ static int vfio_sync_default_container(void) { struct rte_mp_msg mp_req, *mp_rep; - struct rte_mp_reply mp_reply; + struct rte_mp_reply mp_reply = {0}; struct timespec ts = {.tv_sec = 5, .tv_nsec = 0}; struct vfio_mp_param *p = (struct vfio_mp_param *)mp_req.param; int iommu_type_id; @@ -584,8 +584,8 @@ vfio_sync_default_container(void) p = (struct vfio_mp_param *)mp_rep->param; if (p->result == SOCKET_OK) iommu_type_id = p->iommu_type_id; - free(mp_reply.msgs); } + free(mp_reply.msgs); if (iommu_type_id < 0) { RTE_LOG(ERR, EAL, "Could not get IOMMU type for default container\n"); return -1; @@ -1021,7 +1021,7 @@ int vfio_get_default_container_fd(void) { struct rte_mp_msg mp_req, *mp_rep; - struct rte_mp_reply mp_reply; + struct rte_mp_reply mp_reply = {0}; struct timespec ts = {.tv_sec = 5, .tv_nsec = 0}; struct vfio_mp_param *p = (struct vfio_mp_param *)mp_req.param; @@ -1049,9 +1049,9 @@ vfio_get_default_container_fd(void) free(mp_reply.msgs); return mp_rep->fds[0]; } - free(mp_reply.msgs); } + free(mp_reply.msgs); RTE_LOG(ERR, EAL, " cannot request default container fd\n"); return -1; } @@ -1127,7 +1127,7 @@ rte_vfio_get_container_fd(void) { int ret, vfio_container_fd; struct rte_mp_msg mp_req, *mp_rep; - struct rte_mp_reply mp_reply; + struct rte_mp_reply mp_reply = {0}; struct timespec ts = {.tv_sec = 5, .tv_nsec = 0}; struct vfio_mp_param *p = (struct vfio_mp_param *)mp_req.param; @@ -1181,9 +1181,9 @@ rte_vfio_get_container_fd(void) free(mp_reply.msgs); return vfio_container_fd; } - free(mp_reply.msgs); } + free(mp_reply.msgs); RTE_LOG(ERR, EAL, " cannot request container fd\n"); return -1; }