Skip to content

Commit e2647b0

Browse files
mmhalTreehugger Robot
authored andcommitted
UPSTREAM: bpf, vsock: Invoke proto::close on close()
commit 135ffc7 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. Bug: 396331793 Fixes: 634f1a7 ("vsock: support sockmap") Signed-off-by: Michal Luczaj <mhal@rbox.co> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Reviewed-by: Luigi Leonardi <leonardi@redhat.com> Link: https://lore.kernel.org/r/20241118-vsock-bpf-poll-close-v1-3-f1b9669cacdc@rbox.co Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: John Fastabend <john.fastabend@gmail.com> [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 <leonardi@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 13a4362) Signed-off-by: Lee Jones <joneslee@google.com> Change-Id: I8aefa411aa1ef317743deb600aaa4a9cdd52abd3
1 parent cfa792a commit e2647b0

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
@@ -118,12 +118,14 @@
118118
static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr);
119119
static void vsock_sk_destruct(struct sock *sk);
120120
static int vsock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
121+
static void vsock_close(struct sock *sk, long timeout);
121122

122123
/* Protocol family. */
123124
static struct proto vsock_proto = {
124125
.name = "AF_VSOCK",
125126
.owner = THIS_MODULE,
126127
.obj_size = sizeof(struct vsock_sock),
128+
.close = vsock_close,
127129
};
128130

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

806808
static void __vsock_release(struct sock *sk, int level)
807809
{
808-
if (sk) {
809-
struct sock *pending;
810-
struct vsock_sock *vsk;
811-
812-
vsk = vsock_sk(sk);
813-
pending = NULL; /* Compiler warning. */
810+
struct vsock_sock *vsk;
811+
struct sock *pending;
814812

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

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

827-
sock_orphan(sk);
828-
sk->sk_shutdown = SHUTDOWN_MASK;
823+
if (vsk->transport)
824+
vsk->transport->release(vsk);
825+
else if (sock_type_connectible(sk->sk_type))
826+
vsock_remove_sock(vsk);
829827

830-
skb_queue_purge(&sk->sk_receive_queue);
828+
sock_orphan(sk);
829+
sk->sk_shutdown = SHUTDOWN_MASK;
831830

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

838-
release_sock(sk);
839-
sock_put(sk);
833+
/* Clean up any sockets that never were accepted. */
834+
while ((pending = vsock_dequeue_accept(sk)) != NULL) {
835+
__vsock_release(pending, SINGLE_DEPTH_NESTING);
836+
sock_put(pending);
840837
}
838+
839+
release_sock(sk);
840+
sock_put(sk);
841841
}
842842

843843
static void vsock_sk_destruct(struct sock *sk)
@@ -914,9 +914,22 @@ void vsock_data_ready(struct sock *sk)
914914
}
915915
EXPORT_SYMBOL_GPL(vsock_data_ready);
916916

917+
/* Dummy callback required by sockmap.
918+
* See unconditional call of saved_close() in sock_map_close().
919+
*/
920+
static void vsock_close(struct sock *sk, long timeout)
921+
{
922+
}
923+
917924
static int vsock_release(struct socket *sock)
918925
{
919-
__vsock_release(sock->sk, 0);
926+
struct sock *sk = sock->sk;
927+
928+
if (!sk)
929+
return 0;
930+
931+
sk->sk_prot->close(sk, 0);
932+
__vsock_release(sk, 0);
920933
sock->sk = NULL;
921934
sock->state = SS_FREE;
922935

0 commit comments

Comments
 (0)