Skip to content

Commit

Permalink
virtio/vsock: fix leaks due to missing skb owner
Browse files Browse the repository at this point in the history
commit f9d2b1e upstream.

This patch sets the skb owner in the recv and send path for virtio.

For the send path, this solves the leak caused when
virtio_transport_purge_skbs() finds skb->sk is always NULL and therefore
never matches it with the current socket. Setting the owner upon
allocation fixes this.

For the recv path, this ensures correctness of accounting and also
correct transfer of ownership in vsock_loopback (when skbs are sent from
one socket and received by another).

Fixes: 71dc9ec ("virtio/vsock: replace virtio_vsock_pkt with sk_buff")
Signed-off-by: Bobby Eshleman <[email protected]>
Reported-by: Cong Wang <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/
Reviewed-by: Stefano Garzarella <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Bobby Eshleman authored and gregkh committed Nov 20, 2023
1 parent bb1c9a5 commit a6650e7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions net/vmw_vsock/virtio_transport_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info,
info->op,
info->flags);

if (info->vsk && !skb_set_owner_sk_safe(skb, sk_vsock(info->vsk))) {
WARN_ONCE(1, "failed to allocate skb on vsock socket with sk_refcnt == 0\n");
goto out;
}

return skb;

out:
Expand Down Expand Up @@ -1302,6 +1307,11 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
goto free_pkt;
}

if (!skb_set_owner_sk_safe(skb, sk)) {
WARN_ONCE(1, "receiving vsock socket has sk_refcnt == 0\n");
goto free_pkt;
}

vsk = vsock_sk(sk);

lock_sock(sk);
Expand Down

0 comments on commit a6650e7

Please sign in to comment.