From: Oleg Nesterov <oleg@redhat.com>
To: Evgeniy Polyakov <zbr@ioremap.net>
Cc: Vladimir Zapolskiy <vzapolskiy@gmail.com>,
netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH v2] connector: add an event for monitoring process tracers
Date: Mon, 18 Jul 2011 19:14:20 +0200 [thread overview]
Message-ID: <20110718171420.GA11470@redhat.com> (raw)
In-Reply-To: <20110718161558.GA366@ioremap.net>
On 07/18, Evgeniy Polyakov wrote:
>
> Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
OK, thanks, I am going to apply it then...
While we are here, a couple of questions. I've looked at connector
briefly, and some things do not look exactly right to me.
proc_fork_connector() reads task->real_parent lockless. In theory
this is not safe with CLONE_PTHREAD or CLONE_PARENT. Yes, this is
only theoretical, but afaics we need something like
--- x/drivers/connector/cn_proc.c
+++ x/drivers/connector/cn_proc.c
@@ -55,6 +55,7 @@ void proc_fork_connector(struct task_str
struct proc_event *ev;
__u8 buffer[CN_PROC_MSG_SIZE];
struct timespec ts;
+ struct task_struct *parent;
if (atomic_read(&proc_event_num_listeners) < 1)
return;
@@ -65,8 +66,11 @@ void proc_fork_connector(struct task_str
ktime_get_ts(&ts); /* get high res monotonic timestamp */
put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns);
ev->what = PROC_EVENT_FORK;
- ev->event_data.fork.parent_pid = task->real_parent->pid;
- ev->event_data.fork.parent_tgid = task->real_parent->tgid;
+ rcu_read_lock();
+ parent = rcu_dereference(task->real_parent);
+ ev->event_data.fork.parent_pid = parent->pid;
+ ev->event_data.fork.parent_tgid = parent->tgid;
+ rcu_read_unlock();
ev->event_data.fork.child_pid = task->pid;
ev->event_data.fork.child_tgid = task->tgid;
Otherwise ->real_parent can point to the freed/reused and may be
unmapped memory.
But the actual question is, the usage of proc_exec_connector()
looks "obviously wrong", no? Don't we need
--- x/fs/exec.c
+++ x/fs/exec.c
@@ -1380,15 +1380,16 @@ int search_binary_handler(struct linux_b
*/
bprm->recursion_depth = depth;
if (retval >= 0) {
- if (depth == 0)
+ if (depth == 0) {
tracehook_report_exec(fmt, bprm, regs);
+ proc_exec_connector(current);
+ }
put_binfmt(fmt);
allow_write_access(bprm->file);
if (bprm->file)
fput(bprm->file);
bprm->file = NULL;
current->did_exec = 1;
- proc_exec_connector(current);
return retval;
}
read_lock(&binfmt_lock);
? Or do we really want to call proc_exec_connector() twice or
more in "#!whatever" case?
Oleg.
next prev parent reply other threads:[~2011-07-18 17:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-15 17:45 [PATCH v2] connector: add an event for monitoring process tracers Vladimir Zapolskiy
2011-07-18 16:15 ` Evgeniy Polyakov
2011-07-18 17:14 ` Oleg Nesterov [this message]
2011-07-18 17:54 ` Oleg Nesterov
2011-07-18 18:57 ` Vladimir Zapolskiy
2011-07-18 19:39 ` Oleg Nesterov
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=20110718171420.GA11470@redhat.com \
--to=oleg@redhat.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=vzapolskiy@gmail.com \
--cc=zbr@ioremap.net \
/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;
as well as URLs for NNTP newsgroup(s).