procd: Do not leak pipe file descriptors to children
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 6 Jul 2017 20:25:16 +0000 (22:25 +0200)
committerJohn Crispin <john@phrozen.org>
Mon, 31 Jul 2017 17:00:34 +0000 (19:00 +0200)
Without this change, a process started by procd can have access to
stdout/err of processes started by procd before.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
rcS.c
service/instance.c

diff --git a/rcS.c b/rcS.c
index 4ecf0c10d7da1392c905717c2f15906ea6f5fe6e..b1202bf96613d19ee076ee700ad234e6cfcc9db6 100644 (file)
--- a/rcS.c
+++ b/rcS.c
@@ -82,6 +82,7 @@ static void q_initd_run(struct runqueue *q, struct runqueue_task *t)
 
        if (pid) {
                close(pipefd[1]);
+               fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
                s->fd.stream.string_data = true,
                s->fd.stream.notify_read = pipe_cb,
                runqueue_process_add(q, &s->proc, pid);
index 4d340fd2da37b29dcfe23f9a21d0111cb22ea8e3..a968a0b4bc60cb1773c2a66653a82113994e2701 100644 (file)
@@ -444,11 +444,13 @@ instance_start(struct service_instance *in)
        if (opipe[0] > -1) {
                ustream_fd_init(&in->_stdout, opipe[0]);
                closefd(opipe[1]);
+               fcntl(opipe[0], F_SETFD, FD_CLOEXEC);
        }
 
        if (epipe[0] > -1) {
                ustream_fd_init(&in->_stderr, epipe[0]);
                closefd(epipe[1]);
+               fcntl(epipe[0], F_SETFD, FD_CLOEXEC);
        }
 
        service_event("instance.start", in->srv->name, in->name);