mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
virtio/vsock: fix leaks due to missing skb owner
commitf9d2b1e146upstream. 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:71dc9ec9ac("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
bb1c9a5907
commit
a6650e78c4
@@ -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:
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user