* [PATCH 0/1] (Was: connector: add an event for monitoring process tracers)
[not found] ` <20110718171420.GA11470@redhat.com>
@ 2011-07-21 18:34 ` Oleg Nesterov
2011-07-21 18:35 ` [PATCH 1/1] proc_fork_connector: a lockless ->real_parent usage is not safe Oleg Nesterov
0 siblings, 1 reply; 2+ messages in thread
From: Oleg Nesterov @ 2011-07-21 18:34 UTC (permalink / raw)
To: Andrew Morton
Cc: Vladimir Zapolskiy, David S. Miller, Evgeniy Polyakov,
linux-kernel
On 07/18, Oleg Nesterov wrote:
>
> 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.
Looks like, nobody cares ;) I am sending the patch.
> 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?
I think this should be fixed too, I'll send the patch later.
Oleg.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 1/1] proc_fork_connector: a lockless ->real_parent usage is not safe
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
0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2011-07-21 18:35 UTC (permalink / raw)
To: Andrew Morton
Cc: Vladimir Zapolskiy, David S. Miller, Evgeniy Polyakov,
linux-kernel
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;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-07-21 18:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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 ` [PATCH 1/1] proc_fork_connector: a lockless ->real_parent usage is not safe Oleg Nesterov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox