iavf: fix potential races for FDIR filters
Subsystems (2)
PATCH 1/1 iavf: fix potential races for FDIR filters
Add fdir_fltr_lock locking in unprotected places.
The change in iavf_fdir_is_dup_fltr adds a spinlock around a loop which iterates over all filters and looks for a duplicate. The filter can be removed from list and freed from memory at the same time it's being compared. All other places where filters are deleted are already protected with spinlock.
The remaining changes protect adapter->fdir_active_fltr variable so now all its uses are under a spinlock.
--- drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 5 ++++- drivers/net/ethernet/intel/iavf/iavf_fdir.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +4 -1
@@ -1401,14 +1401,15 @@ static int iavf_add_fdir_ethtool(struct iavf_adapter *adapter, struct ethtool_rxif (fsp->flow_type &FLOW_MAC_EXT )return -EINVAL ; +spin_lock_bh (&adapter->fdir_fltr_lock);if (adapter->fdir_active_fltr >=IAVF_MAX_FDIR_FILTERS ) { +spin_unlock_bh (&adapter->fdir_fltr_lock);dev_err (&adapter->pdev->dev,"Unable to add Flow Director filter because VF reached the limit of max allowed filters (%u)\n" ,IAVF_MAX_FDIR_FILTERS );return -ENOSPC ; } -spin_lock_bh (&adapter->fdir_fltr_lock);if (iavf_find_fdir_fltr_by_loc (adapter, fsp->location)) {dev_err (&adapter->pdev->dev,"Failed to add Flow Director filter, it already exists\n" );spin_unlock_bh (&adapter->fdir_fltr_lock);
@@ -1781,7 +1782,9 @@ static int iavf_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,case ETHTOOL_GRXCLSRLCNT :if (!FDIR_FLTR_SUPPORT (adapter))break ; +spin_lock_bh (&adapter->fdir_fltr_lock); cmd->rule_cnt = adapter->fdir_active_fltr; +spin_unlock_bh (&adapter->fdir_fltr_lock); cmd->data =IAVF_MAX_FDIR_FILTERS ; ret =0 ;break ;
drivers/net/ethernet/intel/iavf/iavf_fdir.c +8 -3
@@ -722,7 +722,9 @@ void iavf_print_fdir_fltr(struct iavf_adapter *adapter, struct iavf_fdir_fltr *fbool iavf_fdir_is_dup_fltr (struct iavf_adapter *adapter,struct iavf_fdir_fltr *fltr) {struct iavf_fdir_fltr *tmp; +bool ret = false; +spin_lock_bh (&adapter->fdir_fltr_lock);list_for_each_entry (tmp, &adapter->fdir_list_head, list) {if (tmp->flow_type != fltr->flow_type)continue ;
@@ -732,11 +734,14 @@ bool iavf_fdir_is_dup_fltr(struct iavf_adapter *adapter, struct iavf_fdir_fltr * !memcmp(&tmp->ip_data, &fltr->ip_data, sizeof(fltr->ip_data)) && !memcmp(&tmp->ext_data, &fltr->ext_data, - sizeof(fltr->ext_data))) - return true; + sizeof(fltr->ext_data))) { + ret = true; +break ; + } } +spin_unlock_bh (&adapter->fdir_fltr_lock); -return false; +return ret; }/**
Signature · 6 lines
2.34.1 _______________________________________________ Intel-wired-lan mailing list [email protected] https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
drivers/net/ethernet/intel/iavf/iavf_ethtool.c
Quoted 30 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Piotr Gardocki
Sent: środa, 26 lipca 2023 16:16
To: [email protected]
Subject: [Intel-wired-lan] [PATCH iwl-net] iavf: fix potential races for FDIR filtersAdd
fdir_fltr_locklocking in unprotected places.The change in
iavf_fdir_is_dup_fltradds a spinlock around a loop which iterates over all filters and looks for a duplicate. The filter can be removed from list and freed from memory at the same time it's being compared. All other places where filters are deleted are already protected with spinlock.The remaining changes protect
adapter->fdir_active_fltrvariable so now all its uses are under a spinlock.Fixes 527691bf0682 ("iavf: Support IPv4 Flow Director filters")Signed-off-by Piotr Gardocki <[email protected]>--- drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 5 ++++- drivers/net/ethernet/intel/iavf/iavf_fdir.c | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-)drivers/net/ethernet/intel/iavf/iavf_ethtool.c +0
-0
_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan