Skip to content

Commit 1bd3f41

Browse files
committed
bpf, vsock: Invoke proto::close on close()
jira NONE_AUTOMATION cve CVE-2025-21756 Rebuild_History Non-Buildable kernel-5.14.0-570.17.1.el9_6 commit-author Michal Luczaj <[email protected]> commit 135ffc7 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: 634f1a7 ("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]> (cherry picked from commit 135ffc7) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 66f5604 commit 1bd3f41

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
struct proto vsock_proto = {
122123
.name = "AF_VSOCK",
123124
.owner = THIS_MODULE,
124125
.obj_size = sizeof(struct vsock_sock),
126+
.close = vsock_close,
125127
#ifdef CONFIG_BPF_SYSCALL
126128
.psock_update_sk_prot = vsock_bpf_update_proto,
127129
#endif
@@ -797,39 +799,37 @@ static bool sock_type_connectible(u16 type)
797799

798800
static void __vsock_release(struct sock *sk, int level)
799801
{
800-
if (sk) {
801-
struct sock *pending;
802-
struct vsock_sock *vsk;
803-
804-
vsk = vsock_sk(sk);
805-
pending = NULL; /* Compiler warning. */
802+
struct vsock_sock *vsk;
803+
struct sock *pending;
806804

807-
/* When "level" is SINGLE_DEPTH_NESTING, use the nested
808-
* version to avoid the warning "possible recursive locking
809-
* detected". When "level" is 0, lock_sock_nested(sk, level)
810-
* is the same as lock_sock(sk).
811-
*/
812-
lock_sock_nested(sk, level);
805+
vsk = vsock_sk(sk);
806+
pending = NULL; /* Compiler warning. */
813807

814-
if (vsk->transport)
815-
vsk->transport->release(vsk);
816-
else if (sock_type_connectible(sk->sk_type))
817-
vsock_remove_sock(vsk);
808+
/* When "level" is SINGLE_DEPTH_NESTING, use the nested
809+
* version to avoid the warning "possible recursive locking
810+
* detected". When "level" is 0, lock_sock_nested(sk, level)
811+
* is the same as lock_sock(sk).
812+
*/
813+
lock_sock_nested(sk, level);
818814

819-
sock_orphan(sk);
820-
sk->sk_shutdown = SHUTDOWN_MASK;
815+
if (vsk->transport)
816+
vsk->transport->release(vsk);
817+
else if (sock_type_connectible(sk->sk_type))
818+
vsock_remove_sock(vsk);
821819

822-
skb_queue_purge(&sk->sk_receive_queue);
820+
sock_orphan(sk);
821+
sk->sk_shutdown = SHUTDOWN_MASK;
823822

824-
/* Clean up any sockets that never were accepted. */
825-
while ((pending = vsock_dequeue_accept(sk)) != NULL) {
826-
__vsock_release(pending, SINGLE_DEPTH_NESTING);
827-
sock_put(pending);
828-
}
823+
skb_queue_purge(&sk->sk_receive_queue);
829824

830-
release_sock(sk);
831-
sock_put(sk);
825+
/* Clean up any sockets that never were accepted. */
826+
while ((pending = vsock_dequeue_accept(sk)) != NULL) {
827+
__vsock_release(pending, SINGLE_DEPTH_NESTING);
828+
sock_put(pending);
832829
}
830+
831+
release_sock(sk);
832+
sock_put(sk);
833833
}
834834

835835
static void vsock_sk_destruct(struct sock *sk)
@@ -910,9 +910,22 @@ void vsock_data_ready(struct sock *sk)
910910
}
911911
EXPORT_SYMBOL_GPL(vsock_data_ready);
912912

913+
/* Dummy callback required by sockmap.
914+
* See unconditional call of saved_close() in sock_map_close().
915+
*/
916+
static void vsock_close(struct sock *sk, long timeout)
917+
{
918+
}
919+
913920
static int vsock_release(struct socket *sock)
914921
{
915-
__vsock_release(sock->sk, 0);
922+
struct sock *sk = sock->sk;
923+
924+
if (!sk)
925+
return 0;
926+
927+
sk->sk_prot->close(sk, 0);
928+
__vsock_release(sk, 0);
916929
sock->sk = NULL;
917930
sock->state = SS_FREE;
918931

0 commit comments

Comments
 (0)