diff mbox series

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

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

Checks

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

Commit Message

Reshma Pattan Feb. 28, 2022, 9:58 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>
---
v4: Remove inline of new function
    Change lcore type as unsigned int
    return lcore from the function
---
 app/pdump/main.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Comments

Stephen Hemminger Feb. 28, 2022, 5:09 p.m. UTC | #1
On Mon, 28 Feb 2022 09:58:56 +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>

Great thanks.

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
John McNamara March 8, 2022, 1:47 p.m. UTC | #2
Thomas, could you include this in RC3 if possible.

> -----Original Message-----
> From: Reshma Pattan <reshma.pattan@intel.com>
> Sent: Monday, February 28, 2022 9:59 AM
> To: dev@dpdk.org
> Cc: stephen@networkplumber.org; Yigit, Ferruh <ferruh.yigit@intel.com>;
> Pattan, Reshma <reshma.pattan@intel.com>; vipin.varghese@intel.com;
> stable@dpdk.org
> Subject: [PATCH v4] app/pdump: check lcore is not the maximum core
> 
> 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>
> ---
> v4: Remove inline of new function
>     Change lcore type as unsigned int
>     return lcore from the function
> ---
>  app/pdump/main.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/app/pdump/main.c b/app/pdump/main.c index
> 04a38e8911..96fa76f8da 100644
> --- a/app/pdump/main.c
> +++ b/app/pdump/main.c
> @@ -900,11 +900,21 @@ dump_packets_core(void *arg)
>  	return 0;
>  }
> 
> +static unsigned int
> +get_next_core(unsigned int lcore)
> +{
> +	lcore = rte_get_next_lcore(lcore, 1, 0);
> +	if (lcore == RTE_MAX_LCORE)
> +		rte_exit(EXIT_FAILURE,
> +				"Max core limit %u reached for packet capture",
> lcore);
> +	return lcore;
> +}
> +
>  static inline void
>  dump_packets(void)
>  {
>  	int i;
> -	uint32_t lcore_id = 0;
> +	unsigned int lcore_id = 0;
> 
>  	if (!multiple_core_capture) {
>  		printf(" core (%u), capture for (%d) tuples\n", @@ -930,12
> +940,12 @@ dump_packets(void)
>  		return;
>  	}
> 
> -	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
> +	lcore_id = 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);
> +		lcore_id = get_next_core(lcore_id);
> 
>  		if (rte_eal_wait_lcore(lcore_id) < 0)
>  			rte_exit(EXIT_FAILURE, "failed to wait\n");
> --
> 2.25.1
Thomas Monjalon March 8, 2022, 2:27 p.m. UTC | #3
08/03/2022 14:47, Mcnamara, John:
> Thomas, could you include this in RC3 if possible.

I did already yesterday:
	https://git.dpdk.org/dpdk/commit/?id=3ee04ebc91

Looks like I forgot to send an email.

Applied, thanks :)
John McNamara March 8, 2022, 3:03 p.m. UTC | #4
> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Subject: Re: [PATCH v4] app/pdump: check lcore is not the maximum core
> 
> 08/03/2022 14:47, Mcnamara, John:
> > Thomas, could you include this in RC3 if possible.
> 
> I did already yesterday:
> 	https://git.dpdk.org/dpdk/commit/?id=3ee04ebc91
> 
> Looks like I forgot to send an email.
> 
> Applied, thanks :)

Thank you. :-)
diff mbox series

Patch

diff --git a/app/pdump/main.c b/app/pdump/main.c
index 04a38e8911..96fa76f8da 100644
--- a/app/pdump/main.c
+++ b/app/pdump/main.c
@@ -900,11 +900,21 @@  dump_packets_core(void *arg)
 	return 0;
 }
 
+static unsigned int
+get_next_core(unsigned int lcore)
+{
+	lcore = rte_get_next_lcore(lcore, 1, 0);
+	if (lcore == RTE_MAX_LCORE)
+		rte_exit(EXIT_FAILURE,
+				"Max core limit %u reached for packet capture", lcore);
+	return lcore;
+}
+
 static inline void
 dump_packets(void)
 {
 	int i;
-	uint32_t lcore_id = 0;
+	unsigned int lcore_id = 0;
 
 	if (!multiple_core_capture) {
 		printf(" core (%u), capture for (%d) tuples\n",
@@ -930,12 +940,12 @@  dump_packets(void)
 		return;
 	}
 
-	lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
+	lcore_id = 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);
+		lcore_id = get_next_core(lcore_id);
 
 		if (rte_eal_wait_lcore(lcore_id) < 0)
 			rte_exit(EXIT_FAILURE, "failed to wait\n");