From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Vladimir Zapolskiy <vzapolskiy@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Evgeniy Polyakov <zbr@ioremap.net>,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] proc_fork_connector: a lockless ->real_parent usage is not safe
Date: Thu, 21 Jul 2011 20:35:11 +0200 [thread overview]
Message-ID: <20110721183511.GB3643@redhat.com> (raw)
In-Reply-To: <20110721183446.GA3643@redhat.com>
proc_fork_connector() uses ->real_parent lockless. This is not safe
if copy_process() was called with CLONE_THREAD or CLONE_PARENT, in
this case the parent != current can go away at any moment.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
drivers/connector/cn_proc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
--- ts/drivers/connector/cn_proc.c~proc_fork_connector_parent 2011-04-06 21:33:43.000000000 +0200
+++ ts/drivers/connector/cn_proc.c 2011-07-21 20:24:09.000000000 +0200
@@ -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;
prev parent reply other threads:[~2011-07-21 18:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1310751918-31579-1-git-send-email-vzapolskiy@gmail.com>
[not found] ` <20110718161558.GA366@ioremap.net>
[not found] ` <20110718171420.GA11470@redhat.com>
2011-07-21 18:34 ` [PATCH 0/1] (Was: connector: add an event for monitoring process tracers) Oleg Nesterov
2011-07-21 18:35 ` Oleg Nesterov [this message]
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=20110721183511.GB3643@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=linux-kernel@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