igc: Fix locking issue when retrieving NFC rules

Access to NFC rules stored in adapter->nfc_rule_list is protect by
adapter->nfc_rule_lock. The functions igc_ethtool_get_nfc_rule()
and igc_ethtool_get_nfc_rules() are missing to hold the lock while
accessing rule objects.

Signed-off-by: Andre Guedes <andre.guedes@intel.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
This commit is contained in:
Andre Guedes 2020-04-24 13:16:14 -07:00 committed by Jeff Kirsher
parent d3ba9e6f61
commit b500350a36

View file

@ -939,16 +939,18 @@ static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter,
cmd->data = IGC_MAX_RXNFC_RULES;
spin_lock(&adapter->nfc_rule_lock);
hlist_for_each_entry(rule, &adapter->nfc_rule_list, nfc_node) {
if (fsp->location <= rule->location)
break;
}
if (!rule || fsp->location != rule->location)
return -EINVAL;
goto out;
if (!rule->filter.match_flags)
return -EINVAL;
goto out;
fsp->flow_type = ETHER_FLOW;
fsp->ring_cookie = rule->action;
@ -976,7 +978,12 @@ static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter,
eth_broadcast_addr(fsp->m_u.ether_spec.h_source);
}
spin_unlock(&adapter->nfc_rule_lock);
return 0;
out:
spin_unlock(&adapter->nfc_rule_lock);
return -EINVAL;
}
static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter,
@ -988,13 +995,19 @@ static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter,
cmd->data = IGC_MAX_RXNFC_RULES;
spin_lock(&adapter->nfc_rule_lock);
hlist_for_each_entry(rule, &adapter->nfc_rule_list, nfc_node) {
if (cnt == cmd->rule_cnt)
if (cnt == cmd->rule_cnt) {
spin_unlock(&adapter->nfc_rule_lock);
return -EMSGSIZE;
}
rule_locs[cnt] = rule->location;
cnt++;
}
spin_unlock(&adapter->nfc_rule_lock);
cmd->rule_cnt = cnt;
return 0;