kernel_samsung_a53x/drivers/net/ethernet
Peiyang Wang 4152c38410 net: hns3: fix kernel crash when uninstalling driver
[ Upstream commit df3dff8ab6d79edc942464999d06fbaedf8cdd18 ]

When the driver is uninstalled and the VF is disabled concurrently, a
kernel crash occurs. The reason is that the two actions call function
pci_disable_sriov(). The num_VFs is checked to determine whether to
release the corresponding resources. During the second calling, num_VFs
is not 0 and the resource release function is called. However, the
corresponding resource has been released during the first invoking.
Therefore, the problem occurs:

[15277.839633][T50670] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020
...
[15278.131557][T50670] Call trace:
[15278.134686][T50670]  klist_put+0x28/0x12c
[15278.138682][T50670]  klist_del+0x14/0x20
[15278.142592][T50670]  device_del+0xbc/0x3c0
[15278.146676][T50670]  pci_remove_bus_device+0x84/0x120
[15278.151714][T50670]  pci_stop_and_remove_bus_device+0x6c/0x80
[15278.157447][T50670]  pci_iov_remove_virtfn+0xb4/0x12c
[15278.162485][T50670]  sriov_disable+0x50/0x11c
[15278.166829][T50670]  pci_disable_sriov+0x24/0x30
[15278.171433][T50670]  hnae3_unregister_ae_algo_prepare+0x60/0x90 [hnae3]
[15278.178039][T50670]  hclge_exit+0x28/0xd0 [hclge]
[15278.182730][T50670]  __se_sys_delete_module.isra.0+0x164/0x230
[15278.188550][T50670]  __arm64_sys_delete_module+0x1c/0x30
[15278.193848][T50670]  invoke_syscall+0x50/0x11c
[15278.198278][T50670]  el0_svc_common.constprop.0+0x158/0x164
[15278.203837][T50670]  do_el0_svc+0x34/0xcc
[15278.207834][T50670]  el0_svc+0x20/0x30

For details, see the following figure.

     rmmod hclge              disable VFs
----------------------------------------------------
hclge_exit()            sriov_numvfs_store()
  ...                     device_lock()
  pci_disable_sriov()     hns3_pci_sriov_configure()
                            pci_disable_sriov()
                              sriov_disable()
    sriov_disable()             if !num_VFs :
      if !num_VFs :               return;
        return;                 sriov_del_vfs()
      sriov_del_vfs()             ...
        ...                       klist_put()
        klist_put()               ...
        ...                     num_VFs = 0;
      num_VFs = 0;        device_unlock();

In this patch, when driver is removing, we get the device_lock()
to protect num_VFs, just like sriov_numvfs_store().

Fixes: 0dd8a25f355b ("net: hns3: disable sriov before unload hclge layer")
Signed-off-by: Peiyang Wang <wangpeiyang1@huawei.com>
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20241101091507.3644584-1-shaojijie@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-30 02:33:22 +01:00
..
3com Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
8390 Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
adaptec Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
aeroflex net: ethernet: aeroflex: fix potential memory leak in greth_start_xmit_gbit() 2024-11-23 23:21:59 +01:00
agere Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
alacritech Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
allwinner Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
alteon Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
altera Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
amazon net: ena: Fix incorrect descriptor free behavior 2024-11-19 11:32:20 +01:00
amd net: amd: mvme147: Fix probe banner message 2024-11-23 23:22:04 +01:00
apm Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
apple Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
aquantia Revert "net: atlantic: Avoid warning about potential string truncation" 2024-11-24 00:23:08 +01:00
arc Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
atheros ethernet: atheros: fix a memleak in atl1e_setup_ring_resources 2024-11-18 12:11:59 +01:00
aurora Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
broadcom net: systemport: fix potential memory leak in bcm_sysport_xmit() 2024-11-23 23:21:59 +01:00
brocade bna: adjust 'name' buf size of bna_tcb and bna_ccb structures 2024-11-23 23:20:08 +01:00
cadence Revert "net: macb: Avoid 20s boot delay by skipping MDIO bus registration for fixed-link PHY" 2024-11-24 00:22:53 +01:00
calxeda Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cavium liquidio: Adjust a NULL pointer handling path in lio_vf_rep_copy_packet 2024-11-19 14:19:03 +01:00
chelsio cxgb4: add forgotten u64 ivlan cast before shift 2024-11-23 23:20:49 +01:00
cirrus Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
cisco enic: Validate length of nl attributes in enic_set_vf_port 2024-11-19 12:27:10 +01:00
cortina Revert "net: ethernet: cortina: Drop TSO support" 2024-11-24 00:23:00 +01:00
davicom Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
dec Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dlink Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
emulex be2net: fix potential memory leak in be_xmit() 2024-11-23 23:22:01 +01:00
ezchip Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
faraday Revert "net: ftgmac100: Enable TX interrupt to avoid TX timeout" 2024-11-24 00:23:34 +01:00
freescale net: enetc: set MAC address to the VF net_device 2024-11-30 02:33:22 +01:00
fujitsu Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
google gve: Use size_add() in call to struct_size() 2024-11-18 11:42:47 +01:00
hisilicon net: hns3: fix kernel crash when uninstalling driver 2024-11-30 02:33:22 +01:00
huawei Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
i825xx Revert "net/sun3_82586: Avoid reading past buffer in debug output" 2024-11-24 00:23:52 +01:00
ibm Revert "net: ibm: emac: mal: fix wrong goto" 2024-11-24 00:22:56 +01:00
intel Revert "ice: fix ICE_LAST_OFFSET formula" 2024-11-24 00:23:51 +01:00
marvell Revert "net: mvpp2: Increase size of queue_name buffer" 2024-11-24 00:23:08 +01:00
mediatek net: ethernet: mtk_eth_soc: remove duplicate if statements 2024-11-18 12:12:45 +01:00
mellanox Revert "net/mlx5e: Add a check for the return value from mlx5_port_set_eth_ptys" 2024-11-24 00:23:55 +01:00
micrel net: ks8851: Fix potential TX stall after interface reopen 2024-11-19 14:19:44 +01:00
microchip lan743x: fix for potential NULL pointer dereference with bare card 2024-11-18 22:25:36 +01:00
moxa Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
mscc Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
myricom Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
natsemi Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
neterion vxge: remove unnecessary cast in kfree() 2024-11-19 09:22:37 +01:00
netronome Revert "nfp: Use IRQF_NO_AUTOEN flag in request_irq()" 2024-11-24 00:23:07 +01:00
ni Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nvidia Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
nxp Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
oki-semi Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
packetengines Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pasemi Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
pensando ionic: fix potential irq name truncation 2024-11-23 23:20:58 +01:00
qlogic qed: Improve the stack space of filter_config() 2024-11-23 23:20:08 +01:00
qualcomm qca_spi: Make interrupt remembering atomic 2024-11-19 14:19:08 +01:00
rdc Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
realtek Revert "r8169: disable ALDPS per default for RTL8125" 2024-11-24 00:23:29 +01:00
renesas net: ravb: Always process TX descriptor ring 2024-11-19 09:22:50 +01:00
rocker Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
samsung Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
seeq Revert "net: seeq: Fix use after free vulnerability in ether3 Driver Due to Race Condition" 2024-11-24 00:23:18 +01:00
sfc sfc: fix a double-free bug in efx_probe_filters 2024-11-18 12:12:06 +01:00
sgi Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
silan Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
sis Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
smsc net: smc91x: Fix m68k kernel compilation for ColdFire CPU 2024-11-19 12:26:51 +01:00
socionext Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
stmicro Revert "net: stmmac: Correct byte order of perfect_match" 2024-11-24 00:23:55 +01:00
sun eth: sungem: remove .ndo_poll_controller to avoid deadlocks 2024-11-19 12:26:56 +01:00
synopsys Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
tehuti Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ti net: ethernet: ti: am65-cpts: Fix PTPv1 message type on TX packets 2024-11-19 11:32:38 +01:00
toshiba net: spider_net: Use size_add() in call to struct_size() 2024-11-18 11:42:47 +01:00
tundra Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
via Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
wiznet Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
xilinx Revert "net: axienet: Fix register defines comment description" 2024-11-24 00:23:54 +01:00
xircom Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xscale Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dnet.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
dnet.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ec_bhf.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ethoc.c Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
fealnx.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
jme.c Revert "net: ethernet: use ip_hdrlen() instead of bit shift" 2024-11-24 00:23:36 +01:00
jme.h Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
Kconfig Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
korina.c Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
lantiq_etop.c Revert "net: ethernet: lantiq_etop: fix memory disclosure" 2024-11-24 00:23:12 +01:00
lantiq_xrx200.c Backport mac80211 patches from linux-6.1.y 2024-06-15 16:29:20 -03:00
Makefile Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00