Skip to contentSkip to conversation

net/bnxt: validate pool index in pool manager APIs

PATCH New Manish Kurup 2 participants 2 messages Oct 5 – Oct 12 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/bnxt: validate pool index in pool manager APIs

From: Kishore Padmanabha <[email protected]>

Validate the pool index in the pool manager APIs so that it cannot go out of bounds when setting or getting data from the table-scope pool manager.

Fixes 80317ff6adfd ("net/bnxt/tf_core: support Thor2")
---
 drivers/net/bnxt/hcapi/cfa_v3/tpm/cfa_tpm.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/net/bnxt/hcapi/cfa_v3/tpm/cfa_tpm.c +19 -0
index 790b6c7e42..90d0206a15 100644
@@ -6,6 +6,7 @@
 #define COMP_ID TPM
 
 #include <errno.h>
+#include <inttypes.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <string.h>
@@ -119,6 +120,12 @@ int cfa_tpm_free(void *tpm, uint16_t pool_id)
 		return -EINVAL;
 	}
 
+	if (pool_id >= ctx->max_pools) {
+		CFA_LOG_ERR("pool_id (%" PRIu16 ") out of range (max %" PRIu16 ")\n",
+			    pool_id, ctx->max_pools);
+		return -EINVAL;
+	}
+
 	if (ctx->fid_tbl[pool_id] != CFA_INVALID_FID) {
 		CFA_LOG_ERR("A function (%d) is still using the pool (%d)\n",
 			    ctx->fid_tbl[pool_id], pool_id);
@@ -137,6 +144,12 @@ int cfa_tpm_fid_add(void *tpm, uint16_t pool_id, uint16_t fid)
 		return -EINVAL;
 	}
 
+	if (pool_id >= ctx->max_pools) {
+		CFA_LOG_ERR("pool_id (%" PRIu16 ") out of range (max %" PRIu16 ")\n",
+			    pool_id, ctx->max_pools);
+		return -EINVAL;
+	}
+
 	if (!ba_inuse(ctx->pool_ba, pool_id)) {
 		CFA_LOG_ERR("Pool id (%d) was not allocated\n", pool_id);
 		return -EINVAL;
@@ -163,6 +176,12 @@ int cfa_tpm_fid_rem(void *tpm, uint16_t pool_id, uint16_t fid)
 		return -EINVAL;
 	}
 
+	if (pool_id >= ctx->max_pools) {
+		CFA_LOG_ERR("pool_id (%" PRIu16 ") out of range (max %" PRIu16 ")\n",
+			    pool_id, ctx->max_pools);
+		return -EINVAL;
+	}
+
 	if (!ba_inuse(ctx->pool_ba, pool_id)) {
 		CFA_LOG_ERR("Pool id (%d) was not allocated\n", pool_id);
 		return -EINVAL;
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/1 net/bnxt: validate pool index in pool manager APIs

From: Kishore Padmanabha <[email protected]>

Validate the pool index in the pool manager APIs so that it cannot go out of bounds when setting or getting data from the table-scope pool manager.

Fixes 80317ff6adfd ("net/bnxt/tf_core: support Thor2")

---
v2:
- Use %u for the new log messages instead of PRIu16, and drop the <inttypes.h> include that is no longer needed

 drivers/net/bnxt/hcapi/cfa_v3/tpm/cfa_tpm.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/net/bnxt/hcapi/cfa_v3/tpm/cfa_tpm.c +18 -0
index 790b6c7e420..b143d045e15 100644
@@ -119,6 +119,12 @@ int cfa_tpm_free(void *tpm, uint16_t pool_id)
 		return -EINVAL;
 	}
 
+	if (pool_id >= ctx->max_pools) {
+		CFA_LOG_ERR("pool_id (%u) out of range (max %u)\n",
+			    pool_id, ctx->max_pools);
+		return -EINVAL;
+	}
+
 	if (ctx->fid_tbl[pool_id] != CFA_INVALID_FID) {
 		CFA_LOG_ERR("A function (%d) is still using the pool (%d)\n",
 			    ctx->fid_tbl[pool_id], pool_id);
@@ -137,6 +143,12 @@ int cfa_tpm_fid_add(void *tpm, uint16_t pool_id, uint16_t fid)
 		return -EINVAL;
 	}
 
+	if (pool_id >= ctx->max_pools) {
+		CFA_LOG_ERR("pool_id (%u) out of range (max %u)\n",
+			    pool_id, ctx->max_pools);
+		return -EINVAL;
+	}
+
 	if (!ba_inuse(ctx->pool_ba, pool_id)) {
 		CFA_LOG_ERR("Pool id (%d) was not allocated\n", pool_id);
 		return -EINVAL;
@@ -163,6 +175,12 @@ int cfa_tpm_fid_rem(void *tpm, uint16_t pool_id, uint16_t fid)
 		return -EINVAL;
 	}
 
+	if (pool_id >= ctx->max_pools) {
+		CFA_LOG_ERR("pool_id (%u) out of range (max %u)\n",
+			    pool_id, ctx->max_pools);
+		return -EINVAL;
+	}
+
 	if (!ba_inuse(ctx->pool_ba, pool_id)) {
 		CFA_LOG_ERR("Pool id (%d) was not allocated\n", pool_id);
 		return -EINVAL;
Signature · 1 line
2.47.3