Linux Netfilter development
 help / color / mirror / Atom feed
* [PATCH] conntrackd: Fix signal handler race-condition
@ 2024-04-04 10:39 bre Breitenberger Markus
  2024-05-02  8:30 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: bre Breitenberger Markus @ 2024-04-04 10:39 UTC (permalink / raw)
  To: netfilter-devel@vger.kernel.org

Install signal handlers after everything is initialized as there is a
race condition that can happen when the process gets terminated after
the signal handler is installed but before all fields in the global
state are set up correctly, leading to a SIGSEGV as the cleanup code
dereferences uninitialized pointers.

Signed-Off-By: Markus Breitenberger <bre@keba.com>
---
 src/run.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/run.c b/src/run.c
index 37a0eb1..b31fff5 100644
--- a/src/run.c
+++ b/src/run.c
@@ -277,6 +277,18 @@ init(void)
 	}
 	register_fd(STATE(local).fd, local_cb, NULL, STATE(fds));
 
+	/* Initialization */
+	if (CONFIG(flags) & (CTD_SYNC_MODE | CTD_STATS_MODE))
+		if (ctnl_init() < 0)
+			return -1;
+
+#ifdef BUILD_CTHELPER
+	if (CONFIG(flags) & CTD_HELPER) {
+		if (cthelper_init() < 0)
+			return -1;
+	}
+#endif
+
 	/* Signals handling */
 	sigemptyset(&STATE(block));
 	sigaddset(&STATE(block), SIGTERM);
@@ -296,17 +308,6 @@ init(void)
 	if (signal(SIGCHLD, child) == SIG_ERR)
 		return -1;
 
-	/* Initialization */
-	if (CONFIG(flags) & (CTD_SYNC_MODE | CTD_STATS_MODE))
-		if (ctnl_init() < 0)
-			return -1;
-
-#ifdef BUILD_CTHELPER
-	if (CONFIG(flags) & CTD_HELPER) {
-		if (cthelper_init() < 0)
-			return -1;
-	}
-#endif
 	time(&STATE(stats).daemon_start_time);
 
 	dlog(LOG_NOTICE, "initialization completed");
-- 
2.43.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] conntrackd: Fix signal handler race-condition
  2024-04-04 10:39 [PATCH] conntrackd: Fix signal handler race-condition bre Breitenberger Markus
@ 2024-05-02  8:30 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2024-05-02  8:30 UTC (permalink / raw)
  To: bre Breitenberger Markus; +Cc: netfilter-devel@vger.kernel.org

On Thu, Apr 04, 2024 at 10:39:39AM +0000, bre Breitenberger Markus wrote:
> Install signal handlers after everything is initialized as there is a
> race condition that can happen when the process gets terminated after
> the signal handler is installed but before all fields in the global
> state are set up correctly, leading to a SIGSEGV as the cleanup code
> dereferences uninitialized pointers.

Applied, thanks

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-02  8:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-04 10:39 [PATCH] conntrackd: Fix signal handler race-condition bre Breitenberger Markus
2024-05-02  8:30 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox