Skip to contentSkip to conversation

net/bnxt: fix multiple truflow defects

PATCH New Manish Kurup 1 participant 7 messages Oct 5 – Oct 20 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/bnxt: fix multiple truflow defects

Fix seven unrelated defects found across the tf_core and tf_ulp message/table/resource-management code:

1. tf_ulp: fix blob overflow in Thor2 EM key build ulp_blob_pad_push() in ulp_mapper_tfc_em_tbl_process() was called without checking the return value. If a dynamic EM key length plus block-alignment padding exceeded 1024 bits, write_idx would advance past bitlen and the subsequent ulp_blob_append() would write past the end of the blob.

2. tf_core: fix tcam alloc_set memcpy args tfc_msg_tcam_alloc_set() had two bugs in the memcpy calls packing key, mask, and remap into the HWRM request: source was &key/&mask/&remap (address of the local pointer) instead of key/mask/remap (the data), and the length used key_size * sizeof(u32) when key_size is already a byte count, making each copy 4x oversized and overrunning the buffer.

3. tf_core: fix RM resource leak in tf_sram_mgr_alloc When tf_sram_alloc_block() failed to allocate a block struct, the function returned -ENOMEM without releasing the RM index(es) just claimed via tf_rm_allocate() - both the primary index and, when a second sequential 64B block was also claimed, that second index - leaving them permanently marked in-use in the bitalloc pool.

4. tf_core: validate FW TCAM response offsets before memcpy In tf_msg_tcam_entry_get(), firmware-supplied key_size and result_offset/result_size were used as indices into the dev_data[] response array without range checks. A malformed FW response could cause out-of-bounds reads.

5. tf_core: fix memory leak of query buffer in tf_rm_create_db The query buffer allocated at the start of tf_rm_create_db() was freed on all error paths but not on the success return path, leaking memory on every successful call.

6. tf_core: fix buffer overflow in tf_msg_get_global_cfg The memcpy copying global-cfg data back to the caller used the HWRM resp_size as the copy length. The existing lower-bound check only ensures the FW returned enough data; it does not prevent a larger resp_size from overflowing the caller's buffer. Copy only params->config_sz_in_bytes instead.

7. net/bnxt: fix double-free of TPM in tbl_scope_pools_create After cfa_tim_tpm_inst_set() succeeds, ownership of the TPM transfers to TIM, but tpms[dir][region] was never cleared. On any subsequent failure the cleanup loop would free the TPM again, causing a UAF inside cfa_tpm_close() and a double-free on rte_free(). Null out tpms[dir][region] after a successful set to mark ownership as transferred.

Fixes dd0191d5e70d ("net/bnxt/tf_ulp: support Thor2 ULP layer")
Fixes 80317ff6adfd ("net/bnxt/tf_core: support Thor2")
Fixes 37ff91c158a3 ("net/bnxt: add SRAM manager model")
Fixes a9597be79f66 ("net/bnxt: support L2 context TCAM operations")
Fixes a11f87d3b2ca ("net/bnxt: add global config set and get functions")
Fixes ced3cded4492 ("net/bnxt: update table get to use new design")
---
 drivers/net/bnxt/tf_core/tf_msg.c           | 12 +++++++++++-
 drivers/net/bnxt/tf_core/tf_rm.c            |  1 +
 drivers/net/bnxt/tf_core/tf_sram_mgr.c      | 17 +++++++++++++++++
 drivers/net/bnxt/tf_core/v3/tfc_msg.c       |  6 +++---
 drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c |  1 +
 drivers/net/bnxt/tf_ulp/ulp_mapper_tfc.c    |  5 ++++-
 6 files changed, 37 insertions(+), 5 deletions(-)
drivers/net/bnxt/tf_core/tf_msg.c +11 -1
index 645a4b1e66..c6b661824d 100644
@@ -1243,6 +1243,16 @@ tf_msg_tcam_entry_get(struct tf *tfp,
 			    strerror(-rc));
 		return rc;
 	}
+	if (resp.key_size * 2 > sizeof(resp.dev_data) ||
+	    resp.result_offset + resp.result_size > sizeof(resp.dev_data)) {
+		rc = -EINVAL;
+		TFP_DRV_LOG(ERR,
+			    "%s: FW data out of bounds key_size(%d) result_offset(%d) result_size(%d), rc:%s\n",
+			    tf_dir_2_str(parms->dir), resp.key_size,
+			    resp.result_offset, resp.result_size,
+			    strerror(-rc));
+		return rc;
+	}
 	parms->key_size = resp.key_size;
 	parms->result_size = resp.result_size;
 	tfp_memcpy(parms->key, resp.dev_data, resp.key_size);
@@ -1552,7 +1562,7 @@ tf_msg_get_global_cfg(struct tf *tfp,
 	if (params->config)
 		tfp_memcpy(params->config,
 			   resp.data,
-			   resp_size);
+			   params->config_sz_in_bytes);
 	else
 		return -EFAULT;
 
drivers/net/bnxt/tf_core/tf_rm.c +1 -0
index 18f46c0a0a..a99eb68e59 100644
@@ -721,6 +721,7 @@ tf_rm_create_db(struct tf *tfp,
 	rm_db->module = parms->module;
 	*parms->rm_db = (void *)rm_db;
 
+	tfp_free((void *)query);
 	tfp_free((void *)req);
 	tfp_free((void *)resv);
 	tfp_free((void *)req_cnt);
drivers/net/bnxt/tf_core/tf_sram_mgr.c +17 -0
index 0dffd74cd5..654d273baa 100644
@@ -710,6 +710,23 @@ int tf_sram_mgr_alloc(void *sram_handle,
 		}
 		block_id = index;
 		block = tf_sram_alloc_block(slice_list, block_id);
+		if (!block) {
+			fparms.rm_db = parms->rm_db;
+			fparms.subtype = parms->tbl_type;
+			fparms.index = block_id;
+			rc = tf_rm_free(&fparms);
+			if (rc)
+				TFP_DRV_LOG(ERR,
+					    "Free block_id(%d) failed rc:%d\n",
+					    block_id, rc);
+			fparms.index = next_index;
+			rc = tf_rm_free(&fparms);
+			if (rc)
+				TFP_DRV_LOG(ERR,
+					    "Free block_id(%d) failed rc:%d\n",
+					    next_index, rc);
+			return -ENOMEM;
+		}
 
 	} else {
 		/* Block exists
drivers/net/bnxt/tf_core/v3/tfc_msg.c +3 -3
index cf72d09184..81ef289c50 100644
@@ -1064,9 +1064,9 @@ tfc_msg_tcam_alloc_set(struct tfc *tfcp, uint16_t fid, uint16_t sid,
 		data = &req.dev_data[0];
 	}
 
-	memcpy(&data[0], &key, key_size * sizeof(uint32_t));
-	memcpy(&data[key_size], &mask, key_size * sizeof(uint32_t));
-	memcpy(&data[key_size * 2], &remap, remap_size * sizeof(uint32_t));
+	memcpy(&data[0], key, key_size);
+	memcpy(&data[key_size], mask, key_size);
+	memcpy(&data[key_size * 2], remap, remap_size);
 	rc = bnxt_hwrm_tf_message_direct(bp, false, HWRM_TFC_TCAM_ALLOC_SET,
 					 &req, sizeof(req), &resp, sizeof(resp));
 
drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c +1 -0
index c06099af12..f6dba101aa 100644
@@ -631,6 +631,7 @@ static int tbl_scope_pools_create(struct tfc *tfcp, uint8_t tsid,
 			rc = cfa_tim_tpm_inst_set(tim, tsid, region, dir, tpms[dir][region]);
 			if (rc)
 				goto cleanup;
+			tpms[dir][region] = NULL;
 		}
 	}
 
drivers/net/bnxt/tf_ulp/ulp_mapper_tfc.c +4 -1
index 2d89f10d5e..f02837bf5d 100644
@@ -517,7 +517,10 @@ ulp_mapper_tfc_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
 		align_len_bits = dparms->em_blk_align_bits - key_len;
 	}
 
-	ulp_blob_pad_push(&key, align_len_bits);
+	if (ulp_blob_pad_push(&key, align_len_bits) < 0) {
+		PMD_DRV_LOG_LINE(ERR, "Failed to pad EM key");
+		return -EINVAL;
+	}
 	key_len = ULP_BITS_2_BYTE(ulp_blob_data_len_get(&key));
 	ulp_blob_perform_byte_reverse(&key, key_len);
 	/* Create the result data blob */
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/1 net/bnxt/tf_core: fix TCAM alloc-set key copy

In tfc_msg_tcam_alloc_set(), the key, mask and remap are copied into the HWRM request with memcpy() using the address of the local pointer variables (&key, &mask, &remap) as the source instead of the data they point to. The copy lengths are also computed as size * sizeof(uint32_t), although key_size and remap_size are already byte counts, so each copy is four times too long and can run past the 2 * key_size + remap_size bytes reserved in the request.

Copy from the key, mask and remap buffers themselves, and use the byte sizes directly.

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

---
v2:
* Split out of "net/bnxt: fix multiple truflow defects" (one fix per patch); this is the tfc_msg_tcam_alloc_set() fix.
* New subject and commit message; single Fixes: tag.

 drivers/net/bnxt/tf_core/v3/tfc_msg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/bnxt/tf_core/v3/tfc_msg.c +3 -3
index 89c256b810..af74007747 100644
@@ -1088,9 +1088,9 @@ tfc_msg_tcam_alloc_set(struct tfc *tfcp, uint16_t fid, uint16_t sid,
 		data = &req.dev_data[0];
 	}
 
-	memcpy(&data[0], &key, key_size * sizeof(uint32_t));
-	memcpy(&data[key_size], &mask, key_size * sizeof(uint32_t));
-	memcpy(&data[key_size * 2], &remap, remap_size * sizeof(uint32_t));
+	memcpy(&data[0], key, key_size);
+	memcpy(&data[key_size], mask, key_size);
+	memcpy(&data[key_size * 2], remap, remap_size);
 	rc = bnxt_hwrm_tf_message_direct(bp, false, HWRM_TFC_TCAM_ALLOC_SET,
 					 &req, sizeof(req), &resp, sizeof(resp));
 
Signature · 1 line
2.31.1
#2 lore raw

PATCH v2 1/1 net/bnxt/tf_core: fix SRAM block allocation failure handling

In reply to Manish Kurup

In tf_sram_mgr_alloc(), two sequential 64B blocks are allocated from the resource manager before the tf_sram_block tracking structure is created with tf_sram_alloc_block(). If that allocation fails it returns NULL, but the NULL result was not checked: the RM indices stayed marked in use and could never be reused, and the NULL block was then dereferenced via block->block_id.

Release both RM indices and return -ENOMEM when the block structure cannot be allocated, as is already done when the two indices are not sequential.

Fixes 37ff91c158a3 ("net/bnxt: add SRAM manager model")

---
v2:
* Split out of "net/bnxt: fix multiple truflow defects" (one fix per patch); this is the tf_sram_mgr_alloc() fix.
* New subject and commit message (also notes the NULL dereference); single Fixes: tag.

 drivers/net/bnxt/tf_core/tf_sram_mgr.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/bnxt/tf_core/tf_sram_mgr.c +9 -0
index 0dffd74cd5..70bdb0ba1b 100644
@@ -710,6 +710,15 @@ int tf_sram_mgr_alloc(void *sram_handle,
 		}
 		block_id = index;
 		block = tf_sram_alloc_block(slice_list, block_id);
+		if (unlikely(!block)) {
+			fparms.index = index;
+			fparms.subtype = parms->tbl_type;
+			fparms.rm_db = parms->rm_db;
+			tf_rm_free(&fparms);
+			fparms.index = next_index;
+			tf_rm_free(&fparms);
+			return -ENOMEM;
+		}
 
 	} else {
 		/* Block exists
Signature · 1 line
2.31.1
#3 lore raw

PATCH v2 1/1 net/bnxt/tf_core: validate TCAM entry get response

In reply to Manish Kurup

tf_msg_tcam_entry_get() copies the TCAM key, mask and result out of the firmware response using the key_size, result_offset and result_size values returned in the response, without checking them against the size of the dev_data[] array they index. The mask is read from dev_data[key_size] for key_size bytes and the result from dev_data[result_offset] for result_size bytes, so a bad value makes the copy read past the end of the 272 byte array in the response on the stack.

Reject the response with -EINVAL if the key and mask (2 * key_size) or the result (result_offset + result_size) do not fit in dev_data[].

Fixes a9597be79f66 ("net/bnxt: support L2 context TCAM operations")

---
v2:
* Split out of "net/bnxt: fix multiple truflow defects" (one fix per patch); this is the tf_msg_tcam_entry_get() response check.
* New subject and commit message; single Fixes: tag.

 drivers/net/bnxt/tf_core/tf_msg.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/bnxt/tf_core/tf_msg.c +10 -0
index aab8d05d81..c345d0a7ce 100644
@@ -1243,6 +1243,16 @@ tf_msg_tcam_entry_get(struct tf *tfp,
 			    strerror(-rc));
 		return rc;
 	}
+	if (resp.key_size * 2 > sizeof(resp.dev_data) ||
+	    resp.result_offset + resp.result_size > sizeof(resp.dev_data)) {
+		rc = -EINVAL;
+		TFP_DRV_LOG(ERR,
+			    "%s: FW data out of bounds key_size(%d) result_offset(%d) result_size(%d), rc:%s\n",
+			    tf_dir_2_str(parms->dir), resp.key_size,
+			    resp.result_offset, resp.result_size,
+			    strerror(-rc));
+		return rc;
+	}
 	parms->key_size = resp.key_size;
 	parms->result_size = resp.result_size;
 	tfp_memcpy(parms->key, resp.dev_data, resp.key_size);
Signature · 1 line
2.31.1
#4 lore raw

PATCH v2 1/1 net/bnxt/tf_ulp: check EM key pad result

In reply to Manish Kurup

ulp_mapper_tfc_em_tbl_process() pads the EM key to a record boundary with ulp_blob_pad_push() but ignores its return value. The function returns -1 and leaves the write index unchanged when the requested pad does not fit in the blob, so with a long dynamic key the key was used without its padding. The key length computed afterwards, and the position at which the result is appended, are then wrong, and a malformed EM entry is sent to the hardware.

Check the return value and fail the flow with -EINVAL, as the other ulp_blob_pad_push() callers in the mapper already do.

Fixes dd0191d5e70d ("net/bnxt/tf_ulp: support Thor2 ULP layer")

---
v2:
* Split out of "net/bnxt: fix multiple truflow defects" (one fix per patch); this is the EM key pad check in ulp_mapper_tfc.c.
* Rewrote the commit message: ulp_blob_pad_push() does not overrun the blob, it fails without advancing the write index, and the failure was being ignored.
* Use unlikely() and BNXT_DRV_DBG() like the rest of the file.

 drivers/net/bnxt/tf_ulp/ulp_mapper_tfc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/bnxt/tf_ulp/ulp_mapper_tfc.c +4 -1
index 2cba6fffa8..7ace08838f 100644
@@ -519,7 +519,10 @@ ulp_mapper_tfc_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
 		align_len_bits = dparms->em_blk_align_bits - key_len;
 	}
 
-	ulp_blob_pad_push(&key, align_len_bits);
+	if (unlikely(ulp_blob_pad_push(&key, align_len_bits) < 0)) {
+		BNXT_DRV_DBG(ERR, "Failed to pad EM key\n");
+		return -EINVAL;
+	}
 	key_len = ULP_BITS_2_BYTE(ulp_blob_data_len_get(&key));
 	ulp_blob_perform_byte_reverse(&key, key_len);
 	/* Create the result data blob */
Signature · 1 line
2.31.1
#5 lore raw

PATCH v2 1/1 net/bnxt/tf_core: fix buffer leaks in RM create DB

In reply to Manish Kurup

tf_rm_create_db() allocates a capabilities query buffer, a copy of the requested counts, and the request and reservation arrays. The query buffer is never freed: not on success, not on the common error exit, and not on the early error returns. The early returns also leak whichever of the other buffers had been allocated by that point, and the rm_db structure when the element array allocation fails.

Free the query buffer on success and on the existing error path, and send the early error returns through a common label that frees the temporary buffers and returns the original error code.

Fixes ced3cded4492 ("net/bnxt: update table get to use new design")
Fixes 7052999153f2 ("net/bnxt: add action SRAM translation")

---
v2:
* Split out of "net/bnxt: fix multiple truflow defects" (one fix per patch); this is the tf_rm_create_db() leak fix.
* Rewrote the commit message and the fix: the query buffer was also leaked on the existing error path and on the early error returns, which also leaked the other temporary buffers; they now all exit through a common label.
* Two Fixes: tags, one for each commit that introduced a leaked buffer.

 drivers/net/bnxt/tf_core/tf_rm.c | 44 +++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 15 deletions(-)
drivers/net/bnxt/tf_core/tf_rm.c +29 -15
index 18f46c0a0a..76ef122204 100644
@@ -450,13 +450,13 @@ tf_rm_create_db(struct tf *tfp,
 	struct tf_session *tfs;
 	struct tf_dev_info *dev;
 	int i, j;
-	uint16_t max_types, hcapi_items, *req_cnt;
+	uint16_t max_types, hcapi_items, *req_cnt = NULL;
 	struct tfp_calloc_parms cparms;
-	struct tf_rm_resc_req_entry *query;
+	struct tf_rm_resc_req_entry *query = NULL;
 	enum tf_rm_resc_resv_strategy resv_strategy;
-	struct tf_rm_resc_req_entry *req;
-	struct tf_rm_resc_entry *resv;
-	struct tf_rm_new_db *rm_db;
+	struct tf_rm_resc_req_entry *req = NULL;
+	struct tf_rm_resc_entry *resv = NULL;
+	struct tf_rm_new_db *rm_db = NULL;
 	struct tf_rm_element *db;
 	uint32_t pool_size;
 
@@ -494,7 +494,7 @@ tf_rm_create_db(struct tf *tfp,
 				       &resv_strategy,
 				       NULL);
 	if (rc)
-		return rc;
+		goto free_bufs;
 
 	/* Copy requested counts (alloc_cnt) from tf_open_session() to local
 	 * copy (req_cnt) so that it can be updated if required.
@@ -504,7 +504,7 @@ tf_rm_create_db(struct tf *tfp,
 	cparms.size = sizeof(uint16_t);
 	rc = tfp_calloc(&cparms);
 	if (rc)
-		return rc;
+		goto free_bufs;
 
 	req_cnt = (uint16_t *)cparms.mem_va;
 
@@ -534,7 +534,8 @@ tf_rm_create_db(struct tf *tfp,
 
 	if (hcapi_items == 0) {
 		parms->rm_db = NULL;
-		return -ENOMEM;
+		rc = -ENOMEM;
+		goto free_bufs;
 	}
 
 	/* Alloc request, alignment already set */
@@ -542,14 +543,14 @@ tf_rm_create_db(struct tf *tfp,
 	cparms.size = sizeof(struct tf_rm_resc_req_entry);
 	rc = tfp_calloc(&cparms);
 	if (rc)
-		return rc;
+		goto free_bufs;
 	req = (struct tf_rm_resc_req_entry *)cparms.mem_va;
 
 	/* Alloc reservation, alignment and nitems already set */
 	cparms.size = sizeof(struct tf_rm_resc_entry);
 	rc = tfp_calloc(&cparms);
 	if (rc)
-		return rc;
+		goto free_bufs;
 	resv = (struct tf_rm_resc_entry *)cparms.mem_va;
 
 	/* Build the request */
@@ -586,7 +587,8 @@ tf_rm_create_db(struct tf *tfp,
 					hcapi_type, type_str,
 					req_cnt[i],
 					query[hcapi_type].max);
-				return -EINVAL;
+				rc = -EINVAL;
+				goto free_bufs;
 			}
 		}
 	}
@@ -600,22 +602,24 @@ tf_rm_create_db(struct tf *tfp,
 				       req,
 				       resv);
 	if (rc)
-		return rc;
+		goto free_bufs;
 
 	/* Build the RM DB per the request */
 	cparms.nitems = 1;
 	cparms.size = sizeof(struct tf_rm_new_db);
 	rc = tfp_calloc(&cparms);
 	if (rc)
-		return rc;
+		goto free_bufs;
 	rm_db = (void *)cparms.mem_va;
 
 	/* Build the DB within RM DB */
 	cparms.nitems = parms->num_elements;
 	cparms.size = sizeof(struct tf_rm_element);
 	rc = tfp_calloc(&cparms);
-	if (rc)
-		return rc;
+	if (rc) {
+		tfp_free((void *)rm_db);
+		goto free_bufs;
+	}
 	rm_db->db = (struct tf_rm_element *)cparms.mem_va;
 
 	db = rm_db->db;
@@ -721,12 +725,14 @@ tf_rm_create_db(struct tf *tfp,
 	rm_db->module = parms->module;
 	*parms->rm_db = (void *)rm_db;
 
+	tfp_free((void *)query);
 	tfp_free((void *)req);
 	tfp_free((void *)resv);
 	tfp_free((void *)req_cnt);
 	return 0;
 
  fail:
+	tfp_free((void *)query);
 	tfp_free((void *)req);
 	tfp_free((void *)resv);
 	tfp_free((void *)db->pool);
@@ -736,6 +742,14 @@ tf_rm_create_db(struct tf *tfp,
 	parms->rm_db = NULL;
 
 	return -EINVAL;
+
+ free_bufs:
+	tfp_free((void *)query);
+	tfp_free((void *)req);
+	tfp_free((void *)resv);
+	tfp_free((void *)req_cnt);
+
+	return rc;
 }
 
 int
Signature · 1 line
2.31.1
#6 lore raw

PATCH v2 1/1 net/bnxt/tf_core: fix TPM pool create error return

In reply to Manish Kurup

tbl_scope_pools_create() can return success after a failure. When rte_zmalloc() fails for a pool manager, rc is still 0 from the previous step, so the function jumps to cleanup and returns 0. For the other failures, the cleanup loop assigns the results of cfa_tim_tpm_inst_get() and cfa_tim_tpm_inst_set() to rc, replacing the error that caused the cleanup.

Callers then carry on with a table scope that has no pool managers.

Return -ENOMEM when the allocation fails, and keep the original error across the cleanup.

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

---
v2:
* Split out of "net/bnxt: fix multiple truflow defects" (one fix per patch); this is the tbl_scope_pools_create() error return fix.
* Dropped the tpms[][] = NULL change, which was a no-op. Fix the actual problem instead: the function could return success after a failure.
* Rewrote the commit message.

 drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/bnxt/tf_core/v3/tfc_tbl_scope.c +7 -2
index 0a5dce43fa..a761d9bdeb 100644
@@ -574,6 +574,7 @@ static int tbl_scope_pools_create(struct tfc *tfcp, uint8_t tsid,
 				  struct tbl_scope_pools_create_parms *parms)
 {
 	int rc;
+	int err;
 	int dir;
 	enum cfa_region_type region;
 	uint32_t tpm_db_size;
@@ -614,8 +615,10 @@ static int tbl_scope_pools_create(struct tfc *tfcp, uint8_t tsid,
 	for (region = 0; region < CFA_REGION_TYPE_MAX; region++) {
 		for (dir = 0; dir < CFA_DIR_MAX; dir++) {
 			tpms[dir][region] = rte_zmalloc("TPM", tpm_db_size, 0);
-			if (tpms[dir][region] == NULL)
+			if (tpms[dir][region] == NULL) {
+				rc = -ENOMEM;
 				goto cleanup;
+			}
 
 			rc = cfa_tpm_open(tpms[dir][region], tpm_db_size, parms->max_pools);
 			if (rc)
@@ -637,6 +640,8 @@ static int tbl_scope_pools_create(struct tfc *tfcp, uint8_t tsid,
 	return rc;
 
  cleanup:
+	/* Keep the error that got us here; the calls below overwrite rc */
+	err = rc;
 	if (tim) {
 		for (region = 0; region < CFA_REGION_TYPE_MAX; region++) {
 			for (dir = 0; dir < CFA_DIR_MAX; dir++) {
@@ -666,7 +671,7 @@ static int tbl_scope_pools_create(struct tfc *tfcp, uint8_t tsid,
 		}
 	}
 
-	return rc;
+	return err;
 }
 
 /**
Signature · 1 line
2.31.1