Skip to contentSkip to conversation

fix segfault seen with performance-thread example

PATCH Applied Erik Gabriel Carrillo 4 participants 9 messages Jul 15, 2019 – Jul 18, 2019

lore
Share & tools
lore
#0 lore raw

cover fix segfault seen with performance-thread example

A crash occurs in the examples/performance-thread/l3fwd-thread when it calls into rte_timer_manage() from the LThread library it utilizes. This happens because the application omitted a call to rte_timer_subsystem_init(), which leaves a pointer set to null in the timer library. This pointer is dereferenced in a check for validity of a timer data object, resulting in the segfault. This series fixes the validity check in the timer library, and adds the missing call to rte_timer_subsystem_init in the application.

Erik Gabriel Carrillo (2):
timer: fix null pointer dereference examples/performance-thread: init timer subsystem

 examples/performance-thread/l3fwd-thread/main.c | 5 +++++
 lib/librte_timer/rte_timer.c                    | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
2.6.4
#1 lore raw

PATCH 1/2 timer: fix null pointer dereference

If the timer subsystem is not initialized before rte_timer_manage (for example) is invoked, a pointer to a shared hugepage memory region will still be null and dereferenced when it is checked for validity; handle this case.

Fixes c0749f7096c7 ("timer: allow management in shared memory")
---
 lib/librte_timer/rte_timer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_timer/rte_timer.c +2 -1
index 71dffd2..bdcf05d 100644
@@ -85,7 +85,8 @@ static struct rte_timer_data default_timer_data;
 static inline int
 timer_data_valid(uint32_t id)
 {
-	return !!(rte_timer_data_arr[id].internal_flags & FL_ALLOCATED);
+	return rte_timer_data_arr &&
+		(rte_timer_data_arr[id].internal_flags & FL_ALLOCATED);
 }
 
 /* validate ID and retrieve timer data pointer, or return error value */
Signature · 1 line
2.6.4
#7 lore raw

PATCH 2/2 examples/performance-thread: init timer subsystem

In reply to Erik Gabriel Carrillo

The timer subsystem should be initialized in the l3fwd-thread app before the L-thread subsystem can be used.

Fixes d48415e1fee3 ("examples/performance-thread: add l3fwd-thread app")
---
 examples/performance-thread/l3fwd-thread/main.c | 5 +++++
 1 file changed, 5 insertions(+)
examples/performance-thread/l3fwd-thread/main.c +5 -0
index dd46895..c4065e8 100644
@@ -40,6 +40,7 @@
 #include <rte_udp.h>
 #include <rte_string_fns.h>
 #include <rte_pause.h>
+#include <rte_timer.h>
 
 #include <cmdline_parse.h>
 #include <cmdline_parse_etheraddr.h>
@@ -3497,6 +3498,10 @@ main(int argc, char **argv)
 	argc -= ret;
 	argv += ret;
 
+	ret = rte_timer_subsystem_init();
+	if (ret < 0)
+		rte_exit(EXIT_FAILURE, "Failed to initialize timer subystem\n");
+
 	/* pre-init dst MACs for all ports to 02:00:00:00:00:xx */
 	for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
 		dest_eth_addr[portid] = RTE_ETHER_LOCAL_ADMIN_ADDR +
Signature · 1 line
2.6.4
#2 lore raw

Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

In reply to Erik Gabriel Carrillo
Quoted 9 lines · On Mon, 15 Jul 2019 10:39:31 -0500 Erik Gabriel Carrillo…

If the timer subsystem is not initialized before rte_timer_manage (for example) is invoked, a pointer to a shared hugepage memory region will still be null and dereferenced when it is checked for validity; handle this case.

Fixes c0749f7096c7 ("timer: allow management in shared memory")

I have mixed feelings about this patch.
Any calls to rte_timer before rte_timer_subsystem_init is not a valid usage. Better to kill the application.

#3 lore raw

Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Hi Stephen,

Quoted 15 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, July 15, 2019 10:49 AM
To: Carrillo, Erik G <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Quoted 5 lines · On Mon, 15 Jul 2019 10:39:31 -0500 Erik Gabriel Carrillo…

If the timer subsystem is not initialized before rte_timer_manage (for example) is invoked, a pointer to a shared hugepage memory region will still be null and dereferenced when it is checked for validity; handle this case.

Quoted 8 lines
Quoted 4 lines
Fixes c0749f7096c7 ("timer: allow management in shared memory")

I have mixed feelings about this patch.
Any calls to rte_timer before rte_timer_subsystem_init is not a valid usage. Better to kill the application.

Ok, that sounds like a better approach. I'll update the patch and resubmit.

Thanks,
Erik

#4 lore raw

Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Quoted 29 lines

-----Original Message-----
From: Carrillo, Erik G
Sent: Monday, July 15, 2019 11:04 AM
To: Stephen Hemminger <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Hi Stephen,

Quoted 20 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, July 15, 2019 10:49 AM
To: Carrillo, Erik G <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Quoted 9 lines · On Mon, 15 Jul 2019 10:39:31 -0500 Erik Gabriel Carrillo…

If the timer subsystem is not initialized before rte_timer_manage (for
example) is invoked, a pointer to a shared hugepage memory region will still be null and dereferenced when it is checked for validity; handle this case.

Fixes c0749f7096c7 ("timer: allow management in shared memory")
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I have mixed feelings about this patch.
Any calls to rte_timer before rte_timer_subsystem_init is not a valid usage. Better to kill the application.

Ok, that sounds like a better approach. I'll update the patch and resubmit.

I added a call to rte_exit() in the timer_data_valid() function for the case where the library is uninitialized, but checkpatches.sh issues the following warning:

"Warning in /lib/librte_timer/rte_timer.c:
Using rte_panic/rte_exit"

According to the comments in the script, we should refrain from new additions of rte_panic() and rte_exit() in the lib subtree. In light of this, should we still proceed with this approach? It does seem like it would be useful.

Thanks,
Erik

Quoted 2 lines

Thanks,
Erik

#5 lore raw

Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Quoted 38 lines · Erik G
Quoted 29 lines

-----Original Message-----
From: Carrillo, Erik G
Sent: Monday, July 15, 2019 11:04 AM
To: Stephen Hemminger <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Hi Stephen,

Quoted 20 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, July 15, 2019 10:49 AM
To: Carrillo, Erik G <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Quoted 9 lines · On Mon, 15 Jul 2019 10:39:31 -0500 Erik Gabriel Carrillo…

If the timer subsystem is not initialized before rte_timer_manage (for
example) is invoked, a pointer to a shared hugepage memory region will still be null and dereferenced when it is checked for validity; handle this case.

Fixes c0749f7096c7 ("timer: allow management in shared memory")
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I have mixed feelings about this patch.
Any calls to rte_timer before rte_timer_subsystem_init is not a valid usage. Better to kill the application.

Ok, that sounds like a better approach. I'll update the patch and resubmit.

Quoted 7 lines

I added a call to rte_exit() in the timer_data_valid() function for the case where the library is uninitialized, but checkpatches.sh issues the following warning:

"Warning in /lib/librte_timer/rte_timer.c:
Using rte_panic/rte_exit"

According to the comments in the script, we should refrain from new additions of rte_panic() and rte_exit() in the lib subtree. In light of this, should we still proceed with this approach? It does seem like it would be useful.

I don't think we should ever put panics or exits in our library code, so I think the immediate choices are to either leave things as-is and allow app to crash for invalid use, or else catch the error and return a suitable error code to the user. I think I'd prefer the latter.

However, given that the error condition is not having the timer subsystem initialized, is there the possibility of a third option to just go and initialize before continuing in the timer_manage() function?

#6 lore raw

Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Quoted 66 lines

-----Original Message-----
From: Bruce Richardson <[email protected]>
Sent: Tuesday, July 16, 2019 3:31 AM
To: Carrillo, Erik G <[email protected]>
Cc: 'Stephen Hemminger' <[email protected]>; '[email protected]' <[email protected]>; '[email protected]' <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Quoted 27 lines · Erik G
Quoted 27 lines

-----Original Message-----
From: Carrillo, Erik G
Sent: Monday, July 15, 2019 11:04 AM
To: Stephen Hemminger <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: RE: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Hi Stephen,

Quoted 17 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, July 15, 2019 10:49 AM
To: Carrillo, Erik G <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH 1/2] timer: fix null pointer dereference

Quoted 6 lines · On Mon, 15 Jul 2019 10:39:31 -0500 Erik Gabriel Carrillo…

If the timer subsystem is not initialized before rte_timer_manage (for
example) is invoked, a pointer to a shared hugepage memory region will still be null and dereferenced when it is checked for validity; handle this case.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Fixes c0749f7096c7 ("timer: allow management in shared memory")

I have mixed feelings about this patch.
Any calls to rte_timer before rte_timer_subsystem_init is not a valid

usage.

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Better to kill the application.

Ok, that sounds like a better approach. I'll update the patch and

resubmit.

Quoted 3 lines
Quoted 1 line

I added a call to rte_exit() in the timer_data_valid() function for the case

where the library is uninitialized, but checkpatches.sh issues the following warning:

Quoted 5 lines

"Warning in /lib/librte_timer/rte_timer.c:
Using rte_panic/rte_exit"

According to the comments in the script, we should refrain from new

additions of rte_panic() and rte_exit() in the lib subtree. In light of this,
should we still proceed with this approach? It does seem like it would be useful.

Quoted 1 line
Quoted 5 lines

I don't think we should ever put panics or exits in our library code, so I think the immediate choices are to either leave things as-is and allow app to crash for invalid use, or else catch the error and return a suitable error code to the user. I think I'd prefer the latter.

In that case, I'd like to keep the current patch out for consideration. It detects the error and enables the library APIs to return an error code to the user.

Quoted 3 lines

However, given that the error condition is not having the timer subsystem initialized, is there the possibility of a third option to just go and initialize before continuing in the timer_manage() function?

It seems like this could work, but I'd like to hold off for more investigation.

Thanks,
Erik

#8 lore raw
In reply to Erik Gabriel Carrillo

15/07/2019 17:39, Erik Gabriel Carrillo:

Quoted 11 lines

A crash occurs in the examples/performance-thread/l3fwd-thread when it calls into rte_timer_manage() from the LThread library it utilizes. This happens because the application omitted a call to rte_timer_subsystem_init(), which leaves a pointer set to null in the timer library. This pointer is dereferenced in a check for validity of a timer data object, resulting in the segfault. This series fixes the validity check in the timer library, and adds the missing call to rte_timer_subsystem_init in the application.

Erik Gabriel Carrillo (2):
timer: fix null pointer dereference examples/performance-thread: init timer subsystem

Applied, thanks