Re: [PATCH 1/2] pid: add pidfd_open()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Christian Brauner <christian@xxxxxxxxxx>
- Subject: Re: [PATCH 1/2] pid: add pidfd_open()
- From: Oleg Nesterov <oleg@xxxxxxxxxx>
- Date: Wed, 15 May 2019 17:19:13 +0200
- Cc: jannh@xxxxxxxxxx, viro@xxxxxxxxxxxxxxxxxx, torvalds@xxxxxxxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, arnd@xxxxxxxx, dhowells@xxxxxxxxxx, akpm@xxxxxxxxxxxxxxxxxxxx, cyphar@xxxxxxxxxx, ebiederm@xxxxxxxxxxxx, elena.reshetova@xxxxxxxxx, keescook@xxxxxxxxxxxx, luto@xxxxxxxxxxxxxx, luto@xxxxxxxxxx, tglx@xxxxxxxxxxxxx, linux-alpha@xxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-ia64@xxxxxxxxxxxxxxx, linux-m68k@xxxxxxxxxxxxxxx, linux-mips@xxxxxxxxxxxxxxx, linux-parisc@xxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, linux-s390@xxxxxxxxxxxxxxx, linux-sh@xxxxxxxxxxxxxxx, sparclinux@xxxxxxxxxxxxxxx, linux-xtensa@xxxxxxxxxxxxxxxx, linux-api@xxxxxxxxxxxxxxx, linux-arch@xxxxxxxxxxxxxxx, linux-kselftest@xxxxxxxxxxxxxxx
- In-reply-to: <20190515144927.f2yxyi6w6lhn3xx7@brauner.io>
- References: <20190515100400.3450-1-christian@brauner.io> <20190515143857.GB18892@redhat.com> <20190515144927.f2yxyi6w6lhn3xx7@brauner.io>
- User-agent: Mutt/1.5.24 (2015-08-30)
On 05/15, Christian Brauner wrote:
>
> On Wed, May 15, 2019 at 04:38:58PM +0200, Oleg Nesterov wrote:
> >
> > it seems that you can do a single check
> >
> > tsk = pid_task(p, PIDTYPE_TGID);
> > if (!tsk)
> > ret = -ESRCH;
> >
> > this even looks more correct if we race with exec changing the leader.
>
> The logic here being that you can only reach the thread_group leader
> from struct pid if PIDTYPE_PID == PIDTYPE_TGID for this struct pid?
Not exactly... it is not that PIDTYPE_PID == PIDTYPE_TGID for this pid,
struct pid has no "type" or something like this.
The logic is that pid->tasks[PIDTYPE_XXX] is the list of task which use
this pid as "XXX" type.
For example, clone(CLONE_THREAD) creates a pid which has a single non-
empty list, pid->tasks[PIDTYPE_PID]. This pid can't be used as TGID or
SID.
So if pid_task(PIDTYPE_TGID) returns non-NULL we know that this pid was
used for a group-leader, see copy_process() which does
if (thread_group_leader(p))
attach_pid(p, PIDTYPE_TGID);
If we race with exec which changes the leader pid_task(TGID) can return
the old leader. We do not care, but this means that we should not check
thread_group_leader().
Oleg.
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]