]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
ice: add validation in OP_CONFIG_VSI_QUEUES VF message
authorMichal Swiatkowski <michal.swiatkowski@intel.com>
Thu, 25 Jul 2019 09:53:59 +0000 (02:53 -0700)
committerJeff Kirsher <jeffrey.t.kirsher@intel.com>
Tue, 27 Aug 2019 06:25:14 +0000 (23:25 -0700)
Check num_queue_pairs to avoid access to unallocated field of
vsi->tx_rings/vsi->rx_rings. Without this validation we can set
vsi->alloc_txq/vsi->alloc_rxq to value smaller than ICE_MAX_BASE_QS_PER_VF
and send this command with num_queue_pairs greater than
vsi->alloc_txq/vsi->alloc_rxq. This lead to access to unallocated memory.

In VF vsi alloc_txq and alloc_rxq should be the same. Get minimum
because looks more readable.

Also add validation for ring_len param. It should be greater than 32 and
be multiple of 32. Incorrect value leads to hang traffic on PF.

Signed-off-by: Michal Swiatkowski <michal.swiatkowski@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c

index 86637d99ee77573c4a8eb16b638c3dc8583f43ee..e6578d2f0876a65c7612bc26e7cdf1c3562e0b19 100644 (file)
@@ -1712,6 +1712,19 @@ static bool ice_vc_isvalid_q_id(struct ice_vf *vf, u16 vsi_id, u8 qid)
        return (vsi && (qid < vsi->alloc_txq));
 }
 
+/**
+ * ice_vc_isvalid_ring_len
+ * @ring_len: length of ring
+ *
+ * check for the valid ring count, should be multiple of ICE_REQ_DESC_MULTIPLE
+ */
+static bool ice_vc_isvalid_ring_len(u16 ring_len)
+{
+       return (ring_len >= ICE_MIN_NUM_DESC &&
+               ring_len <= ICE_MAX_NUM_DESC &&
+               !(ring_len % ICE_REQ_DESC_MULTIPLE));
+}
+
 /**
  * ice_vc_config_rss_key
  * @vf: pointer to the VF info
@@ -2107,16 +2120,17 @@ static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
                goto error_param;
        }
 
-       if (qci->num_queue_pairs > ICE_MAX_BASE_QS_PER_VF) {
-               dev_err(&pf->pdev->dev,
-                       "VF-%d requesting more than supported number of queues: %d\n",
-                       vf->vf_id, qci->num_queue_pairs);
+       vsi = pf->vsi[vf->lan_vsi_idx];
+       if (!vsi) {
                v_ret = VIRTCHNL_STATUS_ERR_PARAM;
                goto error_param;
        }
 
-       vsi = pf->vsi[vf->lan_vsi_idx];
-       if (!vsi) {
+       if (qci->num_queue_pairs > ICE_MAX_BASE_QS_PER_VF ||
+           qci->num_queue_pairs > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
+               dev_err(&pf->pdev->dev,
+                       "VF-%d requesting more than supported number of queues: %d\n",
+                       vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
                v_ret = VIRTCHNL_STATUS_ERR_PARAM;
                goto error_param;
        }
@@ -2127,6 +2141,8 @@ static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
                    qpi->rxq.vsi_id != qci->vsi_id ||
                    qpi->rxq.queue_id != qpi->txq.queue_id ||
                    qpi->txq.headwb_enabled ||
+                   !ice_vc_isvalid_ring_len(qpi->txq.ring_len) ||
+                   !ice_vc_isvalid_ring_len(qpi->rxq.ring_len) ||
                    !ice_vc_isvalid_q_id(vf, qci->vsi_id, qpi->txq.queue_id)) {
                        v_ret = VIRTCHNL_STATUS_ERR_PARAM;
                        goto error_param;
@@ -2137,7 +2153,8 @@ static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
                /* copy Rx queue info from VF into VSI */
                vsi->rx_rings[i]->dma = qpi->rxq.dma_ring_addr;
                vsi->rx_rings[i]->count = qpi->rxq.ring_len;
-               if (qpi->rxq.databuffer_size > ((16 * 1024) - 128)) {
+               if (qpi->rxq.databuffer_size > ((16 * 1024) - 128) ||
+                   qpi->rxq.databuffer_size < 1024) {
                        v_ret = VIRTCHNL_STATUS_ERR_PARAM;
                        goto error_param;
                }