]> git.baikalelectronics.ru Git - kernel.git/commit
igb: Add lock to avoid data race
authorLin Ma <linma@zju.edu.cn>
Wed, 17 Aug 2022 18:49:21 +0000 (11:49 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 18 Aug 2022 18:03:26 +0000 (11:03 -0700)
commite830a39d456b3942ebaf4d07737ebf78d01fb00e
tree048d066c0463dc59a31f7de67dbee1eb7142e6b4
parent0d40675b1e586ce0002f350295f1cbee40a9a304
igb: Add lock to avoid data race

The commit 0369858903c6 ("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 b96dc6eb861b ("dpaa2-eth: add
MAC/PHY support through phylink")). And then adds a spinlock to
eliminate races from driver requests. (similar to commit 89d2d79baab9
("ixgbe: Add locking to prevent panic when setting sriov_numvfs to zero")

Fixes: 0369858903c6 ("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>
drivers/net/ethernet/intel/igb/igb.h
drivers/net/ethernet/intel/igb/igb_main.c