[v3] app/pdump: check lcore is not the maximum core

Message ID 20220222110224.56857-1-reshma.pattan@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v3] 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/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
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-abi-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

Pattan, Reshma Feb. 22, 2022, 11:02 a.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>
---
v3: add new function to get next core id and validate it.
---
 app/pdump/main.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
  

Comments

Pattan, Reshma Feb. 25, 2022, 9:59 a.m. UTC | #1
> -----Original Message-----
> From: Pattan, Reshma <reshma.pattan@intel.com>

<snip>

Hi Stephen,

Can you take a look and ack the patch.

Thanks,
Reshma
  
Stephen Hemminger Feb. 25, 2022, 5:34 p.m. UTC | #2
On Tue, 22 Feb 2022 11:02:24 +0000
Reshma Pattan <reshma.pattan@intel.com> wrote:

> 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>
> ---
> v3: add new function to get next core id and validate it.
> ---
>  app/pdump/main.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/app/pdump/main.c b/app/pdump/main.c
> index 04a38e8911..e4e62811c9 100644
> --- a/app/pdump/main.c
> +++ b/app/pdump/main.c
> @@ -900,6 +900,15 @@ dump_packets_core(void *arg)
>  	return 0;
>  }
>  
> +static inline void
> +get_next_core(uint32_t *lcore_id)
> +{
> +	*lcore_id = rte_get_next_lcore(*lcore_id, 1, 0);
> +	if (*lcore_id == RTE_MAX_LCORE)
> +		rte_exit(EXIT_FAILURE,
> +				"Max core limit %u reached for packet capture", *lcore_id);
> +}
> +

This looks good, can I make a some suggestions.

Since function either exits or returns a good value, I would prefer
that it returned the lcore id. Avoiding call by reference if possible.

Also, the lcore is currently typed unsigned int in rte_lcore.h
therefore use that type?

Inline is certainly unnecessary here, not critical path and compiler
is likely to do it anyway.

Also, DPDK uses lcore for most places (rather than core) so use that name.

Result is:

static unsigned int
get_next_lcore(unsigned int lcore)
{
	lcore = rte_get_next_lcore(lcore, 1, 0);
	if (lcore >= RTE_MAX_LCORE)
			"Max core limit %u reached for packet capture", lcore);
	return lcore;
}

>  static inline void
>  dump_packets(void)
>  {
> @@ -930,12 +939,12 @@ dump_packets(void)
>  		return;
>  	}
>  
> -	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
> +	get_next_core(&lcore_id);
>  
>  	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);
> +		get_next_core(&lcore_id);
>  
>  		if (rte_eal_wait_lcore(lcore_id) < 0)
>  			rte_exit(EXIT_FAILURE, "failed to wait\n");
  

Patch

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 04a38e8911..e4e62811c9 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -900,6 +900,15 @@  dump_packets_core(void *arg)
 	return 0;
 }
 
+static inline void
+get_next_core(uint32_t *lcore_id)
+{
+	*lcore_id = rte_get_next_lcore(*lcore_id, 1, 0);
+	if (*lcore_id == RTE_MAX_LCORE)
+		rte_exit(EXIT_FAILURE,
+				"Max core limit %u reached for packet capture", *lcore_id);
+}
+
 static inline void
 dump_packets(void)
 {
@@ -930,12 +939,12 @@  dump_packets(void)
 		return;
 	}
 
-	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
+	get_next_core(&lcore_id);
 
 	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);
+		get_next_core(&lcore_id);
 
 		if (rte_eal_wait_lcore(lcore_id) < 0)
 			rte_exit(EXIT_FAILURE, "failed to wait\n");