From 2bd41c5187b5af3951e7ffb9bdb45d50f530d3ff Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Mon, 27 Dec 2021 15:40:37 +0800 Subject: [PATCH] nvmf/tcp: do cleanup in nvmf_tcp_poll_group_add() we don't remove the socket fd from socket group when nvmf_tcp_poll_group_add() return error, and when closing the socket there is an assertion. This was found via llvm_nvme_fuzz via TCP transport. Change-Id: Ib4ab6fc3fc5e2bc6a9545f6ce854bae8f1157fd5 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10849 Reviewed-by: Ben Walker Reviewed-by: Jim Harris Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins --- lib/nvmf/tcp.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/nvmf/tcp.c b/lib/nvmf/tcp.c index 6459b10372..f3e9df13de 100644 --- a/lib/nvmf/tcp.c +++ b/lib/nvmf/tcp.c @@ -2749,14 +2749,6 @@ nvmf_tcp_poll_group_add(struct spdk_nvmf_transport_poll_group *group, tgroup = SPDK_CONTAINEROF(group, struct spdk_nvmf_tcp_poll_group, group); tqpair = SPDK_CONTAINEROF(qpair, struct spdk_nvmf_tcp_qpair, qpair); - rc = spdk_sock_group_add_sock(tgroup->sock_group, tqpair->sock, - nvmf_tcp_sock_cb, tqpair); - if (rc != 0) { - SPDK_ERRLOG("Could not add sock to sock_group: %s (%d)\n", - spdk_strerror(errno), errno); - return -1; - } - rc = nvmf_tcp_qpair_sock_init(tqpair); if (rc != 0) { SPDK_ERRLOG("Cannot set sock opt for tqpair=%p\n", tqpair); @@ -2775,6 +2767,14 @@ nvmf_tcp_poll_group_add(struct spdk_nvmf_transport_poll_group *group, return -1; } + rc = spdk_sock_group_add_sock(tgroup->sock_group, tqpair->sock, + nvmf_tcp_sock_cb, tqpair); + if (rc != 0) { + SPDK_ERRLOG("Could not add sock to sock_group: %s (%d)\n", + spdk_strerror(errno), errno); + return -1; + } + tqpair->group = tgroup; nvmf_tcp_qpair_set_state(tqpair, NVME_TCP_QPAIR_STATE_INVALID); TAILQ_INSERT_TAIL(&tgroup->qpairs, tqpair, link);