[04/20] net/bnxt: add validations to dpdk port id and phy port parsing
diff mbox series

Message ID 20200706082502.26935-5-somnath.kotur@broadcom.com
State Accepted, archived
Delegated to: Ajit Khaparde
Headers show
Series
  • bnxt patches
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Somnath Kotur July 6, 2020, 8:24 a.m. UTC
From: Kishore Padmanabha <kishore.padmanabha@broadcom.com>

Added validations to the ulp parser to validate the dpdk port id
and phy port index during the flow creation.

Signed-off-by: Kishore Padmanabha <kishore.padmanabha@broadcom.com>
Reviewed-by: Michael Baucom <michael.baucom@broadcom.com>
Signed-off-by: Somnath Kotur <somnath.kotur@broadcom.com>
Signed-off-by: Venkat Duvvuru <venkatkumar.duvvuru@broadcom.com>
---
 drivers/net/bnxt/tf_ulp/ulp_rte_parser.c | 50 ++++++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c b/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c
index a4dbd84..b8146c8 100644
--- a/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c
+++ b/drivers/net/bnxt/tf_ulp/ulp_rte_parser.c
@@ -297,8 +297,13 @@  ulp_rte_port_id_hdr_handler(const struct rte_flow_item *item,
 	 * Copy the rte_flow_item for Port into hdr_field using port id
 	 * header fields.
 	 */
-	if (port_spec)
+	if (port_spec) {
 		svif = (uint16_t)port_spec->id;
+		if (svif >= RTE_MAX_ETHPORTS) {
+			BNXT_TF_DBG(ERR, "ParseErr:Portid is not valid\n");
+			return BNXT_TF_RC_PARSE_ERR;
+		}
+	}
 	if (port_mask)
 		mask = (uint16_t)port_mask->id;
 
@@ -314,6 +319,8 @@  ulp_rte_phy_port_hdr_handler(const struct rte_flow_item *item,
 	const struct rte_flow_item_phy_port *port_spec = item->spec;
 	const struct rte_flow_item_phy_port *port_mask = item->mask;
 	uint32_t svif = 0, mask = 0;
+	struct bnxt_ulp_device_params *dparms;
+	uint32_t dev_id;
 
 	/* Copy the rte_flow_item for phy port into hdr_field */
 	if (port_spec)
@@ -321,6 +328,22 @@  ulp_rte_phy_port_hdr_handler(const struct rte_flow_item *item,
 	if (port_mask)
 		mask = port_mask->index;
 
+	if (bnxt_ulp_cntxt_dev_id_get(params->ulp_ctx, &dev_id)) {
+		BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
+		return -EINVAL;
+	}
+
+	dparms = bnxt_ulp_device_params_get(dev_id);
+	if (!dparms) {
+		BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
+		return -EINVAL;
+	}
+
+	if (svif > dparms->num_phy_ports) {
+		BNXT_TF_DBG(ERR, "ParseErr:Phy Port is not valid\n");
+		return BNXT_TF_RC_PARSE_ERR;
+	}
+
 	/* Update the SVIF details */
 	return ulp_rte_parser_svif_set(params, item->type, svif, mask);
 }
@@ -1330,7 +1353,12 @@  ulp_rte_port_id_act_handler(const struct rte_flow_action *act_item,
 				    "ParseErr:Portid Original not supported\n");
 			return BNXT_TF_RC_PARSE_ERR;
 		}
-		/* TBD: Update the computed VNIC using port conversion */
+		/* Update the computed VNIC using port conversion */
+		if (port_id->id >= RTE_MAX_ETHPORTS) {
+			BNXT_TF_DBG(ERR,
+				    "ParseErr:Portid is not valid\n");
+			return BNXT_TF_RC_PARSE_ERR;
+		}
 		pid = bnxt_get_vnic_id(port_id->id, BNXT_ULP_INTF_TYPE_INVALID);
 		pid = rte_cpu_to_be_32(pid);
 		memcpy(&param->act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
@@ -1349,6 +1377,8 @@  ulp_rte_phy_port_act_handler(const struct rte_flow_action *action_item,
 {
 	const struct rte_flow_action_phy_port *phy_port;
 	uint32_t vport;
+	struct bnxt_ulp_device_params *dparms;
+	uint32_t dev_id;
 
 	phy_port = action_item->conf;
 	if (phy_port) {
@@ -1357,6 +1387,22 @@  ulp_rte_phy_port_act_handler(const struct rte_flow_action *action_item,
 				    "Parse Err:Port Original not supported\n");
 			return BNXT_TF_RC_PARSE_ERR;
 		}
+		if (bnxt_ulp_cntxt_dev_id_get(prm->ulp_ctx, &dev_id)) {
+			BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
+			return -EINVAL;
+		}
+
+		dparms = bnxt_ulp_device_params_get(dev_id);
+		if (!dparms) {
+			BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
+			return -EINVAL;
+		}
+
+		if (phy_port->index > dparms->num_phy_ports) {
+			BNXT_TF_DBG(ERR, "ParseErr:Phy Port is not valid\n");
+			return BNXT_TF_RC_PARSE_ERR;
+		}
+
 		/* Get the vport of the physical port */
 		/* TBD: shall be changed later to portdb call */
 		vport = 1 << phy_port->index;