• Vladimir Oltean's avatar
    net: enetc: fix buffer leaks with XDP_TX enqueue rejections · 92ff9a6e
    Vladimir Oltean authored
    If the TX ring is congested, enetc_xdp_tx() returns false for the
    current XDP frame (represented as an array of software BDs).
    
    This array of software TX BDs is constructed in enetc_rx_swbd_to_xdp_tx_swbd
    from software BDs freshly cleaned from the RX ring. The issue is that we
    scrub the RX software BDs too soon, more precisely before we know that
    we can enqueue the TX BDs successfully into the TX ring.
    
    If we can't enqueue them (and enetc_xdp_tx returns false), we call
    enetc_xdp_drop which attempts to recycle the buffers held by the RX
    software BDs. But because we scrubbed those RX BDs already, two things
    happen:
    
    (a) we leak their memory
    (b) we populate the RX software BD ring with an all-zero rx_swbd
        structure, which makes the buffer refill path allocate more memory.
    
    enetc_refill_rx_ring
    -> if (unlikely(!rx_swbd->page))
       -> enetc_new_page
    
    That is a recipe for fast OOM.
    
    Fixes: 7ed2bc80 ("net: enetc: add support for XDP_TX")
    Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    92ff9a6e
enetc.c 63.9 KB