From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from skyloft.patrickmacarthur.net (skyloft.patrickmacarthur.net [45.55.141.197]) by dpdk.org (Postfix) with ESMTP id B98553B5 for ; Fri, 27 Jan 2017 00:06:13 +0100 (CET) Received: from groose.iol.unh.edu (groose.iol.unh.edu [132.177.124.21]) by skyloft.patrickmacarthur.net (Postfix) with ESMTPSA id 2A15F42120; Thu, 26 Jan 2017 18:06:13 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=patrickmacarthur.net; s=mail; t=1485471973; bh=iKVIqbH4d18uUw3xHwDdaI/Wsa/oFqTVJ3ki+GQW+cA=; h=From:To:Cc:Subject:Date; b=MxBVYI6kCZ4xef2f6o0PdsJA1T5zaFpAuQYF324WZX4LVQ3Pma59uTDUSQOi3p8ek mjHe+5us/0RVxhbOIEdIh10TdizwlDeTyqLwU7X+hmfjh9pQH2EzFrFSzAyWq7fF5t gtfbxRxsfwTXHjZbAjrRYieVLRl93jAIjzRJd1Bc= From: Patrick MacArthur To: dev@dpdk.org, Anatoly Burakov Cc: Patrick MacArthur Date: Thu, 26 Jan 2017 18:05:21 -0500 Message-Id: <20170126230521.28314-1-patrick@patrickmacarthur.net> X-Mailer: git-send-email 2.9.3 X-Spam-Status: No, score=-1.1 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on skyloft.patrickmacarthur.net Subject: [dpdk-dev] [PATCH] vfio: fix file descriptor leak in multi-process applications 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: , X-List-Received-Date: Thu, 26 Jan 2017 23:06:13 -0000 When a secondary process wants access to the VFIO container file descriptor, the primary process calls vfio_get_container_fd() which always opens an entirely new file descriptor on /dev/vfio/vfio. However, once the file descriptor has been passed to the subprocess, it is effectively duplicated, meaning that the copy of the file descriptor in the primary process is no longer needed. However, the primary process does not close the duplicate fd, which results in a resource leak. This can be reproduced by starting a primary process with a small RLIMIT_NOFILE limit configured to use VFIO for at least one device, and repeatedly launching secondary processes until the file descriptor limit is exceeded. Fix the resource leak by closing the local vfio container file descriptor after passing it to the secondary process. Fixes: 2f4adfad0a69 ("vfio: add multiprocess support") Signed-off-by: Patrick MacArthur --- lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c index 00cf919b64d0..fb4a2f84b180 100644 --- a/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c +++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c @@ -301,6 +301,7 @@ vfio_mp_sync_thread(void __rte_unused * arg) vfio_mp_sync_send_request(conn_sock, SOCKET_ERR); else vfio_mp_sync_send_fd(conn_sock, fd); + close(fd); break; case SOCKET_REQ_GROUP: /* wait for group number */ -- 2.9.3