]> git.baikalelectronics.ru Git - kernel.git/commit
net: enetc: fix buffer leaks with XDP_TX enqueue rejections
authorVladimir Oltean <vladimir.oltean@nxp.com>
Fri, 16 Apr 2021 21:22:24 +0000 (00:22 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sat, 17 Apr 2021 00:08:40 +0000 (17:08 -0700)
commit3b05d77bc2047576c79fec1cb7be1e45047a3763
tree90949c0f016366b8b2f962d441d46f3e6dd78303
parent0b3578bef6600b258b7e1b3b3b09e67116104479
net: enetc: fix buffer leaks with XDP_TX enqueue rejections

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: 148e3d204903 ("net: enetc: add support for XDP_TX")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/freescale/enetc/enetc.c