• Jesper Dangaard Brouer's avatar
    virtio_net: fix memory leak in XDP_REDIRECT · 11b7d897
    Jesper Dangaard Brouer authored
    XDP_REDIRECT calling xdp_do_redirect() can fail for multiple reasons
    (which can be inspected by tracepoints). The current semantics is that
    on failure the driver calling xdp_do_redirect() must handle freeing or
    recycling the page associated with this frame.  This can be seen as an
    optimization, as drivers usually have an optimized XDP_DROP code path
    for frame recycling in place already.
    
    The virtio_net driver didn't handle when xdp_do_redirect() failed.
    This caused a memory leak as the page refcnt wasn't decremented on
    failures.
    
    The function __virtnet_xdp_xmit() did handle one type of failure,
    when the xmit queue virtqueue_add_outbuf() is full, which "hides"
    releasing a refcnt on the page.  Instead the function __virtnet_xdp_xmit()
    must follow API of xdp_do_redirect(), which on errors leave it up to
    the caller to free the page, of the failed send operation.
    
    Fixes: 186b3c99 ("virtio-net: support XDP_REDIRECT")
    Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
    Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    11b7d897
virtio_net.c 76.1 KB