DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] vhost: fix crash on vhost-user client port deletion
@ 2023-03-21  6:23 suntianyuan
  2023-05-11  8:26 ` Xia, Chenbo
  0 siblings, 1 reply; 4+ messages in thread
From: suntianyuan @ 2023-03-21  6:23 UTC (permalink / raw)
  To: maxime.coquelin, chenbo.xia; +Cc: dev, suntianyuan

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 excute vhost_user_remove_reconnect
vhost_user_read_cb thread excute 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 excute vhost_user_socket_mem_free
vhost_user_client_reconnect access invalid mem, crash

Signed-off-by: suntianyuan <suntianyuan@baidu.com>
---
 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)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] vhost: fix crash on vhost-user client port deletion
  2023-03-21  6:23 [PATCH] vhost: fix crash on vhost-user client port deletion suntianyuan
@ 2023-05-11  8:26 ` Xia, Chenbo
  2023-05-11 14:59   ` [PATCH v2] " suntianyuan
  0 siblings, 1 reply; 4+ messages in thread
From: Xia, Chenbo @ 2023-05-11  8:26 UTC (permalink / raw)
  To: suntianyuan, maxime.coquelin; +Cc: dev

Hi Tianyuan,

> -----Original Message-----
> From: suntianyuan <suntianyuan@baidu.com>
> Sent: Tuesday, March 21, 2023 2:24 PM
> To: maxime.coquelin@redhat.com; Xia, Chenbo <chenbo.xia@intel.com>
> Cc: dev@dpdk.org; suntianyuan <suntianyuan@baidu.com>
> Subject: [PATCH] vhost: fix crash on vhost-user client port deletion
> 
> 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 excute vhost_user_remove_reconnect
> vhost_user_read_cb thread excute 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 excute
> vhost_user_socket_mem_free
> vhost_user_client_reconnect access invalid mem, crash
> 
> Signed-off-by: suntianyuan <suntianyuan@baidu.com>

There are several coding style issues. Please check and fix:

http://mails.dpdk.org/archives/test-report/2023-March/374602.html

Thanks,
Chenbo

> ---
>  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)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] vhost: fix crash on vhost-user client port deletion
  2023-05-11  8:26 ` Xia, Chenbo
@ 2023-05-11 14:59   ` suntianyuan
  2024-10-04 16:04     ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: suntianyuan @ 2023-05-11 14:59 UTC (permalink / raw)
  To: chenbo.xia; +Cc: dev, maxime.coquelin, suntianyuan

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)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] vhost: fix crash on vhost-user client port deletion
  2023-05-11 14:59   ` [PATCH v2] " suntianyuan
@ 2024-10-04 16:04     ` Stephen Hemminger
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2024-10-04 16:04 UTC (permalink / raw)
  To: suntianyuan; +Cc: chenbo.xia, dev, maxime.coquelin

On Thu, 11 May 2023 22:59:57 +0800
suntianyuan <suntianyuan@baidu.com> wrote:

> 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>

There is a test failure in the vf jumbo frames that needs evaluation.
And this kind of patch needs ack from Maxime.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-04 16:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-21  6:23 [PATCH] vhost: fix crash on vhost-user client port deletion suntianyuan
2023-05-11  8:26 ` Xia, Chenbo
2023-05-11 14:59   ` [PATCH v2] " suntianyuan
2024-10-04 16:04     ` Stephen Hemminger

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).