linux/drivers/net/ethernet
Amit Cohen 13e6065fed mlxsw: spectrum_acl_erp: Fix error flow of pool allocation failure
[ Upstream commit 6d6eeabcfa ]

Lately, a bug was found when many TC filters are added - at some point,
several bugs are printed to dmesg [1] and the switch is crashed with
segmentation fault.

The issue starts when gen_pool_free() fails because of unexpected
behavior - a try to free memory which is already freed, this leads to BUG()
call which crashes the switch and makes many other bugs.

Trying to track down the unexpected behavior led to a bug in eRP code. The
function mlxsw_sp_acl_erp_table_alloc() gets a pointer to the allocated
index, sets the value and returns an error code. When gen_pool_alloc()
fails it returns address 0, we track it and return -ENOBUFS outside, BUT
the call for gen_pool_alloc() already override the index in erp_table
structure. This is a problem when such allocation is done as part of
table expansion. This is not a new table, which will not be used in case
of allocation failure. We try to expand eRP table and override the
current index (non-zero) with zero. Then, it leads to an unexpected
behavior when address 0 is freed twice. Note that address 0 is valid in
erp_table->base_index and indeed other tables use it.

gen_pool_alloc() fails in case that there is no space left in the
pre-allocated pool, in our case, the pool is limited to
ACL_MAX_ERPT_BANK_SIZE, which is read from hardware. When more than max
erp entries are required, we exceed the limit and return an error, this
error leads to "Failed to migrate vregion" print.

Fix this by changing erp_table->base_index only in case of a successful
allocation.

Add a test case for such a scenario. Without this fix it causes
segmentation fault:

$ TESTS="max_erp_entries_test" ./tc_flower.sh
./tc_flower.sh: line 988:  1560 Segmentation fault      tc filter del dev $h2 ingress chain $i protocol ip pref $i handle $j flower &>/dev/null

[1]:
kernel BUG at lib/genalloc.c:508!
invalid opcode: 0000 [#1] PREEMPT SMP
CPU: 6 PID: 3531 Comm: tc Not tainted 6.7.0-rc5-custom-ga6893f479f5e #1
Hardware name: Mellanox Technologies Ltd. MSN4700/VMOD0010, BIOS 5.11 07/12/2021
RIP: 0010:gen_pool_free_owner+0xc9/0xe0
...
Call Trace:
 <TASK>
 __mlxsw_sp_acl_erp_table_other_dec+0x70/0xa0 [mlxsw_spectrum]
 mlxsw_sp_acl_erp_mask_destroy+0xf5/0x110 [mlxsw_spectrum]
 objagg_obj_root_destroy+0x18/0x80 [objagg]
 objagg_obj_destroy+0x12c/0x130 [objagg]
 mlxsw_sp_acl_erp_mask_put+0x37/0x50 [mlxsw_spectrum]
 mlxsw_sp_acl_ctcam_region_entry_remove+0x74/0xa0 [mlxsw_spectrum]
 mlxsw_sp_acl_ctcam_entry_del+0x1e/0x40 [mlxsw_spectrum]
 mlxsw_sp_acl_tcam_ventry_del+0x78/0xd0 [mlxsw_spectrum]
 mlxsw_sp_flower_destroy+0x4d/0x70 [mlxsw_spectrum]
 mlxsw_sp_flow_block_cb+0x73/0xb0 [mlxsw_spectrum]
 tc_setup_cb_destroy+0xc1/0x180
 fl_hw_destroy_filter+0x94/0xc0 [cls_flower]
 __fl_delete+0x1ac/0x1c0 [cls_flower]
 fl_destroy+0xc2/0x150 [cls_flower]
 tcf_proto_destroy+0x1a/0xa0
...
mlxsw_spectrum3 0000:07:00.0: Failed to migrate vregion
mlxsw_spectrum3 0000:07:00.0: Failed to migrate vregion

Fixes: f465261aa1 ("mlxsw: spectrum_acl: Implement common eRP core")
Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Link: https://lore.kernel.org/r/4cfca254dfc0e5d283974801a24371c7b6db5989.1705502064.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2024-01-25 15:27:51 -08:00
..
3com 3c589_cs: Fix an error handling path in tc589_probe() 2023-05-30 14:03:33 +01: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: Fix uninitialized variable 2023-11-02 09:35:27 +01:00
aeroflex ethernet: aeroflex: fix potential skb leak in greth_init_rings() 2022-12-07 11:45:52 +01: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: altera_tse: release phylink resources in tse_shutdown() 2022-11-24 09:34:43 +01:00
amazon net: ena: Fix XDP redirection error 2023-12-20 17:00:18 +01:00
amd amd-xgbe: propagate the correct speed and duplex status 2023-12-03 07:32:08 +01:00
apm drivers: net: xgene: disable napi when register irq failed in xgene_enet_open() 2022-11-08 15:15:55 +01:00
apple net: apple: bmac: don't call dev_kfree_skb() under spin_lock_irqsave() 2022-12-31 13:32:27 +01:00
aquantia net: atlantic: fix double free in ring reinit logic 2023-12-20 17:00:19 +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 ethernet: atheros: fix a memleak in atl1e_setup_ring_resources 2024-01-01 12:38:56 +00:00
broadcom net/tg3: fix race condition in tg3_reset_task() 2024-01-20 11:50:05 +01:00
brocade net: bna: Fix spelling mistake "muliple" -> "multiple" 2022-09-30 13:01:16 +01:00
cadence net: macb: fix sleep inside spinlock 2023-09-19 12:28:10 +02:00
calxeda net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
cavium net: thunderx: Fix missing destroy_workqueue of nicvf_rx_mode_wq 2022-12-06 12:41:46 +01:00
chelsio chtls: fix tp->rcv_tstamp initialization 2023-11-20 11:51:54 +01: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: ethernet: cortina: Fix MTU max setting 2023-11-28 17:07:05 +00:00
davicom net: dm9051: Fix missing dev_kfree_skb() in dm9051_loop_rx() 2022-11-23 12:43:14 +00: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: vlan: introduce skb_vlan_eth_hdr() 2023-12-20 17:00:16 +01:00
engleder tsnep: Fix tsnep_request_irq() format-overflow warning 2023-11-28 17:06:56 +00:00
ezchip eth: switch to netif_napi_add_weight() 2022-05-08 11:33:57 +01:00
faraday net: drop the weight argument from netif_napi_add 2022-09-28 18:57:14 -07:00
freescale dpaa2-eth: recycle the RX buffer only after all processing done 2024-01-10 17:10:32 +01: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 gve: Use size_add() in call to struct_size() 2023-11-20 11:51:52 +01:00
hisilicon net: vlan: introduce skb_vlan_eth_hdr() 2023-12-20 17:00:16 +01:00
huawei net: hinic: Fix error handling in hinic_module_init() 2022-11-11 19:57:37 -08:00
i825xx i825xx: sni_82596: use eth_hw_addr_set() 2023-03-22 13:33:50 +01:00
ibm ibmveth: Remove condition to recompute TCP header checksum. 2023-10-10 22:00:43 +02:00
intel igc: Fix hicredit calculation 2024-01-10 17:10:25 +01:00
litex net: ethernet: litex: add support for 64 bit stats 2023-07-27 08:50:35 +02:00
marvell octeontx2-af: Support variable number of lmacs 2024-01-10 17:10:34 +01:00
mediatek net: ethernet: mtk_wed: fix EXT_INT_STATUS_RX_FBUF definitions for MT7986 SoC 2023-11-20 11:51:52 +01:00
mellanox mlxsw: spectrum_acl_erp: Fix error flow of pool allocation failure 2024-01-25 15:27:51 -08:00
micrel net: ks8851: Fix TX stall caused by TX buffer overrun 2024-01-01 12:39:04 +00:00
microchip net: lan743x: Don't sleep in atomic context 2023-07-23 13:49:18 +02:00
microsoft net: mana: select PAGE_POOL 2024-01-01 12:38:57 +00:00
moxa net: moxa: fix endianness-related issues from 'sparse' 2022-09-06 10:24:42 +02:00
mscc net: mscc: ocelot: fix eMAC TX RMON stats for bucket 256-511 and above 2024-01-01 12:38:56 +00:00
myricom myri10ge: Fix an error handling path in myri10ge_probe() 2022-12-31 13:32:56 +01:00
natsemi net/sonic: use dma_mapping_error() for error check 2023-03-30 12:49:09 +02:00
neterion ethernet: s2io: don't call dev_kfree_skb() under spin_lock_irqsave() 2022-12-31 13:32:26 +01:00
netronome nfp: flower: avoid rmmod nfp crash issues 2023-10-19 23:08:57 +02:00
ni net: ethernet: nixge: fix NULL dereference 2022-11-28 11:09:51 +00:00
nvidia forcedeth: Fix an error handling path in nv_probe() 2023-05-30 14:03:32 +01:00
nxp net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
oki-semi net: pch_gbe: fix pci device refcount leak while module exiting 2022-11-18 19:40:14 -08:00
packetengines net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
pasemi net: pasemi: Fix return type of pasemi_mac_start_tx() 2023-05-24 17:32:37 +01:00
pensando ionic: Fix dim work handling in split interrupt mode 2023-12-13 18:39:09 +01:00
qlogic net/qla3xxx: fix potential memleak in ql_alloc_buffer_queues 2024-01-10 17:10:25 +01:00
qualcomm net: qualcomm: rmnet: fix global oob in rmnet_policy 2024-01-25 15:27:49 -08:00
rdc r6040: Fix kmemleak in probe and remove 2022-12-31 13:32:54 +01:00
realtek r8169: Fix PCI error on system resume 2024-01-10 17:10:23 +01:00
renesas net: ravb: Fix dma_addr_t truncation in error case 2024-01-25 15:27:49 -08: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 ethernet: seeq/ether3: don't write directly to netdev->dev_addr 2022-01-26 15:40:01 +00:00
sfc sfc: fix a double-free bug in efx_probe_filters 2024-01-10 17:10:24 +01:00
sgi net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
silan ethernet: use eth_hw_addr_set() in unmaintained drivers 2021-10-18 13:20:38 +01:00
sis net: ethernet: move from strlcpy with unused retval to strscpy 2022-08-31 14:11:26 -07:00
smsc smsc911x: avoid PHY being resumed when interface is not up 2023-04-06 12:10:47 +02:00
socionext net: netsec: Ignore 'phy-mode' on SynQuacer in DT mode 2023-08-11 12:08:16 +02:00
stmicro net: stmmac: ethtool: Fixed calltrace caused by unbalanced disable_irq_wake calls 2024-01-25 15:27:50 -08:00
sun cassini: Fix a memory leak in the error handling path of cas_init_one() 2023-05-24 17:32:47 +01:00
sunplus eth: sp7021: drop free_netdev() from spl2sw_init_netdev() 2022-11-10 16:27:33 -08: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: Fix max mtu to fit ethernet frames 2024-01-25 15:27:49 -08:00
toshiba net: spider_net: Use size_add() in call to struct_size() 2023-11-20 11:51:52 +01:00
tundra ethernet: tundra: free irq when alloc ring failed in tsi108_open() 2022-11-10 15:39:08 +01: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: axienet: Fix check for partial TX checksum 2023-12-03 07:32:08 +01:00
xircom xirc2ps_cs: Fix use after free bug in xirc2ps_detach 2023-03-30 12:49:04 +02:00
xscale net: xscale: Fix return type for implementation of ndo_start_xmit 2022-09-02 21:18:56 -07:00
dnet.c net: ethernet: dnet: don't call dev_kfree_skb() under spin_lock_irqsave() 2022-12-31 13:32:27 +01:00
dnet.h net/dnet: Delete static version from the driver 2020-03-03 17:54:55 -08:00
ec_bhf.c ethernet: ec_bhf: use eth_hw_addr_set() 2021-10-16 08:53:46 +01:00
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 jme: remove an unnecessary indirection 2022-05-05 15:53:28 -07:00
Kconfig net: ethernet: adi: Add ADIN1110 support 2022-09-20 15:00:30 +02:00
korina.c net: korina: handle clk prepare error in korina_probe() 2023-08-11 12:08:16 +02: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