diff options
author | Stefan Hajnoczi <stefanha@redhat.com> | 2018-12-06 14:14:34 -0500 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2018-12-06 14:22:34 -0500 |
commit | c38f57da428b033f2721b611d84b1f40bde674a8 (patch) | |
tree | c65567f936e34db07096b4003010c8ba64fe9022 | |
parent | 2595646791c319cadfdbf271563aac97d0843dc7 (diff) |
vhost/vsock: fix reset orphans race with close timeout
If a local process has closed a connected socket and hasn't received a
RST packet yet, then the socket remains in the table until a timeout
expires.
When a vhost_vsock instance is released with the timeout still pending,
the socket is never freed because vhost_vsock has already set the
SOCK_DONE flag.
Check if the close timer is pending and let it close the socket. This
prevents the race which can leak sockets.
Reported-by: Maximilian Riemensberger <riemensberger@cadami.net>
Cc: Graham Whaley <graham.whaley@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r-- | drivers/vhost/vsock.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 34bc3ab40c6d..731e2ea2aeca 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c | |||
@@ -563,13 +563,21 @@ static void vhost_vsock_reset_orphans(struct sock *sk) | |||
563 | * executing. | 563 | * executing. |
564 | */ | 564 | */ |
565 | 565 | ||
566 | if (!vhost_vsock_get(vsk->remote_addr.svm_cid)) { | 566 | /* If the peer is still valid, no need to reset connection */ |
567 | sock_set_flag(sk, SOCK_DONE); | 567 | if (vhost_vsock_get(vsk->remote_addr.svm_cid)) |
568 | vsk->peer_shutdown = SHUTDOWN_MASK; | 568 | return; |
569 | sk->sk_state = SS_UNCONNECTED; | 569 | |
570 | sk->sk_err = ECONNRESET; | 570 | /* If the close timeout is pending, let it expire. This avoids races |
571 | sk->sk_error_report(sk); | 571 | * with the timeout callback. |
572 | } | 572 | */ |
573 | if (vsk->close_work_scheduled) | ||
574 | return; | ||
575 | |||
576 | sock_set_flag(sk, SOCK_DONE); | ||
577 | vsk->peer_shutdown = SHUTDOWN_MASK; | ||
578 | sk->sk_state = SS_UNCONNECTED; | ||
579 | sk->sk_err = ECONNRESET; | ||
580 | sk->sk_error_report(sk); | ||
573 | } | 581 | } |
574 | 582 | ||
575 | static int vhost_vsock_dev_release(struct inode *inode, struct file *file) | 583 | static int vhost_vsock_dev_release(struct inode *inode, struct file *file) |