lkml.org 
[lkml]   [2013]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 03/12] pid: get ppid pid_t of task in init_pid_ns safely
On 08/20, Richard Guy Briggs wrote:
>
> Added the functions
> task_ppid()
> task_ppid_nr_ns()
> task_ppid_nr_init_ns()
> to safely abstract the lookup of the PPID

but it is not safe.

> +static inline struct pid *task_ppid(struct task_struct *task)
> +{
> + return task_tgid(rcu_dereference(current->real_parent));
^^^^^^^
task?

> +static inline pid_t task_ppid_nr_ns(struct task_struct *tsk,
> + struct pid_namespace *ns)
> +{
> + pid_t pid;
> +
> + rcu_read_lock();
> + pid = pid_nr_ns(task_ppid(current), ns);
^^^^^^^
again.

> + rcu_read_unlock();

And why this is safe?

rcu_read_lock() can't help if tsk was already dead _before_ it takes
the rcu lock. ->real_parent can point the already freed/reused/unmapped
memory.

This is safe if, for example, the caller alredy holds rcu_read_lock()
and tsk was found by find_task_by*(), or tsk is current.

Richard, just in case... I am going to vacation, I will be completely
offline till Sep 10.

Oleg.



\
 
 \ /
  Last update: 2013-08-27 19:41    [W:0.220 / U:0.144 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site