linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing: fix the "old_pid" usage in trace_sched_process_exec()
@ 2012-03-30 16:26 Oleg Nesterov
  2012-03-30 16:29 ` Oleg Nesterov
  2012-03-31 17:20 ` [tip:perf/urgent] tracing, sched, vfs: Fix 'old_pid' " tip-bot for Oleg Nesterov
  0 siblings, 2 replies; 4+ messages in thread
From: Oleg Nesterov @ 2012-03-30 16:26 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: David Smith, Peter Zijlstra, Steven Rostedt, Denys Vlasenko,
	linux-kernel

1. TRACE_EVENT(sched_process_exec) forgets to actually use the
   old pid argument, it sets ->old_pid = p->pid.

2. search_binary_handler() uses the wrong pid number. tracepoint
   needs the global pid_t from the root namespace, while old_pid
   is the virtual pid number as it seen by the tracer/parent.

With this patch we have two pid_t's in search_binary_handler(),
not really nice. Perhaps we should switch to "struct pid*", but
in this case it would be better to cleanup the current code first
and move the "depth == 0" code outside.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 fs/exec.c                    |    7 ++++---
 include/trace/events/sched.h |    2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index e48c66e..91db3e8 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1372,7 +1372,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
 	unsigned int depth = bprm->recursion_depth;
 	int try,retval;
 	struct linux_binfmt *fmt;
-	pid_t old_pid;
+	pid_t old_pid, old_vpid;
 
 	retval = security_bprm_check(bprm);
 	if (retval)
@@ -1383,8 +1383,9 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
 		return retval;
 
 	/* Need to fetch pid before load_binary changes it */
+	old_pid = current->pid;
 	rcu_read_lock();
-	old_pid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
+	old_vpid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
 	rcu_read_unlock();
 
 	retval = -ENOENT;
@@ -1407,7 +1408,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
 			if (retval >= 0) {
 				if (depth == 0) {
 					trace_sched_process_exec(current, old_pid, bprm);
-					ptrace_event(PTRACE_EVENT_EXEC, old_pid);
+					ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
 				}
 				put_binfmt(fmt);
 				allow_write_access(bprm->file);
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index e61ddfe..2f10e81 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -295,7 +295,7 @@ TRACE_EVENT(sched_process_exec,
 	TP_fast_assign(
 		__assign_str(filename, bprm->filename);
 		__entry->pid		= p->pid;
-		__entry->old_pid	= p->pid;
+		__entry->old_pid	= old_pid;
 	),
 
 	TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
-- 
1.5.5.1



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

* Re: [PATCH] tracing: fix the "old_pid" usage in trace_sched_process_exec()
  2012-03-30 16:26 [PATCH] tracing: fix the "old_pid" usage in trace_sched_process_exec() Oleg Nesterov
@ 2012-03-30 16:29 ` Oleg Nesterov
  2012-03-31  9:52   ` Ingo Molnar
  2012-03-31 17:20 ` [tip:perf/urgent] tracing, sched, vfs: Fix 'old_pid' " tip-bot for Oleg Nesterov
  1 sibling, 1 reply; 4+ messages in thread
From: Oleg Nesterov @ 2012-03-30 16:29 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: David Smith, Peter Zijlstra, Steven Rostedt, Denys Vlasenko,
	linux-kernel

On 03/30, Oleg Nesterov wrote:
>
> 1. TRACE_EVENT(sched_process_exec) forgets to actually use the
>    old pid argument, it sets ->old_pid = p->pid.
>
> 2. search_binary_handler() uses the wrong pid number. tracepoint
>    needs the global pid_t from the root namespace, while old_pid
>    is the virtual pid number as it seen by the tracer/parent.

Not really serious, but probably makes sense for 3.4. This fixes
the recently merged 4ff16c25e2cc48cbe6956e356c38a25ac063a64d
"tracepoint, vfs, sched: Add exec() tracepoint"

Oleg.


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

* Re: [PATCH] tracing: fix the "old_pid" usage in trace_sched_process_exec()
  2012-03-30 16:29 ` Oleg Nesterov
@ 2012-03-31  9:52   ` Ingo Molnar
  0 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2012-03-31  9:52 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Ingo Molnar, David Smith, Peter Zijlstra, Steven Rostedt,
	Denys Vlasenko, linux-kernel


* Oleg Nesterov <oleg@redhat.com> wrote:

> On 03/30, Oleg Nesterov wrote:
> >
> > 1. TRACE_EVENT(sched_process_exec) forgets to actually use the
> >    old pid argument, it sets ->old_pid = p->pid.
> >
> > 2. search_binary_handler() uses the wrong pid number. tracepoint
> >    needs the global pid_t from the root namespace, while old_pid
> >    is the virtual pid number as it seen by the tracer/parent.
> 
> Not really serious, but probably makes sense for 3.4. This fixes
> the recently merged 4ff16c25e2cc48cbe6956e356c38a25ac063a64d
> "tracepoint, vfs, sched: Add exec() tracepoint"

Thanks Oleg - will queue your fix up in tip:perf/urgent.

Thanks,

	Ingo

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

* [tip:perf/urgent] tracing, sched, vfs: Fix 'old_pid' usage in trace_sched_process_exec()
  2012-03-30 16:26 [PATCH] tracing: fix the "old_pid" usage in trace_sched_process_exec() Oleg Nesterov
  2012-03-30 16:29 ` Oleg Nesterov
@ 2012-03-31 17:20 ` tip-bot for Oleg Nesterov
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Oleg Nesterov @ 2012-03-31 17:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, rostedt, dvlasenk, tglx,
	oleg, dsmith

Commit-ID:  6308191f6f55d3629c7dbe72dfb856ad9fa560fd
Gitweb:     http://git.kernel.org/tip/6308191f6f55d3629c7dbe72dfb856ad9fa560fd
Author:     Oleg Nesterov <oleg@redhat.com>
AuthorDate: Fri, 30 Mar 2012 18:26:36 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 31 Mar 2012 11:53:22 +0200

tracing, sched, vfs: Fix 'old_pid' usage in trace_sched_process_exec()

1. TRACE_EVENT(sched_process_exec) forgets to actually use the
   old pid argument, it sets ->old_pid = p->pid.

2. search_binary_handler() uses the wrong pid number. tracepoint
   needs the global pid_t from the root namespace, while old_pid
   is the virtual pid number as it seen by the tracer/parent.

With this patch we have two pid_t's in search_binary_handler(),
not really nice. Perhaps we should switch to "struct pid*", but
in this case it would be better to cleanup the current code
first and move the "depth == 0" code outside.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: David Smith <dsmith@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Link: http://lkml.kernel.org/r/20120330162636.GA4857@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 fs/exec.c                    |    7 ++++---
 include/trace/events/sched.h |    2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 23559c2..644f6c4 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1370,7 +1370,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
 	unsigned int depth = bprm->recursion_depth;
 	int try,retval;
 	struct linux_binfmt *fmt;
-	pid_t old_pid;
+	pid_t old_pid, old_vpid;
 
 	retval = security_bprm_check(bprm);
 	if (retval)
@@ -1381,8 +1381,9 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
 		return retval;
 
 	/* Need to fetch pid before load_binary changes it */
+	old_pid = current->pid;
 	rcu_read_lock();
-	old_pid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
+	old_vpid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
 	rcu_read_unlock();
 
 	retval = -ENOENT;
@@ -1405,7 +1406,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
 			if (retval >= 0) {
 				if (depth == 0) {
 					trace_sched_process_exec(current, old_pid, bprm);
-					ptrace_event(PTRACE_EVENT_EXEC, old_pid);
+					ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
 				}
 				put_binfmt(fmt);
 				allow_write_access(bprm->file);
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index fbc7b1a..ea7a203 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -295,7 +295,7 @@ TRACE_EVENT(sched_process_exec,
 	TP_fast_assign(
 		__assign_str(filename, bprm->filename);
 		__entry->pid		= p->pid;
-		__entry->old_pid	= p->pid;
+		__entry->old_pid	= old_pid;
 	),
 
 	TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),

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

end of thread, other threads:[~2012-03-31 17:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-30 16:26 [PATCH] tracing: fix the "old_pid" usage in trace_sched_process_exec() Oleg Nesterov
2012-03-30 16:29 ` Oleg Nesterov
2012-03-31  9:52   ` Ingo Molnar
2012-03-31 17:20 ` [tip:perf/urgent] tracing, sched, vfs: Fix 'old_pid' " tip-bot for Oleg Nesterov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).