qed: validate and restrict untrusted VFs vlan promisc mode
authorManish Chopra <manishc@marvell.com>
Wed, 2 Mar 2022 10:52:22 +0000 (02:52 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 12:22:54 +0000 (14:22 +0200)
commit cbcc44db2cf7b836896733acc0e5ea966136ed22 upstream.

Today when VFs are put in promiscuous mode, they can request PF
to configure device for them to receive all VLANs traffic regardless
of what vlan is configured by the PF (via ip link) and PF allows this
config request regardless of whether VF is trusted or not.

From security POV, when VLAN is configured for VF through PF (via ip link),
honour such config requests from VF only when they are configured to be
trusted, otherwise restrict such VFs vlan promisc mode config.

Cc: stable@vger.kernel.org
Fixes: f990c82c385b ("qed*: Add support for ndo_set_vf_trust")
Signed-off-by: Manish Chopra <manishc@marvell.com>
Signed-off-by: Ariel Elior <aelior@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/net/ethernet/qlogic/qed/qed_sriov.c
drivers/net/ethernet/qlogic/qed/qed_sriov.h

index 3fe242b81e4a502a678c9aa69f1d0eca38884254..3eb05376e7c3e516c783963a8edaceb061edb693 100644 (file)
@@ -2982,12 +2982,16 @@ static int qed_iov_pre_update_vport(struct qed_hwfn *hwfn,
        u8 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
        struct qed_filter_accept_flags *flags = &params->accept_flags;
        struct qed_public_vf_info *vf_info;
+       u16 tlv_mask;
+
+       tlv_mask = BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM) |
+                  BIT(QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN);
 
        /* Untrusted VFs can't even be trusted to know that fact.
         * Simply indicate everything is configured fine, and trace
         * configuration 'behind their back'.
         */
-       if (!(*tlvs & BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM)))
+       if (!(*tlvs & tlv_mask))
                return 0;
 
        vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
@@ -3004,6 +3008,13 @@ static int qed_iov_pre_update_vport(struct qed_hwfn *hwfn,
                        flags->tx_accept_filter &= ~mask;
        }
 
+       if (params->update_accept_any_vlan_flg) {
+               vf_info->accept_any_vlan = params->accept_any_vlan;
+
+               if (vf_info->forced_vlan && !vf_info->is_trusted_configured)
+                       params->accept_any_vlan = false;
+       }
+
        return 0;
 }
 
@@ -5122,6 +5133,12 @@ static void qed_iov_handle_trust_change(struct qed_hwfn *hwfn)
 
                params.update_ctl_frame_check = 1;
                params.mac_chk_en = !vf_info->is_trusted_configured;
+               params.update_accept_any_vlan_flg = 0;
+
+               if (vf_info->accept_any_vlan && vf_info->forced_vlan) {
+                       params.update_accept_any_vlan_flg = 1;
+                       params.accept_any_vlan = vf_info->accept_any_vlan;
+               }
 
                if (vf_info->rx_accept_mode & mask) {
                        flags->update_rx_mode_config = 1;
@@ -5137,13 +5154,20 @@ static void qed_iov_handle_trust_change(struct qed_hwfn *hwfn)
                if (!vf_info->is_trusted_configured) {
                        flags->rx_accept_filter &= ~mask;
                        flags->tx_accept_filter &= ~mask;
+                       params.accept_any_vlan = false;
                }
 
                if (flags->update_rx_mode_config ||
                    flags->update_tx_mode_config ||
-                   params.update_ctl_frame_check)
+                   params.update_ctl_frame_check ||
+                   params.update_accept_any_vlan_flg) {
+                       DP_VERBOSE(hwfn, QED_MSG_IOV,
+                                  "vport update config for %s VF[abs 0x%x rel 0x%x]\n",
+                                  vf_info->is_trusted_configured ? "trusted" : "untrusted",
+                                  vf->abs_vf_id, vf->relative_vf_id);
                        qed_sp_vport_update(hwfn, &params,
                                            QED_SPQ_MODE_EBLOCK, NULL);
+               }
        }
 }
 
index eacd6457f195ce650b35859ca442cbe73377479f..7ff23ef8ccc170c15b7c80d1dd6d1c34d8798b79 100644 (file)
@@ -62,6 +62,7 @@ struct qed_public_vf_info {
        bool is_trusted_request;
        u8 rx_accept_mode;
        u8 tx_accept_mode;
+       bool accept_any_vlan;
 };
 
 struct qed_iov_vf_init_params {