linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/proc: report eip/esp in /prod/PID/stat for coredumping
@ 2017-09-14  9:42 John Ogness
  2017-09-14 14:51 ` Andy Lutomirski
       [not found] ` <87poatfwg6.fsf-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
  0 siblings, 2 replies; 7+ messages in thread
From: John Ogness @ 2017-09-14  9:42 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: Thomas Gleixner, Al Viro, Andrew Morton, Borislav Petkov,
	Brian Gerst, Kees Cook, Linus Torvalds, Linux API,
	Peter Zijlstra, Tetsuo Handa, Tycho Andersen, Ingo Molnar,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	stable-u79uwXL29TY76Z2rM5mHXA

Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
/proc/PID/stat") stopped reporting eip/esp because it is
racey and dangerous for executing tasks. The comment adds:

    As far as I know, there are no use programs that make any
    material use of these fields, so just get rid of them.

However, existing userspace core-dump-handler applications (for
example, minicoredumper) are using these fields since they
provide an excellent cross-platform interface to these valuable
pointers. So that commit introduced a user space visible
regression.

Partially revert the change and make the readout possible for
tasks with the proper permissions and only if the target task
has the PF_DUMPCORE flag set.

Reported-by: Marco Felsch <marco.felsch-4vaI68m59Pc@public.gmane.org>
Signed-off-by: John Ogness <john.ogness-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Fixes: 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in> /proc/PID/stat")
---
 fs/proc/array.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 88c3555..696cc68 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -421,7 +421,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
 		 * esp and eip are intentionally zeroed out.  There is no
 		 * non-racy way to read them without freezing the task.
 		 * Programs that need reliable values can use ptrace(2).
+		 *
+		 * The only exception is if the task is core dumping because
+		 * a program is not able to use ptrace(2) in that case. It is
+		 * safe because the task has stopped executing permanently.
 		 */
+		if (permitted && (task->flags & PF_DUMPCORE)) {
+			eip = KSTK_EIP(task);
+			esp = KSTK_ESP(task);
+		}
 	}
 
 	get_task_comm(tcomm, task);
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] fs/proc: report eip/esp in /prod/PID/stat for coredumping
  2017-09-14  9:42 [PATCH] fs/proc: report eip/esp in /prod/PID/stat for coredumping John Ogness
@ 2017-09-14 14:51 ` Andy Lutomirski
       [not found] ` <87poatfwg6.fsf-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
  1 sibling, 0 replies; 7+ messages in thread
From: Andy Lutomirski @ 2017-09-14 14:51 UTC (permalink / raw)
  To: John Ogness
  Cc: Andy Lutomirski, Thomas Gleixner, Al Viro, Andrew Morton,
	Borislav Petkov, Brian Gerst, Kees Cook, Linus Torvalds,
	Linux API, Peter Zijlstra, Tetsuo Handa, Tycho Andersen,
	Ingo Molnar, linux-kernel, stable

On Thu, Sep 14, 2017 at 2:42 AM, John Ogness <john.ogness@linutronix.de> wrote:
> Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
> /proc/PID/stat") stopped reporting eip/esp because it is
> racey and dangerous for executing tasks. The comment adds:
>
>     As far as I know, there are no use programs that make any
>     material use of these fields, so just get rid of them.
>
> However, existing userspace core-dump-handler applications (for
> example, minicoredumper) are using these fields since they
> provide an excellent cross-platform interface to these valuable
> pointers. So that commit introduced a user space visible
> regression.
>
> Partially revert the change and make the readout possible for
> tasks with the proper permissions and only if the target task
> has the PF_DUMPCORE flag set.

Looks okay to me.

Reviewed-by: Andy Lutomirski <luto@kernel.org>

--Andy

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] fs/proc: report eip/esp in /prod/PID/stat for coredumping
       [not found] ` <87poatfwg6.fsf-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
@ 2017-09-14 15:37   ` Thomas Gleixner
  2017-09-15 19:08     ` Linus Torvalds
  2017-09-15 21:09   ` [tip:core/urgent] fs/proc: Report " tip-bot for John Ogness
  2017-09-15 21:36   ` tip-bot for John Ogness
  2 siblings, 1 reply; 7+ messages in thread
From: Thomas Gleixner @ 2017-09-14 15:37 UTC (permalink / raw)
  To: John Ogness
  Cc: Andy Lutomirski, Al Viro, Andrew Morton, Borislav Petkov,
	Brian Gerst, Kees Cook, Linus Torvalds, Linux API,
	Peter Zijlstra, Tetsuo Handa, Tycho Andersen, Ingo Molnar,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	stable-u79uwXL29TY76Z2rM5mHXA

On Thu, 14 Sep 2017, John Ogness wrote:

> Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
> /proc/PID/stat") stopped reporting eip/esp because it is
> racey and dangerous for executing tasks. The comment adds:
> 
>     As far as I know, there are no use programs that make any
>     material use of these fields, so just get rid of them.
> 
> However, existing userspace core-dump-handler applications (for
> example, minicoredumper) are using these fields since they
> provide an excellent cross-platform interface to these valuable
> pointers. So that commit introduced a user space visible
> regression.
> 
> Partially revert the change and make the readout possible for
> tasks with the proper permissions and only if the target task
> has the PF_DUMPCORE flag set.

Duh, I completely forgot about mini core dumper when I acked that commit.

Reviewed-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] fs/proc: report eip/esp in /prod/PID/stat for coredumping
  2017-09-14 15:37   ` Thomas Gleixner
@ 2017-09-15 19:08     ` Linus Torvalds
  2017-09-15 21:03       ` Ingo Molnar
  0 siblings, 1 reply; 7+ messages in thread
From: Linus Torvalds @ 2017-09-15 19:08 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: John Ogness, Andy Lutomirski, Al Viro, Andrew Morton,
	Borislav Petkov, Brian Gerst, Kees Cook, Linux API,
	Peter Zijlstra, Tetsuo Handa, Tycho Andersen, Ingo Molnar,
	Linux Kernel Mailing List, stable

Ingo, I'm assuming I'll get this from the -tip tree, which is where I
got the original commit that this fixes.

Thanks,
                   Linus

On Thu, Sep 14, 2017 at 8:37 AM, Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org> wrote:
> On Thu, 14 Sep 2017, John Ogness wrote:
>
>> Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
>> /proc/PID/stat") stopped reporting eip/esp because it is
>> racey and dangerous for executing tasks. The comment adds:
...
>> Partially revert the change and make the readout possible for
>> tasks with the proper permissions and only if the target task
>> has the PF_DUMPCORE flag set.
>
> Duh, I completely forgot about mini core dumper when I acked that commit.
>
> Reviewed-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] fs/proc: report eip/esp in /prod/PID/stat for coredumping
  2017-09-15 19:08     ` Linus Torvalds
@ 2017-09-15 21:03       ` Ingo Molnar
  0 siblings, 0 replies; 7+ messages in thread
From: Ingo Molnar @ 2017-09-15 21:03 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Thomas Gleixner, John Ogness, Andy Lutomirski, Al Viro,
	Andrew Morton, Borislav Petkov, Brian Gerst, Kees Cook,
	Linux API, Peter Zijlstra, Tetsuo Handa, Tycho Andersen,
	Linux Kernel Mailing List, stable


* Linus Torvalds <torvalds@linux-foundation.org> wrote:

> Ingo, I'm assuming I'll get this from the -tip tree, which is where I
> got the original commit that this fixes.
> 
> Thanks,
>                    Linus

Yeah, will do!

Thanks,

	Ingo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [tip:core/urgent] fs/proc: Report eip/esp in /prod/PID/stat for coredumping
       [not found] ` <87poatfwg6.fsf-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
  2017-09-14 15:37   ` Thomas Gleixner
@ 2017-09-15 21:09   ` tip-bot for John Ogness
  2017-09-15 21:36   ` tip-bot for John Ogness
  2 siblings, 0 replies; 7+ messages in thread
From: tip-bot for John Ogness @ 2017-09-15 21:09 UTC (permalink / raw)
  To: linux-tip-commits-u79uwXL29TY76Z2rM5mHXA
  Cc: luto-DgEjT+Ai2ygdnm+yROfE0A,
	tycho.andersen-Z7WLFzj8eWMS+FvcfC7Uqw, bp-Gina5bIWoIWzQB+pC5nmwQ,
	mingo-DgEjT+Ai2ygdnm+yROfE0A,
	torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	hpa-YMNOUZJC4hwAvxtiuMwx3w,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn, marco.felsch-4vaI68m59Pc,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	penguin-kernel-1yMVhJb1mP/7nzcFbJAaVXf5DAMn2ifp,
	peterz-wEGCiKHe2LqWVfeAwA7xHQ, brgerst-Re5JQEeQqe8AvxtiuMwx3w,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	linux-api-u79uwXL29TY76Z2rM5mHXA, tglx-hfZtesqFncYOwBW4kG4KsQ,
	keescook-F7+t8E8rja9g9hUCZPvPmw,
	john.ogness-hfZtesqFncYOwBW4kG4KsQ

Commit-ID:  451eb3f2053ea4eeb40f94947c542cfbd7636186
Gitweb:     http://git.kernel.org/tip/451eb3f2053ea4eeb40f94947c542cfbd7636186
Author:     John Ogness <john.ogness-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
AuthorDate: Thu, 14 Sep 2017 11:42:17 +0200
Committer:  Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
CommitDate: Fri, 15 Sep 2017 23:04:59 +0200

fs/proc: Report eip/esp in /prod/PID/stat for coredumping

Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
/proc/PID/stat") stopped reporting eip/esp because it is
racey and dangerous for executing tasks. The comment adds:

    As far as I know, there are no use programs that make any
    material use of these fields, so just get rid of them.

However, existing userspace core-dump-handler applications (for
example, minicoredumper) are using these fields since they
provide an excellent cross-platform interface to these valuable
pointers. So that commit introduced a user space visible
regression.

Partially revert the change and make the readout possible for
tasks with the proper permissions and only if the target task
has the PF_DUMPCORE flag set.

Fixes: 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in> /proc/PID/stat")
Reported-by: Marco Felsch <marco.felsch-4vaI68m59Pc@public.gmane.org>
Signed-off-by: John Ogness <john.ogness-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Reviewed-by: Andy Lutomirski <luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Tycho Andersen <tycho.andersen-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Cc: Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Cc: Brian Gerst <brgerst-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Tetsuo Handa <penguin-kernel-1yMVhJb1mP/7nzcFbJAaVXf5DAMn2ifp@public.gmane.org>
Cc: Borislav Petkov <bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org>
Cc: Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
Cc: Linux API <linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Cc: Linus Torvalds <torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Link: http://lkml.kernel.org/r/87poatfwg6.fsf-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org
Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>

---
 fs/proc/array.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 88c3555..696cc68 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -421,7 +421,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
 		 * esp and eip are intentionally zeroed out.  There is no
 		 * non-racy way to read them without freezing the task.
 		 * Programs that need reliable values can use ptrace(2).
+		 *
+		 * The only exception is if the task is core dumping because
+		 * a program is not able to use ptrace(2) in that case. It is
+		 * safe because the task has stopped executing permanently.
 		 */
+		if (permitted && (task->flags & PF_DUMPCORE)) {
+			eip = KSTK_EIP(task);
+			esp = KSTK_ESP(task);
+		}
 	}
 
 	get_task_comm(tcomm, task);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [tip:core/urgent] fs/proc: Report eip/esp in /prod/PID/stat for coredumping
       [not found] ` <87poatfwg6.fsf-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
  2017-09-14 15:37   ` Thomas Gleixner
  2017-09-15 21:09   ` [tip:core/urgent] fs/proc: Report " tip-bot for John Ogness
@ 2017-09-15 21:36   ` tip-bot for John Ogness
  2 siblings, 0 replies; 7+ messages in thread
From: tip-bot for John Ogness @ 2017-09-15 21:36 UTC (permalink / raw)
  To: linux-tip-commits-u79uwXL29TY76Z2rM5mHXA
  Cc: peterz-wEGCiKHe2LqWVfeAwA7xHQ, tglx-hfZtesqFncYOwBW4kG4KsQ,
	torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn,
	keescook-F7+t8E8rja9g9hUCZPvPmw,
	linux-api-u79uwXL29TY76Z2rM5mHXA,
	john.ogness-hfZtesqFncYOwBW4kG4KsQ, marco.felsch-4vaI68m59Pc,
	akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b,
	tycho.andersen-Z7WLFzj8eWMS+FvcfC7Uqw,
	mingo-DgEjT+Ai2ygdnm+yROfE0A, brgerst-Re5JQEeQqe8AvxtiuMwx3w,
	hpa-YMNOUZJC4hwAvxtiuMwx3w, luto-DgEjT+Ai2ygdnm+yROfE0A,
	bp-Gina5bIWoIWzQB+pC5nmwQ,
	penguin-kernel-1yMVhJb1mP/7nzcFbJAaVXf5DAMn2ifp

Commit-ID:  fd7d56270b526ca3ed0c224362e3c64a0f86687a
Gitweb:     http://git.kernel.org/tip/fd7d56270b526ca3ed0c224362e3c64a0f86687a
Author:     John Ogness <john.ogness-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
AuthorDate: Thu, 14 Sep 2017 11:42:17 +0200
Committer:  Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
CommitDate: Fri, 15 Sep 2017 23:31:16 +0200

fs/proc: Report eip/esp in /prod/PID/stat for coredumping

Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
/proc/PID/stat") stopped reporting eip/esp because it is
racy and dangerous for executing tasks. The comment adds:

    As far as I know, there are no use programs that make any
    material use of these fields, so just get rid of them.

However, existing userspace core-dump-handler applications (for
example, minicoredumper) are using these fields since they
provide an excellent cross-platform interface to these valuable
pointers. So that commit introduced a user space visible
regression.

Partially revert the change and make the readout possible for
tasks with the proper permissions and only if the target task
has the PF_DUMPCORE flag set.

Fixes: 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in> /proc/PID/stat")
Reported-by: Marco Felsch <marco.felsch-4vaI68m59Pc@public.gmane.org>
Signed-off-by: John Ogness <john.ogness-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Reviewed-by: Andy Lutomirski <luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Tycho Andersen <tycho.andersen-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Cc: Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Cc: Peter Zijlstra <peterz-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
Cc: Brian Gerst <brgerst-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Tetsuo Handa <penguin-kernel-1yMVhJb1mP/7nzcFbJAaVXf5DAMn2ifp@public.gmane.org>
Cc: Borislav Petkov <bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org>
Cc: Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
Cc: Linux API <linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Cc: Linus Torvalds <torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Link: http://lkml.kernel.org/r/87poatfwg6.fsf-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org
Signed-off-by: Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>

---
 fs/proc/array.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 88c3555..525157c 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -62,6 +62,7 @@
 #include <linux/mman.h>
 #include <linux/sched/mm.h>
 #include <linux/sched/numa_balancing.h>
+#include <linux/sched/task_stack.h>
 #include <linux/sched/task.h>
 #include <linux/sched/cputime.h>
 #include <linux/proc_fs.h>
@@ -421,7 +422,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
 		 * esp and eip are intentionally zeroed out.  There is no
 		 * non-racy way to read them without freezing the task.
 		 * Programs that need reliable values can use ptrace(2).
+		 *
+		 * The only exception is if the task is core dumping because
+		 * a program is not able to use ptrace(2) in that case. It is
+		 * safe because the task has stopped executing permanently.
 		 */
+		if (permitted && (task->flags & PF_DUMPCORE)) {
+			eip = KSTK_EIP(task);
+			esp = KSTK_ESP(task);
+		}
 	}
 
 	get_task_comm(tcomm, task);

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-09-15 21:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-14  9:42 [PATCH] fs/proc: report eip/esp in /prod/PID/stat for coredumping John Ogness
2017-09-14 14:51 ` Andy Lutomirski
     [not found] ` <87poatfwg6.fsf-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
2017-09-14 15:37   ` Thomas Gleixner
2017-09-15 19:08     ` Linus Torvalds
2017-09-15 21:03       ` Ingo Molnar
2017-09-15 21:09   ` [tip:core/urgent] fs/proc: Report " tip-bot for John Ogness
2017-09-15 21:36   ` tip-bot for John Ogness

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).