app/pdump: check lcore is not the maximum core
PATCH 1/1 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
--- app/pdump/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)
app/pdump/main.c +8 -0
@@ -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" );
Signature · 1 line
2.25.1
app/pdump/main.c dump_packets(void) · line 937
Quoted 5 lines · On Fri, 18 Feb 2022 15:18:41 +0000 Reshma Pattan <[email protected]>…
app/pdump/main.c +4
-0lcore_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 v2 1/1 app/pdump: check lcore is not the maximum core
In reply to Reshma PattanCheck 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
--- app/pdump/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
app/pdump/main.c +5 -2
@@ -930,12 +930,15 @@ dump_packets(void)return ; } - lcore_id =rte_get_next_lcore (lcore_id,1 ,0 );for (i =0 ; i < num_tuples; i++) { + 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); +rte_eal_remote_launch (dump_packets_core, &pdump_t[i], lcore_id); - lcore_id =rte_get_next_lcore (lcore_id,1 ,0 );if (rte_eal_wait_lcore (lcore_id) <0 )rte_exit (EXIT_FAILURE ,"failed to wait\n" );
Signature · 1 line
2.27.0
PATCH v3 1/1 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
---
v3: add new function to get next core id and validate it.
--- app/pdump/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
app/pdump/main.c +11 -2
@@ -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" );
Signature · 1 line
2.25.1
Quoted 4 lines
-----Original Message-----
From: Pattan, Reshma <[email protected]>
<snip>
Hi Stephen,
Can you take a look and ack the patch.
Thanks,
Reshma
Quoted 23 lines · On Tue, 22 Feb 2022 11:02:24 +0000 Reshma Pattan <[email protected]>…
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")Signed-off-by Reshma Pattan <[email protected]>---
v3: add new function to get next core id and validate it.--- app/pdump/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)app/pdump/main.c +0
-0@@ -900,6 +900,15 @@ dump_packets_core(void *arg)return 0 ; }
app/pdump/main.c dump_packets_core(void *arg) · line 911
Quoted 10 lines
app/pdump/main.c +9
-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 intget_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;
}Quoted 18 lines
app/pdump/main.c +2
-2static 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 v4 1/1 app/pdump: check lcore is not the maximum core
In reply to Reshma PattanCheck 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
---
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(-)
app/pdump/main.c +13 -3
@@ -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" );
Signature · 1 line
2.25.1
Quoted 10 lines · On Mon, 28 Feb 2022 09:58:56 +0000 Reshma Pattan <[email protected]>…
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")Signed-off-by Reshma Pattan <[email protected]>
Great thanks.
Thomas, could you include this in RC3 if possible.
Quoted 72 lines
-----Original Message-----
From: Reshma Pattan <[email protected]>
Sent: Monday, February 28, 2022 9:59 AM
To: [email protected]
Cc: [email protected]; Yigit, Ferruh <[email protected]>; Pattan, Reshma <[email protected]>; [email protected]; [email protected]
Subject: [PATCH v4] app/pdump: check lcore is not the maximum coreCheck 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")Signed-off-by Reshma Pattan <[email protected]>---
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(-)app/pdump/main.c index renamed from app/pdump/main.c +0
-0
04a38e8911..96fa76f8da100644app/pdump/main.c +11
-1@@ -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) {app/pdump/main.c +3
-3printf(" 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
Applied08/03/2022 14:47, Mcnamara, John:
Quoted 1 line
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 :)
Quoted 6 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Subject: Re: [PATCH v4] app/pdump: check lcore is not the maximum core08/03/2022 14:47, Mcnamara, John:
Quoted 8 lines
Quoted 1 line
Thomas, could you include this in RC3 if possible.
I did already yesterday:
https://git.dpdk.org/dpdk/commit/?id=3ee04ebc91Looks like I forgot to send an email.
Applied, thanks :)
Thank you. :-)