diff mbox series

[6/6] spawn_process: use CLOEXEC for child communication fd

Message ID 20220527044700.3666830-7-dominique.martinet@atmark-techno.com
State Rejected
Delegated to: Stefano Babic
Headers show
Series Avoid leaking fd to child processes: use CLOEXEC | expand

Commit Message

Dominique Martinet May 27, 2022, 4:47 a.m. UTC
This fd leaks to subprocesses when using e.g. downloader mode

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
 core/pctl.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/core/pctl.c b/core/pctl.c
index 1c6e556d8721..89ebb452de04 100644
--- a/core/pctl.c
+++ b/core/pctl.c
@@ -10,6 +10,7 @@ 
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <fcntl.h>
 #include <sys/select.h>
 #if defined(__linux__)
 #include <sys/prctl.h>
@@ -147,6 +148,7 @@  static int spawn_process(struct swupdate_task *task,
 	if (process_id) {
 		/* Parent close the [1] */
 		close(sockfd[1]);
+		fcntl(sockfd[0], F_SETFD, FD_CLOEXEC);
 		task->pid = process_id;
 		task->pipe = sockfd[0];
 		return 0;
@@ -154,6 +156,7 @@  static int spawn_process(struct swupdate_task *task,
 
 	/* Child closes [0] */
 	close(sockfd[0]);
+	fcntl(sockfd[1], F_SETFD, FD_CLOEXEC);
 
 	sw_sockfd = sockfd[1];