Skip to content

Commit 79e42c5

Browse files
committed
firewall3: fix process termination in child processes
When execv() or execl() fail in child processes, the child would continue executing parent code instead of properly terminating. This could lead to unexpected behavior with multiple firewall3 processes running. Add proper error handling and _exit(EXIT_FAILURE) calls after failed exec operations in __fw3_command_pipe() and fw3_hotplug() to ensure child processes terminate immediately on exec failure. Signed-off-by: Stacy Corcoran <stacy.corcoran@verkada.com>
1 parent 3a65fde commit 79e42c5

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

utils.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ __fw3_command_pipe(bool silent, const char *command, ...)
271271

272272
execv(command, args);
273273

274+
/* Only reach on execv failure - must exit to prevent child continuing */
275+
warn("Unable to execute %s: %s", command, strerror(errno));
276+
_exit(1);
277+
274278
default:
275279
signal(SIGPIPE, SIG_IGN);
276280
pipe_pid = pid;
@@ -771,7 +775,7 @@ fw3_hotplug(bool add, void *zone, void *device)
771775
switch (fork())
772776
{
773777
case -1:
774-
warn("Unable to fork(): %s\n", strerror(errno));
778+
warn("Unable to fork(): %s", strerror(errno));
775779
return false;
776780

777781
case 0:
@@ -783,7 +787,6 @@ fw3_hotplug(bool add, void *zone, void *device)
783787

784788
close(0);
785789
close(1);
786-
close(2);
787790
if (chdir("/")) {};
788791

789792
clearenv();
@@ -794,8 +797,9 @@ fw3_hotplug(bool add, void *zone, void *device)
794797

795798
execl(FW3_HOTPLUG, FW3_HOTPLUG, "firewall", NULL);
796799

797-
/* unreached */
798-
return false;
800+
/* Only reach on execl() failure - must exit to prevent child continuing */
801+
warn("Unable to execute %s command: %s", FW3_HOTPLUG, strerror(errno));
802+
_exit(1);
799803
}
800804

801805
int

0 commit comments

Comments
 (0)