2014-01-23 19:34:33

by Richard Guy Briggs

[permalink] [raw]
Subject: [PATCH 5/7] pid: rewrite task helper function is_global_init() avoiding task->pid

Use the access function task_pid_nr() to get pid.

(informed by ebiederman's ea5a4d01)
Cc: "Eric W. Biederman" <[email protected]>
Signed-off-by: Richard Guy Briggs <[email protected]>
---
include/linux/sched.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index b4e658c..f60de19 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1615,7 +1615,7 @@ static inline int pid_alive(struct task_struct *p)
*/
static inline int is_global_init(struct task_struct *tsk)
{
- return tsk->pid == 1;
+ return task_pid_nr(tsk) == 1;
}

extern struct pid *cad_pid;
--
1.7.1


2014-02-20 22:21:20

by Oleg Nesterov

[permalink] [raw]
Subject: Re: [PATCH 5/7] pid: rewrite task helper function is_global_init() avoiding task->pid

On 01/23, Richard Guy Briggs wrote:
>
> static inline int is_global_init(struct task_struct *tsk)
> {
> - return tsk->pid == 1;
> + return task_pid_nr(tsk) == 1;
> }

ACK, but we need to fix it.

With or without this change is_global_init() actually means
is-the-main-thread-of-global-init.

This is not what the callers actually want. Just look at
oom_unkillable_task(). Suppose that p is the sub-thread of
/sbin/init, if we kill this thread we kill the whole process.

The same of other callers. is_global_init() should return T
if this task is the part of init's thread group.

Oleg.

2014-02-21 16:11:49

by Richard Guy Briggs

[permalink] [raw]
Subject: Re: [PATCH 5/7] pid: rewrite task helper function is_global_init() avoiding task->pid

On 14/02/20, Oleg Nesterov wrote:
> On 01/23, Richard Guy Briggs wrote:
> >
> > static inline int is_global_init(struct task_struct *tsk)
> > {
> > - return tsk->pid == 1;
> > + return task_pid_nr(tsk) == 1;
> > }
>
> ACK, but we need to fix it.
>
> With or without this change is_global_init() actually means
> is-the-main-thread-of-global-init.
>
> This is not what the callers actually want. Just look at
> oom_unkillable_task(). Suppose that p is the sub-thread of
> /sbin/init, if we kill this thread we kill the whole process.
>
> The same of other callers. is_global_init() should return T
> if this task is the part of init's thread group.

Good. Updated in my tree.

> Oleg.

- RGB

--
Richard Guy Briggs <[email protected]>
Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat
Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545