DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Sergeev <denserg.edu@gmail.com>
To: dev@dpdk.org
Cc: kishore.padmanabha@broadcom.com, ajit.khaparde@broadcom.com,
	stable@dpdk.org, sdl.dpdk@linuxtesting.org,
	Denis Sergeev <denserg.edu@gmail.com>
Subject: [PATCH] net/bnxt/tf_core: fix null deref on pool use allocation
Date: Wed,  3 Jun 2026 07:15:43 +0300	[thread overview]
Message-ID: <20260603041557.115956-1-denserg.edu@gmail.com> (raw)

rte_zmalloc() in cpm_insert_pool_id() can return NULL when memory is
exhausted. The return value was not checked before being dereferenced,
resulting in a crash.

Add a NULL check and return -ENOMEM on failure. Also propagate the
error in tfc_cpm_set_cmm_inst() which silently discarded the return
value of cpm_insert_pool_id(), and restore the pool state on failure.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 80317ff6adfd ("net/bnxt/tf_core: support Thor2")
Cc: stable@dpdk.org

Signed-off-by: Denis Sergeev <denserg.edu@gmail.com>
---
 drivers/net/bnxt/tf_core/v3/tfc_cpm.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/net/bnxt/tf_core/v3/tfc_cpm.c b/drivers/net/bnxt/tf_core/v3/tfc_cpm.c
index f58ec48db7..28e2a3d8dd 100644
--- a/drivers/net/bnxt/tf_core/v3/tfc_cpm.c
+++ b/drivers/net/bnxt/tf_core/v3/tfc_cpm.c
@@ -92,6 +92,10 @@ static int cpm_insert_pool_id(struct tfc_cpm *cpm, uint16_t pool_id)
 
 	/* Alloc new entry */
 	new_pool_use = rte_zmalloc("tf", sizeof(struct cpm_pool_use), 0);
+	if (new_pool_use == NULL) {
+		PMD_DRV_LOG_LINE(ERR, "Failed to allocate pool_use entry");
+		return -ENOMEM;
+	}
 	new_pool_use->pool_id = pool_id;
 	new_pool_use->prev = NULL;
 	new_pool_use->next = NULL;
@@ -287,6 +291,7 @@ int tfc_cpm_get_pool_size(struct tfc_cpm *cpm, uint32_t *pool_sz_in_records)
 int tfc_cpm_set_cmm_inst(struct tfc_cpm *cpm, uint16_t pool_id, struct tfc_cmm *cmm)
 {
 	struct cpm_pool_entry *pool;
+	int rc;
 
 	if (cpm == NULL) {
 		PMD_DRV_LOG_LINE(ERR, "CPM is NULL");
@@ -313,7 +318,12 @@ int tfc_cpm_set_cmm_inst(struct tfc_cpm *cpm, uint16_t pool_id, struct tfc_cmm *
 		pool->valid = false;
 	} else {
 		pool->valid = true;
-		cpm_insert_pool_id(cpm, pool_id);
+		rc = cpm_insert_pool_id(cpm, pool_id);
+		if (rc) {
+			pool->cmm = NULL;
+			pool->valid = false;
+			return rc;
+		}
 	}
 
 	return 0;
-- 
2.50.1


                 reply	other threads:[~2026-06-03  4:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260603041557.115956-1-denserg.edu@gmail.com \
    --to=denserg.edu@gmail.com \
    --cc=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=kishore.padmanabha@broadcom.com \
    --cc=sdl.dpdk@linuxtesting.org \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox