提交 50dc13e2 编写于 作者: S Stefan Hajnoczi 提交者: Greg Kroah-Hartman

vhost/vsock: fix reset orphans race with close timeout

[ Upstream commit c38f57da428b033f2721b611d84b1f40bde674a8 ]

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: NMaximilian Riemensberger <riemensberger@cadami.net>
Cc: Graham Whaley <graham.whaley@gmail.com>
Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
上级 b5a8028c
...@@ -563,13 +563,21 @@ static void vhost_vsock_reset_orphans(struct sock *sk) ...@@ -563,13 +563,21 @@ static void vhost_vsock_reset_orphans(struct sock *sk)
* executing. * executing.
*/ */
if (!vhost_vsock_get(vsk->remote_addr.svm_cid)) { /* If the peer is still valid, no need to reset connection */
sock_set_flag(sk, SOCK_DONE); if (vhost_vsock_get(vsk->remote_addr.svm_cid))
vsk->peer_shutdown = SHUTDOWN_MASK; return;
sk->sk_state = SS_UNCONNECTED;
sk->sk_err = ECONNRESET; /* If the close timeout is pending, let it expire. This avoids races
sk->sk_error_report(sk); * with the timeout callback.
} */
if (vsk->close_work_scheduled)
return;
sock_set_flag(sk, SOCK_DONE);
vsk->peer_shutdown = SHUTDOWN_MASK;
sk->sk_state = SS_UNCONNECTED;
sk->sk_err = ECONNRESET;
sk->sk_error_report(sk);
} }
static int vhost_vsock_dev_release(struct inode *inode, struct file *file) static int vhost_vsock_dev_release(struct inode *inode, struct file *file)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册