mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nathan Lynch <ntl@pobox.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [trace-cmd patch] close open fds on exec
Date: Fri, 20 May 2011 13:22:09 -0500	[thread overview]
Message-ID: <1305915732.2429.4.camel@orca.stoopid.dyndns.org> (raw)

trace-cmd's record mode allows child processes to inherit
tracing-related file descriptors:

$ trace-cmd record -esched: ls -l /proc/self/fd

total 0
lrwx------. 1 root root 64 May 20 12:44 0 -> /dev/pts/11
lrwx------. 1 root root 64 May 20 12:44 1 -> /dev/pts/11
lrwx------. 1 root root 64 May 20 12:44 2 -> /dev/pts/11
lrwx------. 1 root root 64 May 20 12:44 3 -> /sys/kernel/debug/tracing/tracing_on
l-wx------. 1 root root 64 May 20 12:44 4 -> /sys/kernel/debug/tracing/set_ftrace_pid
l-wx------. 1 root root 64 May 20 12:44 5 -> /sys/kernel/debug/tracing/tracing_enabled
lr-x------. 1 root root 64 May 20 12:44 6 -> /proc/31036/fd

This can be problematic for applications (such as lxc) that
interrogate their open file descriptors.

Open these with O_CLOEXEC so they are not inherited.

Signed-off-by: Nathan Lynch <ntl@pobox.com>
---
 trace-record.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/trace-record.c b/trace-record.c
index fa23b82..c4a51d7 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -343,7 +343,7 @@ static void update_ftrace_pid(const char *pid, int reset)
 			path = tracecmd_get_tracing_file("set_ftrace_pid");
 		if (!path)
 			return;
-		fd = open(path, O_WRONLY | (reset ? O_TRUNC : 0));
+		fd = open(path, O_WRONLY | O_CLOEXEC | (reset ? O_TRUNC : 0));
 		if (fd < 0)
 			return;
 	}
@@ -795,7 +795,7 @@ static void check_tracing_enabled(void)
 
 	if (fd < 0) {
 		path = tracecmd_get_tracing_file("tracing_enabled");
-		fd = open(path, O_WRONLY);
+		fd = open(path, O_WRONLY | O_CLOEXEC);
 		tracecmd_put_tracing_file(path);
 
 		if (fd < 0)
@@ -815,7 +815,7 @@ static int open_tracing_on(void)
 		return fd;
 
 	path = tracecmd_get_tracing_file("tracing_on");
-	fd = open(path, O_RDWR);
+	fd = open(path, O_RDWR | O_CLOEXEC);
 	if (fd < 0)
 		die("opening '%s'", path);
 	tracecmd_put_tracing_file(path);
-- 
1.7.5.1




                 reply	other threads:[~2011-05-20 18:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1305915732.2429.4.camel@orca.stoopid.dyndns.org \
    --to=ntl@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®