Skip to content

Commit f9d2b1e

Browse files
Bobby Eshlemandavem330
authored andcommitted
virtio/vsock: fix leaks due to missing skb owner
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 <bobby.eshleman@bytedance.com> Reported-by: Cong Wang <xiyou.wangcong@gmail.com> Link: https://lore.kernel.org/all/ZCCbATwov4U+GBUv@pop-os.localdomain/ Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6b36d68 commit f9d2b1e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

net/vmw_vsock/virtio_transport_common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info,
9494
info->op,
9595
info->flags);
9696

97+
if (info->vsk && !skb_set_owner_sk_safe(skb, sk_vsock(info->vsk))) {
98+
WARN_ONCE(1, "failed to allocate skb on vsock socket with sk_refcnt == 0\n");
99+
goto out;
100+
}
101+
97102
return skb;
98103

99104
out:
@@ -1303,6 +1308,11 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
13031308
goto free_pkt;
13041309
}
13051310

1311+
if (!skb_set_owner_sk_safe(skb, sk)) {
1312+
WARN_ONCE(1, "receiving vsock socket has sk_refcnt == 0\n");
1313+
goto free_pkt;
1314+
}
1315+
13061316
vsk = vsock_sk(sk);
13071317

13081318
lock_sock(sk);

0 commit comments

Comments
 (0)