vhost: fix device leak on connection add failure

Message ID 20190411102306.11943-1-i.maximets@samsung.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series vhost: fix device leak on connection add failure |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Ilya Maximets April 11, 2019, 10:23 a.m. UTC
  Need to destroy allocated device if application fails to
add new connection or we have fdset failure.

Fixes: acbff5c67ea7 ("vhost: fix crash when exceeding file descriptors")
Fixes: efba12a78ddf ("vhost: add user callbacks for socket open/close")
Cc: stable@dpdk.org

Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
---
 lib/librte_vhost/socket.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

David Marchand April 11, 2019, 2:06 p.m. UTC | #1
On Thu, Apr 11, 2019 at 12:23 PM Ilya Maximets <i.maximets@samsung.com>
wrote:

> Need to destroy allocated device if application fails to
> add new connection or we have fdset failure.
>
> Fixes: acbff5c67ea7 ("vhost: fix crash when exceeding file descriptors")
> Fixes: efba12a78ddf ("vhost: add user callbacks for socket open/close")
> Cc: stable@dpdk.org
>
> Reported-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> ---
>  lib/librte_vhost/socket.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
> index 43f091d10..c34668004 100644
> --- a/lib/librte_vhost/socket.c
> +++ b/lib/librte_vhost/socket.c
> @@ -240,7 +240,7 @@ vhost_user_add_connection(int fd, struct
> vhost_user_socket *vsocket)
>                         RTE_LOG(ERR, VHOST_CONFIG,
>                                 "failed to add vhost user connection with
> fd %d\n",
>                                 fd);
> -                       goto err;
> +                       goto err_cleanup;
>                 }
>         }
>
> @@ -257,7 +257,7 @@ vhost_user_add_connection(int fd, struct
> vhost_user_socket *vsocket)
>                 if (vsocket->notify_ops->destroy_connection)
>                         vsocket->notify_ops->destroy_connection(conn->vid);
>
> -               goto err;
> +               goto err_cleanup;
>         }
>
>         pthread_mutex_lock(&vsocket->conn_mutex);
> @@ -267,6 +267,8 @@ vhost_user_add_connection(int fd, struct
> vhost_user_socket *vsocket)
>         fdset_pipe_notify(&vhost_user.fdset);
>         return;
>
> +err_cleanup:
> +       vhost_destroy_device(vid);
>  err:
>         free(conn);
>         close(fd);
> --
> 2.17.1
>

Thanks Ilya.

Reviewed-by: David Marchand <david.marchand@redhat.com>
  
Jens Freimann April 11, 2019, 2:30 p.m. UTC | #2
On Thu, Apr 11, 2019 at 01:23:06PM +0300, Ilya Maximets wrote:
>Need to destroy allocated device if application fails to
>add new connection or we have fdset failure.
>
>Fixes: acbff5c67ea7 ("vhost: fix crash when exceeding file descriptors")
>Fixes: efba12a78ddf ("vhost: add user callbacks for socket open/close")
>Cc: stable@dpdk.org
>
>Reported-by: David Marchand <david.marchand@redhat.com>
>Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
>---
> lib/librte_vhost/socket.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>

Reviewed-by: Jens Freimann <jfreimann@redhat.com>
  
Tiwei Bie April 15, 2019, 6:32 a.m. UTC | #3
On Thu, Apr 11, 2019 at 01:23:06PM +0300, Ilya Maximets wrote:
> Need to destroy allocated device if application fails to
> add new connection or we have fdset failure.
> 
> Fixes: acbff5c67ea7 ("vhost: fix crash when exceeding file descriptors")
> Fixes: efba12a78ddf ("vhost: add user callbacks for socket open/close")
> Cc: stable@dpdk.org
> 
> Reported-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
> ---
>  lib/librte_vhost/socket.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
  
Maxime Coquelin April 17, 2019, 7:55 a.m. UTC | #4
On 4/11/19 12:23 PM, Ilya Maximets wrote:
> Need to destroy allocated device if application fails to
> add new connection or we have fdset failure.
> 
> Fixes: acbff5c67ea7 ("vhost: fix crash when exceeding file descriptors")
> Fixes: efba12a78ddf ("vhost: add user callbacks for socket open/close")
> Cc:stable@dpdk.org
> 
> Reported-by: David Marchand<david.marchand@redhat.com>
> Signed-off-by: Ilya Maximets<i.maximets@samsung.com>
> ---
>   lib/librte_vhost/socket.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)


Applied to dpdk-next-virtio/master.

Thanks,
Maxime
  

Patch

diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index 43f091d10..c34668004 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -240,7 +240,7 @@  vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
 			RTE_LOG(ERR, VHOST_CONFIG,
 				"failed to add vhost user connection with fd %d\n",
 				fd);
-			goto err;
+			goto err_cleanup;
 		}
 	}
 
@@ -257,7 +257,7 @@  vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
 		if (vsocket->notify_ops->destroy_connection)
 			vsocket->notify_ops->destroy_connection(conn->vid);
 
-		goto err;
+		goto err_cleanup;
 	}
 
 	pthread_mutex_lock(&vsocket->conn_mutex);
@@ -267,6 +267,8 @@  vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket)
 	fdset_pipe_notify(&vhost_user.fdset);
 	return;
 
+err_cleanup:
+	vhost_destroy_device(vid);
 err:
 	free(conn);
 	close(fd);