1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/drivers/net/ethernet/intel
Lin Ma 6faee3d4ee igb: Add lock to avoid data race
The commit c23d92b80e ("igb: Teardown SR-IOV before
unregister_netdev()") places the unregister_netdev() call after the
igb_disable_sriov() call to avoid functionality issue.

However, it introduces several race conditions when detaching a device.
For example, when .remove() is called, the below interleaving leads to
use-after-free.

 (FREE from device detaching)      |   (USE from netdev core)
igb_remove                         |  igb_ndo_get_vf_config
 igb_disable_sriov                 |  vf >= adapter->vfs_allocated_count?
  kfree(adapter->vf_data)          |
  adapter->vfs_allocated_count = 0 |
                                   |    memcpy(... adapter->vf_data[vf]

Moreover, the igb_disable_sriov() also suffers from data race with the
requests from VF driver.

 (FREE from device detaching)      |   (USE from requests)
igb_remove                         |  igb_msix_other
 igb_disable_sriov                 |   igb_msg_task
  kfree(adapter->vf_data)          |    vf < adapter->vfs_allocated_count
  adapter->vfs_allocated_count = 0 |

To this end, this commit first eliminates the data races from netdev
core by using rtnl_lock (similar to commit 7194792308 ("dpaa2-eth: add
MAC/PHY support through phylink")). And then adds a spinlock to
eliminate races from driver requests. (similar to commit 1e53834ce5
("ixgbe: Add locking to prevent panic when setting sriov_numvfs to zero")

Fixes: c23d92b80e ("igb: Teardown SR-IOV before unregister_netdev()")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Link: https://lore.kernel.org/r/20220817184921.735244-1-anthony.l.nguyen@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-08-18 11:03:26 -07:00
..
e1000 net: add skb_[inner_]tcp_all_headers helpers 2022-07-02 16:22:25 +01:00
e1000e e1000e: convert .adjfreq to .adjfine 2022-07-28 10:57:06 -07:00
fm10k intel/fm10k:fix repeated words in comments 2022-06-30 10:56:01 -07:00
i40e i40e: Fix to stop tx_timeout recovery if GLOBR fails 2022-08-16 08:54:37 -07:00
iavf iavf: Fix deadlock in initialization 2022-08-12 08:23:01 -07:00
ice ice: Fix VF not able to send tagged traffic with no VLAN filters 2022-08-17 09:30:44 -07:00
igb igb: Add lock to avoid data race 2022-08-18 11:03:26 -07:00
igbvf intel/igbvf:fix repeated words in comments 2022-06-30 11:04:14 -07:00
igc Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2022-07-21 13:03:39 -07:00
ixgb net: add skb_[inner_]tcp_all_headers helpers 2022-07-02 16:22:25 +01:00
ixgbe ixgbe: convert .adjfreq to .adjfine 2022-07-28 11:02:02 -07:00
ixgbevf intel/ixgbevf:fix repeated words in comments 2022-06-30 11:08:45 -07:00
e100.c intel: remove unused macros 2022-06-30 09:40:55 -07:00
Kconfig ice: support crosstimestamping on E822 devices if supported 2021-12-21 09:11:40 -08:00
Makefile igc: Add skeletal frame for Intel(R) 2.5G Ethernet Controller support 2018-10-17 12:14:54 -07:00