summaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/virtio
diff options
context:
space:
mode:
authorHaiyang Tan <haiyang.tan.dev@gmail.com>2018-02-06 11:16:48 -0500
committerDamjan Marion <dmarion.lists@gmail.com>2018-02-08 20:33:17 +0000
commit2ae5135e4cc47f5be8895486a91ad98be36dd5dd (patch)
treedf317c8f249d3a1ddbf4819d65d2f9363766272f /src/vnet/devices/virtio
parentb81831d122d59b55c7d42b39e4fd9e94b7d40aca (diff)
vhostuser: Fix vhostuser file descriptor leak
In the case that vhostuser server accepted more than one client connection, 'vui->clib_file_index' will be overwritten directly without release the possible existed resource, so file descriptor leak occurs Change-Id: I89d08133dae31a12a815df2631334dbf0aefeb1e Signed-off-by: Haiyang Tan <haiyang.tan.dev@gmail.com>
Diffstat (limited to 'src/vnet/devices/virtio')
-rw-r--r--src/vnet/devices/virtio/vhost-user.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/vnet/devices/virtio/vhost-user.c b/src/vnet/devices/virtio/vhost-user.c
index be3405488fe..5460f10b74e 100644
--- a/src/vnet/devices/virtio/vhost-user.c
+++ b/src/vnet/devices/virtio/vhost-user.c
@@ -97,10 +97,11 @@
*/
#define VHOST_USER_TX_COPY_THRESHOLD (VHOST_USER_COPY_ARRAY_N - 40)
-#define UNIX_GET_FD(unixfd_idx) \
- (unixfd_idx != ~0) ? \
+#define UNIX_GET_FD(unixfd_idx) ({ \
+ typeof(unixfd_idx) __unixfd_idx = (unixfd_idx); \
+ (__unixfd_idx != ~0) ? \
pool_elt_at_index (file_main.file_pool, \
- unixfd_idx)->file_descriptor : -1;
+ __unixfd_idx)->file_descriptor : -1; })
#define foreach_virtio_trace_flags \
_ (SIMPLE_CHAINED, 0, "Simple descriptor chaining") \
@@ -1282,7 +1283,15 @@ vhost_user_socksvr_accept_ready (clib_file_t * uf)
if (client_fd < 0)
return clib_error_return_unix (0, "accept");
- DBG_SOCK ("New client socket for vhost interface %d", vui->sw_if_index);
+ if (vui->clib_file_index != ~0)
+ {
+ DBG_SOCK ("Close client socket for vhost interface %d, fd %d",
+ vui->sw_if_index, UNIX_GET_FD (vui->clib_file_index));
+ clib_file_del (&file_main, file_main.file_pool + vui->clib_file_index);
+ }
+
+ DBG_SOCK ("New client socket for vhost interface %d, fd %d",
+ vui->sw_if_index, client_fd);
template.read_function = vhost_user_socket_read;
template.error_function = vhost_user_socket_error;
template.file_descriptor = client_fd;