From 8d7e75be24f21126193d4b97d2cd433c4c46a716 Mon Sep 17 00:00:00 2001 From: Zhiqiang Liu Date: Sun, 13 Jun 2021 20:12:17 +0800 Subject: [PATCH] nvmf: fix fd leakage problem in nvmf_vfio_user_listen() In nvmf_vfio_user_listen(), fd should be closed before set it to endpoint->fd, otherwise, the fd leakage probem occurs. Signed-off-by: Zhiqiang Liu Change-Id: I3fabc65d2764926e5873475962e4362e46eb37e4 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8309 Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: sunshihao Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins --- lib/nvmf/vfio_user.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index ac8ae9081..5f9776734 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -1708,6 +1708,7 @@ nvmf_vfio_user_listen(struct spdk_nvmf_transport *transport, } free(path); + endpoint->fd = fd; err = ftruncate(fd, NVMF_VFIO_USER_DOORBELLS_OFFSET + NVMF_VFIO_USER_DOORBELLS_SIZE); if (err != 0) { goto out; @@ -1721,8 +1722,6 @@ nvmf_vfio_user_listen(struct spdk_nvmf_transport *transport, goto out; } - endpoint->fd = fd; - snprintf(uuid, PATH_MAX, "%s/cntrl", endpoint_id(endpoint)); endpoint->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, uuid, LIBVFIO_USER_FLAG_ATTACH_NB,