linux-stable/net/vmw_vsock
Dexuan Cui 91a71a61da hv_sock: Fix hang when a connection is closed
[ Upstream commit 685703b497 ]

There is a race condition for an established connection that is being closed
by the guest: the refcnt is 4 at the end of hvs_release() (Note: here the
'remove_sock' is false):

1 for the initial value;
1 for the sk being in the bound list;
1 for the sk being in the connected list;
1 for the delayed close_work.

After hvs_release() finishes, __vsock_release() -> sock_put(sk) *may*
decrease the refcnt to 3.

Concurrently, hvs_close_connection() runs in another thread:
  calls vsock_remove_sock() to decrease the refcnt by 2;
  call sock_put() to decrease the refcnt to 0, and free the sk;
  next, the "release_sock(sk)" may hang due to use-after-free.

In the above, after hvs_release() finishes, if hvs_close_connection() runs
faster than "__vsock_release() -> sock_put(sk)", then there is not any issue,
because at the beginning of hvs_close_connection(), the refcnt is still 4.

The issue can be resolved if an extra reference is taken when the
connection is established.

Fixes: a9eeb998c2 ("hv_sock: Add support for delayed close")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
Reviewed-by: Sunil Muthuswamy <sunilmut@microsoft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-09-16 08:21:41 +02:00
..
Kconfig VSOCK: add sock_diag interface 2017-10-05 18:44:17 -07:00
Makefile Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2017-11-04 09:26:51 +09:00
af_vsock.c vsock: correct removal of socket from the list 2019-08-04 09:30:51 +02:00
af_vsock_tap.c VSOCK: Add vsockmon tap functions 2017-04-24 12:35:56 -04:00
diag.c VSOCK: add sock_diag interface 2017-10-05 18:44:17 -07:00
hyperv_transport.c hv_sock: Fix hang when a connection is closed 2019-09-16 08:21:41 +02:00
virtio_transport.c vsock/virtio: Initialize core virtio vsock before registering the driver 2019-05-25 18:23:22 +02:00
virtio_transport_common.c vsock/virtio: set SOCK_DONE on peer shutdown 2019-06-22 08:15:14 +02:00
vmci_transport.c vsock: cope with memory allocation failure at socket creation time 2019-02-23 09:07:25 +01:00
vmci_transport.h
vmci_transport_notify.c VSOCK: use TCP state constants for sk_state 2017-10-05 18:44:17 -07:00
vmci_transport_notify.h
vmci_transport_notify_qstate.c VSOCK: use TCP state constants for sk_state 2017-10-05 18:44:17 -07:00
vsock_addr.c