From: Oleg Nesterov <oleg@redhat.com>
To: Christian Brauner <christian@brauner.io>
Cc: jannh@google.com, viro@zeniv.linux.org.uk,
torvalds@linux-foundation.org, linux-kernel@vger.kernel.org,
arnd@arndb.de, dhowells@redhat.com, akpm@linux-foundation.org,
cyphar@cyphar.com, ebiederm@xmission.com,
elena.reshetova@intel.com, keescook@chromium.org,
luto@amacapital.net, luto@kernel.org, tglx@linutronix.de,
linux-alpha@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org,
linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org,
linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-s390@vger.kernel.org, linux-sh@vger.kernel.org,
sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org,
linux-api@vger.kernel.org, linux-arch@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 1/2] pid: add pidfd_open()
Date: Wed, 15 May 2019 16:38:58 +0200 [thread overview]
Message-ID: <20190515143857.GB18892@redhat.com> (raw)
In-Reply-To: <20190515100400.3450-1-christian@brauner.io>
On 05/15, Christian Brauner wrote:
>
> +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
> +{
> + int fd, ret;
> + struct pid *p;
> + struct task_struct *tsk;
> +
> + if (flags)
> + return -EINVAL;
> +
> + if (pid <= 0)
> + return -EINVAL;
> +
> + p = find_get_pid(pid);
> + if (!p)
> + return -ESRCH;
> +
> + rcu_read_lock();
> + tsk = pid_task(p, PIDTYPE_PID);
You do not need find_get_pid() before rcu_lock and put_pid() at the end.
You can just do find_vpid() under rcu_read_lock().
> + if (!tsk)
> + ret = -ESRCH;
> + else if (unlikely(!thread_group_leader(tsk)))
> + ret = -EINVAL;
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.
Oleg.
WARNING: multiple messages have this Message-ID (diff)
From: Oleg Nesterov <oleg@redhat.com>
To: Christian Brauner <christian@brauner.io>
Cc: jannh@google.com, viro@zeniv.linux.org.uk,
torvalds@linux-foundation.org, linux-kernel@vger.kernel.org,
arnd@arndb.de, dhowells@redhat.com, akpm@linux-foundation.org,
cyphar@cyphar.com, ebiederm@xmission.com,
elena.reshetova@intel.com, keescook@chromium.org,
luto@amacapital.net, luto@kernel.org, tglx@linutronix.de,
linux-alpha@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org,
linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org,
linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-s390@vger.kernel.org, linux-sh@vger.kernel.org,
sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org,
linux-api@vger.kernel.org, linux-arch@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 1/2] pid: add pidfd_open()
Date: Wed, 15 May 2019 14:38:58 +0000 [thread overview]
Message-ID: <20190515143857.GB18892@redhat.com> (raw)
In-Reply-To: <20190515100400.3450-1-christian@brauner.io>
On 05/15, Christian Brauner wrote:
>
> +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
> +{
> + int fd, ret;
> + struct pid *p;
> + struct task_struct *tsk;
> +
> + if (flags)
> + return -EINVAL;
> +
> + if (pid <= 0)
> + return -EINVAL;
> +
> + p = find_get_pid(pid);
> + if (!p)
> + return -ESRCH;
> +
> + rcu_read_lock();
> + tsk = pid_task(p, PIDTYPE_PID);
You do not need find_get_pid() before rcu_lock and put_pid() at the end.
You can just do find_vpid() under rcu_read_lock().
> + if (!tsk)
> + ret = -ESRCH;
> + else if (unlikely(!thread_group_leader(tsk)))
> + ret = -EINVAL;
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.
Oleg.
WARNING: multiple messages have this Message-ID (diff)
From: oleg at redhat.com (Oleg Nesterov)
Subject: [PATCH 1/2] pid: add pidfd_open()
Date: Wed, 15 May 2019 16:38:58 +0200 [thread overview]
Message-ID: <20190515143857.GB18892@redhat.com> (raw)
In-Reply-To: <20190515100400.3450-1-christian@brauner.io>
On 05/15, Christian Brauner wrote:
>
> +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
> +{
> + int fd, ret;
> + struct pid *p;
> + struct task_struct *tsk;
> +
> + if (flags)
> + return -EINVAL;
> +
> + if (pid <= 0)
> + return -EINVAL;
> +
> + p = find_get_pid(pid);
> + if (!p)
> + return -ESRCH;
> +
> + rcu_read_lock();
> + tsk = pid_task(p, PIDTYPE_PID);
You do not need find_get_pid() before rcu_lock and put_pid() at the end.
You can just do find_vpid() under rcu_read_lock().
> + if (!tsk)
> + ret = -ESRCH;
> + else if (unlikely(!thread_group_leader(tsk)))
> + ret = -EINVAL;
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.
Oleg.
WARNING: multiple messages have this Message-ID (diff)
From: oleg@redhat.com (Oleg Nesterov)
Subject: [PATCH 1/2] pid: add pidfd_open()
Date: Wed, 15 May 2019 16:38:58 +0200 [thread overview]
Message-ID: <20190515143857.GB18892@redhat.com> (raw)
Message-ID: <20190515143858.D8LzwUubAgFl0XR687gke_31vVzM1UjWh31yEmg0sv0@z> (raw)
In-Reply-To: <20190515100400.3450-1-christian@brauner.io>
On 05/15, Christian Brauner wrote:
>
> +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
> +{
> + int fd, ret;
> + struct pid *p;
> + struct task_struct *tsk;
> +
> + if (flags)
> + return -EINVAL;
> +
> + if (pid <= 0)
> + return -EINVAL;
> +
> + p = find_get_pid(pid);
> + if (!p)
> + return -ESRCH;
> +
> + rcu_read_lock();
> + tsk = pid_task(p, PIDTYPE_PID);
You do not need find_get_pid() before rcu_lock and put_pid() at the end.
You can just do find_vpid() under rcu_read_lock().
> + if (!tsk)
> + ret = -ESRCH;
> + else if (unlikely(!thread_group_leader(tsk)))
> + ret = -EINVAL;
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.
Oleg.
WARNING: multiple messages have this Message-ID (diff)
From: Oleg Nesterov <oleg@redhat.com>
To: Christian Brauner <christian@brauner.io>
Cc: linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org,
linux-mips@vger.kernel.org, dhowells@redhat.com,
linux-kselftest@vger.kernel.org, sparclinux@vger.kernel.org,
linux-api@vger.kernel.org, elena.reshetova@intel.com,
linux-arch@vger.kernel.org, linux-s390@vger.kernel.org,
linux-xtensa@linux-xtensa.org, keescook@chromium.org,
arnd@arndb.de, jannh@google.com, linux-m68k@lists.linux-m68k.org,
viro@zeniv.linux.org.uk, luto@kernel.org, tglx@linutronix.de,
linux-arm-kernel@lists.infradead.org,
linux-parisc@vger.kernel.org, cyphar@cyphar.com,
torvalds@linux-foundation.org, linux-kernel@vger.kernel.org,
luto@amacapital.net, ebiederm@xmission.com,
linux-alpha@vger.kernel.org, akpm@linux-foundation.org,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 1/2] pid: add pidfd_open()
Date: Wed, 15 May 2019 16:38:58 +0200 [thread overview]
Message-ID: <20190515143857.GB18892@redhat.com> (raw)
In-Reply-To: <20190515100400.3450-1-christian@brauner.io>
On 05/15, Christian Brauner wrote:
>
> +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
> +{
> + int fd, ret;
> + struct pid *p;
> + struct task_struct *tsk;
> +
> + if (flags)
> + return -EINVAL;
> +
> + if (pid <= 0)
> + return -EINVAL;
> +
> + p = find_get_pid(pid);
> + if (!p)
> + return -ESRCH;
> +
> + rcu_read_lock();
> + tsk = pid_task(p, PIDTYPE_PID);
You do not need find_get_pid() before rcu_lock and put_pid() at the end.
You can just do find_vpid() under rcu_read_lock().
> + if (!tsk)
> + ret = -ESRCH;
> + else if (unlikely(!thread_group_leader(tsk)))
> + ret = -EINVAL;
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.
Oleg.
WARNING: multiple messages have this Message-ID (diff)
From: Oleg Nesterov <oleg@redhat.com>
To: Christian Brauner <christian@brauner.io>
Cc: linux-ia64@vger.kernel.org, linux-sh@vger.kernel.org,
linux-mips@vger.kernel.org, dhowells@redhat.com,
linux-kselftest@vger.kernel.org, sparclinux@vger.kernel.org,
linux-api@vger.kernel.org, elena.reshetova@intel.com,
linux-arch@vger.kernel.org, linux-s390@vger.kernel.org,
linux-xtensa@linux-xtensa.org, keescook@chromium.org,
arnd@arndb.de, jannh@google.com, linux-m68k@lists.linux-m68k.org,
viro@zeniv.linux.org.uk, luto@kernel.org, tglx@linutronix.de,
linux-arm-kernel@lists.infradead.org,
linux-parisc@vger.kernel.org, cyphar@cyphar.com,
torvalds@linux-foundation.org, linux-kernel@vger.kernel.org,
luto@amacapital.net, ebiederm@xmission.com,
linux-alpha@vger.kernel.org, akpm@linux-foundation.org,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH 1/2] pid: add pidfd_open()
Date: Wed, 15 May 2019 16:38:58 +0200 [thread overview]
Message-ID: <20190515143857.GB18892@redhat.com> (raw)
In-Reply-To: <20190515100400.3450-1-christian@brauner.io>
On 05/15, Christian Brauner wrote:
>
> +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
> +{
> + int fd, ret;
> + struct pid *p;
> + struct task_struct *tsk;
> +
> + if (flags)
> + return -EINVAL;
> +
> + if (pid <= 0)
> + return -EINVAL;
> +
> + p = find_get_pid(pid);
> + if (!p)
> + return -ESRCH;
> +
> + rcu_read_lock();
> + tsk = pid_task(p, PIDTYPE_PID);
You do not need find_get_pid() before rcu_lock and put_pid() at the end.
You can just do find_vpid() under rcu_read_lock().
> + if (!tsk)
> + ret = -ESRCH;
> + else if (unlikely(!thread_group_leader(tsk)))
> + ret = -EINVAL;
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.
Oleg.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-05-15 14:38 UTC|newest]
Thread overview: 115+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-15 10:03 [PATCH 1/2] pid: add pidfd_open() Christian Brauner
2019-05-15 10:03 ` Christian Brauner
2019-05-15 10:03 ` Christian Brauner
2019-05-15 10:03 ` Christian Brauner
2019-05-15 10:03 ` christian
2019-05-15 10:03 ` Christian Brauner
2019-05-15 10:04 ` [PATCH 2/2] tests: add pidfd_open() tests Christian Brauner
2019-05-15 10:04 ` Christian Brauner
2019-05-15 10:04 ` Christian Brauner
2019-05-15 10:04 ` Christian Brauner
2019-05-15 10:04 ` christian
2019-05-15 10:04 ` Christian Brauner
2019-05-15 12:29 ` [PATCH 1/2] pid: add pidfd_open() Geert Uytterhoeven
2019-05-15 12:29 ` Geert Uytterhoeven
2019-05-15 12:29 ` Geert Uytterhoeven
2019-05-15 12:29 ` Geert Uytterhoeven
2019-05-15 12:29 ` geert
2019-05-15 12:29 ` Geert Uytterhoeven
2019-05-15 12:29 ` Geert Uytterhoeven
2019-05-15 14:00 ` Yann Droneaud
2019-05-15 14:00 ` Yann Droneaud
2019-05-15 14:00 ` Yann Droneaud
2019-05-15 14:00 ` ydroneaud
2019-05-15 14:00 ` Yann Droneaud
2019-05-15 14:00 ` Yann Droneaud
2019-05-15 14:16 ` Christian Brauner
2019-05-15 14:16 ` Christian Brauner
2019-05-15 14:16 ` Christian Brauner
2019-05-15 14:16 ` christian
2019-05-15 14:16 ` Christian Brauner
2019-05-15 14:16 ` Christian Brauner
2019-05-15 14:16 ` Christian Brauner
2019-05-15 14:51 ` Aleksa Sarai
2019-05-15 14:51 ` Aleksa Sarai
2019-05-15 14:51 ` Aleksa Sarai
2019-05-15 14:51 ` Aleksa Sarai
2019-05-15 14:51 ` cyphar
2019-05-15 14:51 ` Aleksa Sarai
2019-05-15 15:29 ` Yann Droneaud
2019-05-15 15:29 ` Yann Droneaud
2019-05-15 15:29 ` Yann Droneaud
2019-05-15 15:29 ` Yann Droneaud
2019-05-15 15:29 ` ydroneaud
2019-05-15 15:29 ` Yann Droneaud
2019-05-15 14:38 ` Oleg Nesterov [this message]
2019-05-15 14:38 ` Oleg Nesterov
2019-05-15 14:38 ` Oleg Nesterov
2019-05-15 14:38 ` Oleg Nesterov
2019-05-15 14:38 ` oleg
2019-05-15 14:38 ` Oleg Nesterov
2019-05-15 14:49 ` Christian Brauner
2019-05-15 14:49 ` Christian Brauner
2019-05-15 14:49 ` Christian Brauner
2019-05-15 14:49 ` Christian Brauner
2019-05-15 14:49 ` christian
2019-05-15 14:49 ` Christian Brauner
2019-05-15 15:19 ` Oleg Nesterov
2019-05-15 15:19 ` Oleg Nesterov
2019-05-15 15:19 ` Oleg Nesterov
2019-05-15 15:19 ` Oleg Nesterov
2019-05-15 15:19 ` oleg
2019-05-15 15:19 ` Oleg Nesterov
2019-05-15 15:30 ` Christian Brauner
2019-05-15 15:30 ` Christian Brauner
2019-05-15 15:30 ` Christian Brauner
2019-05-15 15:30 ` Christian Brauner
2019-05-15 15:30 ` christian
2019-05-15 15:30 ` Christian Brauner
2019-05-15 15:35 ` Oleg Nesterov
2019-05-15 15:35 ` Oleg Nesterov
2019-05-15 15:35 ` Oleg Nesterov
2019-05-15 15:35 ` Oleg Nesterov
2019-05-15 15:35 ` oleg
2019-05-15 15:35 ` Oleg Nesterov
2019-05-15 15:40 ` Christian Brauner
2019-05-15 15:40 ` Christian Brauner
2019-05-15 15:40 ` Christian Brauner
2019-05-15 15:40 ` Christian Brauner
2019-05-15 15:40 ` christian
2019-05-15 15:40 ` Christian Brauner
2019-05-15 17:45 ` Daniel Colascione
2019-05-15 17:45 ` Daniel Colascione
2019-05-15 17:45 ` Daniel Colascione
2019-05-15 17:45 ` Daniel Colascione
2019-05-15 17:45 ` dancol
2019-05-15 17:45 ` Daniel Colascione
2019-05-15 17:45 ` Daniel Colascione
2019-05-16 13:08 ` Christian Brauner
2019-05-16 13:08 ` Christian Brauner
2019-05-16 13:08 ` Christian Brauner
2019-05-16 13:08 ` Christian Brauner
2019-05-16 13:08 ` christian
2019-05-16 13:08 ` Christian Brauner
2019-05-16 13:08 ` Christian Brauner
2019-05-16 14:03 ` Jann Horn
2019-05-16 14:03 ` Jann Horn
2019-05-16 14:03 ` Jann Horn
2019-05-16 14:03 ` Jann Horn
2019-05-16 14:03 ` jannh
2019-05-16 14:03 ` Jann Horn
2019-05-16 14:03 ` Jann Horn
2019-05-16 14:05 ` Christian Brauner
2019-05-16 14:05 ` Christian Brauner
2019-05-16 14:05 ` Christian Brauner
2019-05-16 14:05 ` Christian Brauner
2019-05-16 14:05 ` christian
2019-05-16 14:05 ` Christian Brauner
2019-05-16 14:05 ` Christian Brauner
2019-05-16 14:53 ` Aleksa Sarai
2019-05-16 14:53 ` Aleksa Sarai
2019-05-16 14:53 ` Aleksa Sarai
2019-05-16 14:53 ` Aleksa Sarai
2019-05-16 14:53 ` cyphar
2019-05-16 14:53 ` Aleksa Sarai
2019-05-16 14:53 ` Aleksa Sarai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190515143857.GB18892@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=christian@brauner.io \
--cc=cyphar@cyphar.com \
--cc=dhowells@redhat.com \
--cc=ebiederm@xmission.com \
--cc=elena.reshetova@intel.com \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-xtensa@linux-xtensa.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=luto@amacapital.net \
--cc=luto@kernel.org \
--cc=sparclinux@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.