Re: task_is_descendant() cleanup

From: Kees Cook
Date: Wed Jan 25 2017 - 17:00:09 EST


On Mon, Jan 23, 2017 at 4:52 AM, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> On 01/23, Oleg Nesterov wrote:
>>
>> Btw task_is_descendant() looks wrong at first glance.
>
> No, I missed the 2nd ->group_leader dereference. Still this function looks
> overcomplicated and the usage of thread_group_leader/group_leader just add
> the unnecessary confusion. It can be simplified a little bit:
>
> static int task_is_descendant(struct task_struct *parent,
> struct task_struct *child)
> {
> int rc = 0;
> struct task_struct *walker;
>
> if (!parent || !child)
> return 0;
>
> rcu_read_lock();
> for (walker = child; walker->pid; walker = rcu_dereference(walker->real_parent))
> if (same_thread_group(parent, walker)) {
> rc = 1;
> break;
> }
> rcu_read_unlock();
>
> return rc;
> }
>
> Kees, I can send a patch if you think this very minor cleanup makes any sense.

Err, isn't checking same_thread_group() at every level more expensive
than what I currently have?

-Kees

--
Kees Cook
Nexus Security