All of lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-wired-lan] [PATCH net v2] iavf: Fix ping is lost after untrusted VF had tried to change MAC
@ 2021-06-28 12:11 Mateusz Palczewski
       [not found] ` <BN6PR11MB392398056E8C2C4942BEC4038C189@BN6PR11MB3923.namprd11.prod.outlook.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Mateusz Palczewski @ 2021-06-28 12:11 UTC (permalink / raw)
  To: intel-wired-lan

From: Sylwester Dziedziuch <sylwesterx.dziedziuch@intel.com>

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: c5c922b3e09b ("iavf: fix MAC address setting for VFs when filter is rejected")
Signed-off-by: Przemyslaw Patynowski <przemyslawx.patynowski@intel.com>
Signed-off-by: Sylwester Dziedziuch <sylwesterx.dziedziuch@intel.com>
Signed-off-by: Mateusz Palczewski <mateusz.palczewski@intel.com>
---
 v2: Fixed function names in comments
---
 drivers/net/ethernet/intel/iavf/iavf.h        |  1 +
 drivers/net/ethernet/intel/iavf/iavf_main.c   |  1 +
 .../net/ethernet/intel/iavf/iavf_virtchnl.c   | 47 ++++++++++++++++++-
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/iavf/iavf.h b/drivers/net/ethernet/intel/iavf/iavf.h
index 9ccb88e..b79d02f 100644
--- a/drivers/net/ethernet/intel/iavf/iavf.h
+++ b/drivers/net/ethernet/intel/iavf/iavf.h
@@ -137,6 +137,7 @@ struct iavf_q_vector {
 struct iavf_mac_filter {
 	struct list_head list;
 	u8 macaddr[ETH_ALEN];
+	bool is_new_mac;	/* filter is new, wait for PF decision */
 	bool remove;		/* filter needs to be removed */
 	bool add;		/* filter needs to be added */
 };
diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index d64e256..c9d9bf9 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -797,6 +797,7 @@ struct iavf_mac_filter *iavf_add_filter(struct iavf_adapter *adapter,
 
 		list_add_tail(&f->list, &adapter->mac_filter_list);
 		f->add = true;
+		f->is_new_mac = true;
 		adapter->aq_required |= IAVF_FLAG_AQ_ADD_MAC_FILTER;
 	} else {
 		f->remove = false;
diff --git a/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c b/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
index bc403b7..9c12846 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
@@ -540,6 +540,47 @@ void iavf_del_ether_addrs(struct iavf_adapter *adapter)
 	kfree(veal);
 }
 
+/**
+ * iavf_mac_add_ok
+ * @adapter: adapter structure
+ *
+ * Submit list of filters based on PF response.
+ **/
+static void iavf_mac_add_ok(struct iavf_adapter *adapter)
+{
+	struct iavf_mac_filter *f, *ftmp;
+
+	spin_lock_bh(&adapter->mac_vlan_list_lock);
+	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
+		f->is_new_mac = false;
+	}
+	spin_unlock_bh(&adapter->mac_vlan_list_lock);
+}
+
+/**
+ * iavf_mac_add_reject
+ * @adapter: adapter structure
+ *
+ * Remove filters from list based on PF response.
+ **/
+static void iavf_mac_add_reject(struct iavf_adapter *adapter)
+{
+	struct net_device *netdev = adapter->netdev;
+	struct iavf_mac_filter *f, *ftmp;
+
+	spin_lock_bh(&adapter->mac_vlan_list_lock);
+	list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
+		if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
+			f->remove = false;
+
+		if (f->is_new_mac) {
+			list_del(&f->list);
+			kfree(f);
+		}
+	}
+	spin_unlock_bh(&adapter->mac_vlan_list_lock);
+}
+
 /**
  * iavf_add_vlans
  * @adapter: adapter structure
@@ -1500,6 +1541,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
 		case VIRTCHNL_OP_ADD_ETH_ADDR:
 			dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
 				iavf_stat_str(&adapter->hw, v_retval));
+			iavf_mac_add_reject(adapter);
 			/* restore administratively set MAC address */
 			ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
 			break;
@@ -1647,10 +1689,11 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
 		}
 	}
 	switch (v_opcode) {
-	case VIRTCHNL_OP_ADD_ETH_ADDR: {
+	case VIRTCHNL_OP_ADD_ETH_ADDR:
+		if (!v_retval)
+			iavf_mac_add_ok(adapter);
 		if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
 			ether_addr_copy(netdev->dev_addr, adapter->hw.mac.addr);
-		}
 		break;
 	case VIRTCHNL_OP_GET_STATS: {
 		struct iavf_eth_stats *stats =
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Intel-wired-lan] [PATCH net v2] iavf: Fix ping is lost after untrusted VF had tried to change MAC
       [not found]           ` <BYAPR11MB3367EF5CEE54FC6415541454FCE49@BYAPR11MB3367.namprd11.prod.outlook.com>
@ 2021-07-22  9:55             ` G, GurucharanX
  0 siblings, 0 replies; 2+ messages in thread
From: G, GurucharanX @ 2021-07-22  9:55 UTC (permalink / raw)
  To: intel-wired-lan

> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf
> Of Mateusz Palczewski
> Sent: Monday, June 28, 2021 5:41 PM
> To: intel-wired-lan at lists.osuosl.org
> Cc: Dziedziuch, SylwesterX <sylwesterx.dziedziuch@intel.com>;
> Patynowski, PrzemyslawX <przemyslawx.patynowski@intel.com>;
> Palczewski, Mateusz <mateusz.palczewski@intel.com>
> Subject: [Intel-wired-lan] [PATCH net v2] iavf: Fix ping is lost after
> untrusted VF had tried to change MAC
>
> From: Sylwester Dziedziuch <sylwesterx.dziedziuch@intel.com>
>
> 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: c5c922b3e09b ("iavf: fix MAC address setting for VFs when
> filter is
> rejected")
> Signed-off-by: Przemyslaw Patynowski
> <przemyslawx.patynowski@intel.com>
> Signed-off-by: Sylwester Dziedziuch <sylwesterx.dziedziuch@intel.com>
> Signed-off-by: Mateusz Palczewski <mateusz.palczewski@intel.com>
> ---
>  v2: Fixed function names in comments
> ---
>  drivers/net/ethernet/intel/iavf/iavf.h        |  1 +
>  drivers/net/ethernet/intel/iavf/iavf_main.c   |  1 +
>  .../net/ethernet/intel/iavf/iavf_virtchnl.c   | 47 ++++++++++++++++++-
>  3 files changed, 47 insertions(+), 2 deletions(-)
>
 
Tested-by: Gurucharan  G <Gurucharanx.g@intel.com> A Contingent Worker
> at Intel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-22  9:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-28 12:11 [Intel-wired-lan] [PATCH net v2] iavf: Fix ping is lost after untrusted VF had tried to change MAC Mateusz Palczewski
     [not found] ` <BN6PR11MB392398056E8C2C4942BEC4038C189@BN6PR11MB3923.namprd11.prod.outlook.com>
     [not found]   ` <BYAPR11MB33678799BFFC6AEEEE9EDDCCFC139@BYAPR11MB3367.namprd11.prod.outlook.com>
     [not found]     ` <BYAPR11MB336713E82D26AEEA08B4A2FAFC139@BYAPR11MB3367.namprd11.prod.outlook.com>
     [not found]       ` <BYAPR11MB3367955F8C5E5474683E46F7FCE49@BYAPR11MB3367.namprd11.prod.outlook.com>
     [not found]         ` <BYAPR11MB3367A5CD95A08A740B0D3843FCE49@BYAPR11MB3367.namprd11.prod.outlook.com>
     [not found]           ` <BYAPR11MB3367EF5CEE54FC6415541454FCE49@BYAPR11MB3367.namprd11.prod.outlook.com>
2021-07-22  9:55             ` G, GurucharanX

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.