Skip to content

Commit 8da80c9

Browse files
sylwesterdziedziuchkuba-moo
authored andcommitted
iavf: Fix ping is lost after untrusted VF had tried to change MAC
Make changes to MAC address dependent on the response of PF. Disallow changes to HW MAC address and MAC filter from untrusted VF, thanks to that ping is not lost if VF tries to change MAC. Add a new field in iavf_mac_filter, to indicate whether there was response from PF for given filter. Based on this field pass or discard the filter. If untrusted VF tried to change it's address, it's not changed. Still filter was changed, because of that ping couldn't go through. Fixes: c5c922b ("iavf: fix MAC address setting for VFs when filter is rejected") Signed-off-by: Przemyslaw Patynowski <[email protected]> Signed-off-by: Sylwester Dziedziuch <[email protected]> Signed-off-by: Mateusz Palczewski <[email protected]> Tested-by: Gurucharan G <[email protected]> Signed-off-by: Tony Nguyen <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a222be5 commit 8da80c9

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

drivers/net/ethernet/intel/iavf/iavf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct iavf_q_vector {
136136
struct iavf_mac_filter {
137137
struct list_head list;
138138
u8 macaddr[ETH_ALEN];
139+
bool is_new_mac; /* filter is new, wait for PF decision */
139140
bool remove; /* filter needs to be removed */
140141
bool add; /* filter needs to be added */
141142
};

drivers/net/ethernet/intel/iavf/iavf_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ struct iavf_mac_filter *iavf_add_filter(struct iavf_adapter *adapter,
751751

752752
list_add_tail(&f->list, &adapter->mac_filter_list);
753753
f->add = true;
754+
f->is_new_mac = true;
754755
adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER;
755756
} else {
756757
f->remove = false;

drivers/net/ethernet/intel/iavf/iavf_virtchnl.c

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,47 @@ void iavf_del_ether_addrs(struct iavf_adapter *adapter)
540540
kfree(veal);
541541
}
542542

543+
/**
544+
* iavf_mac_add_ok
545+
* @adapter: adapter structure
546+
*
547+
* Submit list of filters based on PF response.
548+
**/
549+
static void iavf_mac_add_ok(struct iavf_adapter *adapter)
550+
{
551+
struct iavf_mac_filter *f, *ftmp;
552+
553+
spin_lock_bh(&adapter->mac_vlan_list_lock);
554+
list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
555+
f->is_new_mac = false;
556+
}
557+
spin_unlock_bh(&adapter->mac_vlan_list_lock);
558+
}
559+
560+
/**
561+
* iavf_mac_add_reject
562+
* @adapter: adapter structure
563+
*
564+
* Remove filters from list based on PF response.
565+
**/
566+
static void iavf_mac_add_reject(struct iavf_adapter *adapter)
567+
{
568+
struct net_device *netdev = adapter->netdev;
569+
struct iavf_mac_filter *f, *ftmp;
570+
571+
spin_lock_bh(&adapter->mac_vlan_list_lock);
572+
list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
573+
if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
574+
f->remove = false;
575+
576+
if (f->is_new_mac) {
577+
list_del(&f->list);
578+
kfree(f);
579+
}
580+
}
581+
spin_unlock_bh(&adapter->mac_vlan_list_lock);
582+
}
583+
543584
/**
544585
* iavf_add_vlans
545586
* @adapter: adapter structure
@@ -1492,6 +1533,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
14921533
case VIRTCHNL_OP_ADD_ETH_ADDR:
14931534
dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
14941535
iavf_stat_str(&adapter->hw, v_retval));
1536+
iavf_mac_add_reject(adapter);
14951537
/* restore administratively set MAC address */
14961538
ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
14971539
break;
@@ -1639,10 +1681,11 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
16391681
}
16401682
}
16411683
switch (v_opcode) {
1642-
case VIRTCHNL_OP_ADD_ETH_ADDR: {
1684+
case VIRTCHNL_OP_ADD_ETH_ADDR:
1685+
if (!v_retval)
1686+
iavf_mac_add_ok(adapter);
16431687
if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
16441688
ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
1645-
}
16461689
break;
16471690
case VIRTCHNL_OP_GET_STATS: {
16481691
struct iavf_eth_stats *stats =

0 commit comments

Comments
 (0)