Skip to content

Commit 13a4362

Browse files
mmhalgregkh
authored andcommitted
bpf, vsock: Invoke proto::close on close()
commit 135ffc7becc82cfb84936ae133da7969220b43b2 upstream. vsock defines a BPF callback to be invoked when close() is called. However, this callback is never actually executed. As a result, a closed vsock socket is not automatically removed from the sockmap/sockhash. Introduce a dummy vsock_close() and make vsock_release() call proto::close. Note: changes in __vsock_release() look messy, but it's only due to indent level reduction and variables xmas tree reorder. Fixes: 634f1a7110b4 ("vsock: support sockmap") Signed-off-by: Michal Luczaj <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Reviewed-by: Luigi Leonardi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: John Fastabend <[email protected]> [LL: There is no sockmap support for this kernel version. This patch has been backported because it helps reduce conflicts on future backports] Signed-off-by: Luigi Leonardi <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent effac69 commit 13a4362

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

net/vmw_vsock/af_vsock.c

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@
116116
static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr);
117117
static void vsock_sk_destruct(struct sock *sk);
118118
static int vsock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
119+
static void vsock_close(struct sock *sk, long timeout);
119120

120121
/* Protocol family. */
121122
static struct proto vsock_proto = {
122123
.name = "AF_VSOCK",
123124
.owner = THIS_MODULE,
124125
.obj_size = sizeof(struct vsock_sock),
126+
.close = vsock_close,
125127
};
126128

127129
/* The default peer timeout indicates how long we will wait for a peer response
@@ -803,39 +805,37 @@ static bool sock_type_connectible(u16 type)
803805

804806
static void __vsock_release(struct sock *sk, int level)
805807
{
806-
if (sk) {
807-
struct sock *pending;
808-
struct vsock_sock *vsk;
809-
810-
vsk = vsock_sk(sk);
811-
pending = NULL; /* Compiler warning. */
808+
struct vsock_sock *vsk;
809+
struct sock *pending;
812810

813-
/* When "level" is SINGLE_DEPTH_NESTING, use the nested
814-
* version to avoid the warning "possible recursive locking
815-
* detected". When "level" is 0, lock_sock_nested(sk, level)
816-
* is the same as lock_sock(sk).
817-
*/
818-
lock_sock_nested(sk, level);
811+
vsk = vsock_sk(sk);
812+
pending = NULL; /* Compiler warning. */
819813

820-
if (vsk->transport)
821-
vsk->transport->release(vsk);
822-
else if (sock_type_connectible(sk->sk_type))
823-
vsock_remove_sock(vsk);
814+
/* When "level" is SINGLE_DEPTH_NESTING, use the nested
815+
* version to avoid the warning "possible recursive locking
816+
* detected". When "level" is 0, lock_sock_nested(sk, level)
817+
* is the same as lock_sock(sk).
818+
*/
819+
lock_sock_nested(sk, level);
824820

825-
sock_orphan(sk);
826-
sk->sk_shutdown = SHUTDOWN_MASK;
821+
if (vsk->transport)
822+
vsk->transport->release(vsk);
823+
else if (sock_type_connectible(sk->sk_type))
824+
vsock_remove_sock(vsk);
827825

828-
skb_queue_purge(&sk->sk_receive_queue);
826+
sock_orphan(sk);
827+
sk->sk_shutdown = SHUTDOWN_MASK;
829828

830-
/* Clean up any sockets that never were accepted. */
831-
while ((pending = vsock_dequeue_accept(sk)) != NULL) {
832-
__vsock_release(pending, SINGLE_DEPTH_NESTING);
833-
sock_put(pending);
834-
}
829+
skb_queue_purge(&sk->sk_receive_queue);
835830

836-
release_sock(sk);
837-
sock_put(sk);
831+
/* Clean up any sockets that never were accepted. */
832+
while ((pending = vsock_dequeue_accept(sk)) != NULL) {
833+
__vsock_release(pending, SINGLE_DEPTH_NESTING);
834+
sock_put(pending);
838835
}
836+
837+
release_sock(sk);
838+
sock_put(sk);
839839
}
840840

841841
static void vsock_sk_destruct(struct sock *sk)
@@ -912,9 +912,22 @@ void vsock_data_ready(struct sock *sk)
912912
}
913913
EXPORT_SYMBOL_GPL(vsock_data_ready);
914914

915+
/* Dummy callback required by sockmap.
916+
* See unconditional call of saved_close() in sock_map_close().
917+
*/
918+
static void vsock_close(struct sock *sk, long timeout)
919+
{
920+
}
921+
915922
static int vsock_release(struct socket *sock)
916923
{
917-
__vsock_release(sock->sk, 0);
924+
struct sock *sk = sock->sk;
925+
926+
if (!sk)
927+
return 0;
928+
929+
sk->sk_prot->close(sk, 0);
930+
__vsock_release(sk, 0);
918931
sock->sk = NULL;
919932
sock->state = SS_FREE;
920933

0 commit comments

Comments
 (0)