linux-stable/drivers/net/ethernet
Vladimir Oltean 84ce1ca3fe net: enetc: survive memory pressure without crashing
Under memory pressure, enetc_refill_rx_ring() may fail, and when called
during the enetc_open() -> enetc_setup_rxbdr() procedure, this is not
checked for.

An extreme case of memory pressure will result in exactly zero buffers
being allocated for the RX ring, and in such a case it is expected that
hardware drops all RX packets due to lack of buffers.

This does not happen, because the reset-default value of the consumer
and produces index is 0, and this makes the ENETC think that all buffers
have been initialized and that it owns them (when in reality none were).

The hardware guide explains this best:

| Configure the receive ring producer index register RBaPIR with a value
| of 0. The producer index is initially configured by software but owned
| by hardware after the ring has been enabled. Hardware increments the
| index when a frame is received which may consume one or more BDs.
| Hardware is not allowed to increment the producer index to match the
| consumer index since it is used to indicate an empty condition. The ring
| can hold at most RBLENR[LENGTH]-1 received BDs.
|
| Configure the receive ring consumer index register RBaCIR. The
| consumer index is owned by software and updated during operation of the
| of the BD ring by software, to indicate that any receive data occupied
| in the BD has been processed and it has been prepared for new data.
| - If consumer index and producer index are initialized to the same
|   value, it indicates that all BDs in the ring have been prepared and
|   hardware owns all of the entries.
| - If consumer index is initialized to producer index plus N, it would
|   indicate N BDs have been prepared. Note that hardware cannot start if
|   only a single buffer is prepared due to the restrictions described in
|   (2).
| - Software may write consumer index to match producer index anytime
|   while the ring is operational to indicate all received BDs prior have
|   been processed and new BDs prepared for hardware.

Normally, the value of rx_ring->rcir (consumer index) is brought in sync
with the rx_ring->next_to_use software index, but this only happens if
page allocation ever succeeded.

When PI==CI==0, the hardware appears to receive frames and write them to
DMA address 0x0 (?!), then set the READY bit in the BD.

The enetc_clean_rx_ring() function (and its XDP derivative) is naturally
not prepared to handle such a condition. It will attempt to process
those frames using the rx_swbd structure associated with index i of the
RX ring, but that structure is not fully initialized (enetc_new_page()
does all of that). So what happens next is undefined behavior.

To operate using no buffer, we must initialize the CI to PI + 1, which
will block the hardware from advancing the CI any further, and drop
everything.

The issue was seen while adding support for zero-copy AF_XDP sockets,
where buffer memory comes from user space, which can even decide to
supply no buffers at all (example: "xdpsock --txonly"). However, the bug
is present also with the network stack code, even though it would take a
very determined person to trigger a page allocation failure at the
perfect time (a series of ifup/ifdown under memory pressure should
eventually reproduce it given enough retries).

Fixes: d4fd0404c1 ("enetc: Introduce basic PF and VF ENETC ethernet drivers")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Claudiu Manoil <claudiu.manoil@nxp.com>
Link: https://lore.kernel.org/r/20221027182925.3256653-1-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-10-27 11:32:25 -07:00
..
3com net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
8390 ethernet: 8390: remove unnecessary check of mem 2022-09-29 11:05:23 +02:00
actions net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
adaptec net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
adi net: ethernet: adi: adin1110: Add check in netdev_event 2022-10-05 20:32:52 -07:00
aeroflex net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
agere net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
alacritech net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
allwinner net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
alteon net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
altera net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
amazon net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
amd amd-xgbe: add the bit rate quirk for Molex cables 2022-10-21 22:40:22 -07:00
apm net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
apple
aquantia atlantic: fix deadlock at aq_nic_stop 2022-10-24 10:27:09 +01:00
arc net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
asix net: ax88796c: Use skb_put_data() instead of skb_put/memcpy pair 2022-09-29 09:37:29 +02:00
atheros Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2022-10-03 17:44:18 -07:00
broadcom net: broadcom: bcm4908_enet: update TX stats after actual transmission 2022-10-27 10:27:53 -07:00
brocade net: bna: Fix spelling mistake "muliple" -> "multiple" 2022-09-30 13:01:16 +01:00
cadence net: macb: Specify PHY PM management done by MAC 2022-10-20 21:12:00 -07:00
calxeda net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
cavium eth: octeon: fix build after netif_napi_add() changes 2022-10-03 17:03:25 -07:00
chelsio treewide: use get_random_u32() when possible 2022-10-11 17:42:58 -06:00
cirrus net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
cisco net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
cortina net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
davicom net: davicom: Fix return type of dm9000_start_xmit 2022-09-19 18:23:14 -07:00
dec net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
dlink net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
emulex net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
engleder tsnep: Use page pool for RX 2022-09-30 11:32:27 +01:00
ezchip
faraday net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
freescale net: enetc: survive memory pressure without crashing 2022-10-27 11:32:25 -07:00
fujitsu net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
fungible net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
google net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
hisilicon net: hns: fix possible memory leak in hnae_ae_register() 2022-10-19 17:28:52 -07:00
huawei net: hinic: fix the issue of double release MBOX callback of VF 2022-10-20 21:09:48 -07:00
i825xx
ibm net: ehea: fix possible memory leak in ehea_register_port() 2022-10-27 12:51:41 +02:00
intel i40e: Fix flow-type by setting GL_HASH_INSET registers 2022-10-25 16:18:32 -07:00
litex net: ethernet: litex: Fix return type of liteeth_start_xmit 2022-09-19 18:23:39 -07:00
marvell ethernet: marvell: octeontx2 Fix resource not freed after malloc 2022-10-19 13:43:41 +01:00
mediatek net: ethernet: mediatek: ppe: Remove the unused function mtk_foe_entry_usable() 2022-10-17 09:36:39 +01:00
mellanox net/mlx5e: Fix macsec sci endianness at rx sa update 2022-10-27 11:06:57 -07:00
micrel net: ksz884x: fix missing pci_disable_device() on error in pcidev_init() 2022-10-25 19:46:35 -07:00
microchip net: lan966x: Stop replacing tx dcbs and dcbs_buf when changing MTU 2022-10-24 21:04:51 -07:00
microsoft Including fixes from wifi, netfilter and can. 2022-09-22 10:58:13 -07:00
moxa net: moxa: fix endianness-related issues from 'sparse' 2022-09-06 10:24:42 +02:00
mscc Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2022-09-29 14:30:51 -07:00
myricom net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
natsemi net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
neterion ethernet: s2io: Use skb_put_data() instead of skb_put/memcpy pair 2022-09-29 09:19:09 +02:00
netronome nfp: only clean sp_indiff when application firmware is unloaded 2022-10-21 22:43:48 -07:00
ni net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
nvidia net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
nxp net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
oki-semi net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
packetengines net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
pasemi net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
pensando ionic: catch NULL pointer issue on reconfig 2022-10-18 19:19:31 -07:00
qlogic net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
qualcomm net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
rdc net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
realtek r8169: add rtl_disable_rxdvgate() 2022-09-30 18:17:06 -07:00
renesas net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
rocker treewide: use get_random_bytes() when possible 2022-10-11 17:42:58 -06:00
samsung net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
seeq
sfc sfc: include vport_id in filter spec hash and equal() 2022-10-19 17:08:43 -07:00
sgi net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
silan
sis net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
smsc net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
socionext net: ethernet: ave: Fix MAC to be in charge of PHY PM 2022-10-26 20:21:34 -07:00
stmicro net: stmmac: rk3588: Allow multiple gmac controller 2022-10-25 11:02:37 +02:00
sun sunhme: Uninitialized variable in happy_meal_init() 2022-10-15 11:14:24 +01:00
sunplus Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2022-10-03 17:44:18 -07:00
synopsys net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
tehuti net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
ti net: ethernet: ti: am65-cpsw: set correct devlink flavour for unused ports 2022-10-12 09:05:04 +01:00
toshiba net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
tundra net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
vertexcom net: vertexcom: mse102x: Silence no spi_device_id warnings 2022-09-26 12:46:16 -07:00
via net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
wangxun net: ngbe: Add build support for ngbe 2022-08-30 12:32:51 +02:00
wiznet net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
xilinx net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
xircom net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
xscale net: xscale: Fix return type for implementation of ndo_start_xmit 2022-09-02 21:18:56 -07:00
dnet.c net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
dnet.h
ec_bhf.c
ethoc.c net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
fealnx.c net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
jme.c net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
jme.h
Kconfig net: ethernet: adi: Add ADIN1110 support 2022-09-20 15:00:30 +02:00
korina.c net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
lantiq_etop.c net: lantiq_etop: don't free skb when returning NETDEV_TX_BUSY 2022-10-24 13:02:18 +01:00
lantiq_xrx200.c net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
Makefile net: ethernet: adi: Add ADIN1110 support 2022-09-20 15:00:30 +02:00