DPDK patches and discussions
 help / color / mirror / Atom feed
From: suntianyuan <suntianyuan@baidu.com>
To: <chenbo.xia@intel.com>
Cc: <dev@dpdk.org>, <maxime.coquelin@redhat.com>, <suntianyuan@baidu.com>
Subject: [PATCH v2] vhost: fix crash on vhost-user client port deletion
Date: Thu, 11 May 2023 22:59:57 +0800	[thread overview]
Message-ID: <20230511145957.33904-1-suntianyuan@baidu.com> (raw)
In-Reply-To: <SN6PR11MB35042FDAA797B9969AE05AF99C749@SN6PR11MB3504.namprd11.prod.outlook.com>

The rte_vhost_driver_unregister() and vhost_user_read_cb() can be
called at the same time by 2 threads. reconn may be added back to
reconn_list by vhost_user_read_cb() after rte_vhost_driver_unregister()
removed from reconn_list. Then rte_vhost_driver_unregister free vsocket,
cause vhost_user_client_reconnect access invalid vsocket memory.

Timeline is as below:
rte_vhost_driver_unregister thread execute vhost_user_remove_reconnect
vhost_user_read_cb thread execute vhost_user_start_client add reconn to
reconn_list
vhost_user_read_cb thread free conn
rte_vhost_driver_unregister thread cannot find conn, then execute
vhost_user_socket_mem_free
vhost_user_client_reconnect access invalid mem, crash

Signed-off-by: suntianyuan <suntianyuan@baidu.com>
---
v2:
* Fixed coding style issues.

 lib/vhost/socket.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
index 669c322e12..72c776d15c 100644
--- a/lib/vhost/socket.c
+++ b/lib/vhost/socket.c
@@ -1046,8 +1046,6 @@ rte_vhost_driver_unregister(const char *path)
 				pthread_mutex_unlock(&vhost_user.mutex);
 				goto again;
 			}
-		} else if (vsocket->reconnect) {
-			vhost_user_remove_reconnect(vsocket);
 		}
 
 		pthread_mutex_lock(&vsocket->conn_mutex);
@@ -1080,6 +1078,8 @@ rte_vhost_driver_unregister(const char *path)
 		if (vsocket->is_server) {
 			close(vsocket->socket_fd);
 			unlink(path);
+		} else if (vsocket->reconnect) {
+			vhost_user_remove_reconnect(vsocket);
 		}
 
 		pthread_mutex_destroy(&vsocket->conn_mutex);
-- 
2.32.0 (Apple Git-132)


  reply	other threads:[~2023-05-11 15:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21  6:23 [PATCH] " suntianyuan
2023-05-11  8:26 ` Xia, Chenbo
2023-05-11 14:59   ` suntianyuan [this message]
2024-10-04 16:04     ` [PATCH v2] " Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230511145957.33904-1-suntianyuan@baidu.com \
    --to=suntianyuan@baidu.com \
    --cc=chenbo.xia@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).