app/pdump: check lcore is not the maximum core

Message ID 20220218151841.116135-1-reshma.pattan@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series app/pdump: check lcore is not the maximum core |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Pattan, Reshma Feb. 18, 2022, 3:18 p.m. UTC
  Check lcore id value is not the maximum core supported.
Using lcore id without this check might cause
out of bound access inside the rte_eal_wait_lcore.

Coverity issue: 375841
Fixes: b2854d5317e8 ("app/pdump: support multi-core capture")
Cc: vipin.varghese@intel.com
Cc: stable@dpdk.org

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
 app/pdump/main.c | 8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Stephen Hemminger Feb. 18, 2022, 4:27 p.m. UTC | #1
On Fri, 18 Feb 2022 15:18:41 +0000
Reshma Pattan <reshma.pattan@intel.com> wrote:

>  	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
> +	if (lcore_id == RTE_MAX_LCORE) {
> +		printf("Invalid core %u for the packet capture!\n", lcore_id);
> +		return;
> +	}

Since nothing useful can be done, maybe rte_exit()?
Or at least print to stderr and return error status.

Also, if you write same code in two places, it should
be a function.
  

Patch

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 04a38e8911..686c27d965 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -931,11 +931,19 @@  dump_packets(void)
 	}
 
 	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
+	if (lcore_id == RTE_MAX_LCORE) {
+		printf("Invalid core %u for the packet capture!\n", lcore_id);
+		return;
+	}
 
 	for (i = 0; i < num_tuples; i++) {
 		rte_eal_remote_launch(dump_packets_core,
 				&pdump_t[i], lcore_id);
 		lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
+		if (lcore_id == RTE_MAX_LCORE) {
+			printf("Invalid core %u for the capture for the tuple=%d!\n", lcore_id, i);
+			return;
+		}
 
 		if (rte_eal_wait_lcore(lcore_id) < 0)
 			rte_exit(EXIT_FAILURE, "failed to wait\n");