2019-05-29 08:57:24

by John Ogness

[permalink] [raw]
Subject: [PATCHv2] fs/proc: allow reporting eip/esp for all coredumping threads

Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
/proc/PID/stat") stopped reporting eip/esp and commit fd7d56270b52
("fs/proc: Report eip/esp in /prod/PID/stat for coredumping")
reintroduced the feature to fix a regression with userspace core dump
handlers (such as minicoredumper).

Because PF_DUMPCORE is only set for the primary thread, this didn't fix
the original problem for secondary threads. Allow reporting the eip/esp
for all threads by checking for PF_EXITING as well. This is set for all
the other threads when they are killed. coredump_wait() waits for all
the tasks to become inactive before proceeding to invoke the core the
core dumper.

Reported-by: Jan Luebbe <[email protected]>
Signed-off-by: John Ogness <[email protected]>
---
This is a rework of Jan's v1 patch that allows accessing eip/esp of all
the threads without risk of the task still executing on a CPU.

fs/proc/array.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 2edbb657f859..55180501b915 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -462,7 +462,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
* 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)) {
+ if (permitted && (task->flags & (PF_EXITING|PF_DUMPCORE))) {
if (try_get_task_stack(task)) {
eip = KSTK_EIP(task);
esp = KSTK_ESP(task);
--
2.11.0


2019-05-29 21:56:50

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCHv2] fs/proc: allow reporting eip/esp for all coredumping threads

On Wed, 29 May 2019 10:55:53 +0200 John Ogness <[email protected]> wrote:

> Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
> /proc/PID/stat") stopped reporting eip/esp and commit fd7d56270b52
> ("fs/proc: Report eip/esp in /prod/PID/stat for coredumping")
> reintroduced the feature to fix a regression with userspace core dump
> handlers (such as minicoredumper).
>
> Because PF_DUMPCORE is only set for the primary thread, this didn't fix
> the original problem for secondary threads. Allow reporting the eip/esp
> for all threads by checking for PF_EXITING as well. This is set for all
> the other threads when they are killed. coredump_wait() waits for all
> the tasks to become inactive before proceeding to invoke the core the
> core dumper.
>
> Reported-by: Jan Luebbe <[email protected]>
> Signed-off-by: John Ogness <[email protected]>
> ---
> This is a rework of Jan's v1 patch that allows accessing eip/esp of all
> the threads without risk of the task still executing on a CPU.

Jan's patch ended up including

Fixes: fd7d56270b526ca3 ("fs/proc: Report eip/esp in /prod/PID/stat for coredumping")
Cc: <[email protected]>

Are these not appropriate here?

2019-05-30 01:01:55

by John Ogness

[permalink] [raw]
Subject: [PATCHv3] fs/proc: allow reporting eip/esp for all coredumping threads

Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
/proc/PID/stat") stopped reporting eip/esp and commit fd7d56270b52
("fs/proc: Report eip/esp in /prod/PID/stat for coredumping")
reintroduced the feature to fix a regression with userspace core dump
handlers (such as minicoredumper).

Because PF_DUMPCORE is only set for the primary thread, this didn't fix
the original problem for secondary threads. Allow reporting the eip/esp
for all threads by checking for PF_EXITING as well. This is set for all
the other threads when they are killed. coredump_wait() waits for all
the tasks to become inactive before proceeding to invoke a core dumper.

Fixes: fd7d56270b526ca3 ("fs/proc: Report eip/esp in /prod/PID/stat for coredumping")
Reported-by: Jan Luebbe <[email protected]>
Signed-off-by: John Ogness <[email protected]>
---
This is a rework of Jan's v1 patch that allows accessing eip/esp of all
the threads without risk of the task still executing on a CPU.

The code chagnes are the same as v2. With v3 I included a "Fixes" tag,
fixed a typo in the commit message, and Cc'd stable.

fs/proc/array.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 2edbb657f859..55180501b915 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -462,7 +462,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
* 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)) {
+ if (permitted && (task->flags & (PF_EXITING|PF_DUMPCORE))) {
if (try_get_task_stack(task)) {
eip = KSTK_EIP(task);
esp = KSTK_ESP(task);
--
2.11.0

2019-05-30 01:15:42

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCHv3] fs/proc: allow reporting eip/esp for all coredumping threads

(ooh, Greg, let me do it!)

On Thu, 30 May 2019 02:58:59 +0200 John Ogness <[email protected]> wrote:

> Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
> /proc/PID/stat") stopped reporting eip/esp and commit fd7d56270b52
> ("fs/proc: Report eip/esp in /prod/PID/stat for coredumping")
> reintroduced the feature to fix a regression with userspace core dump
> handlers (such as minicoredumper).
>
> Because PF_DUMPCORE is only set for the primary thread, this didn't fix
> the original problem for secondary threads. Allow reporting the eip/esp
> for all threads by checking for PF_EXITING as well. This is set for all
> the other threads when they are killed. coredump_wait() waits for all
> the tasks to become inactive before proceeding to invoke a core dumper.
>
> Fixes: fd7d56270b526ca3 ("fs/proc: Report eip/esp in /prod/PID/stat for coredumping")
> Reported-by: Jan Luebbe <[email protected]>
> Signed-off-by: John Ogness <[email protected]>
> ---
> This is a rework of Jan's v1 patch that allows accessing eip/esp of all
> the threads without risk of the task still executing on a CPU.
>
> The code chagnes are the same as v2. With v3 I included a "Fixes" tag,
> fixed a typo in the commit message, and Cc'd stable.

No, the way to Cc stable is to add

Cc: <[email protected]> to the changelog metadata.

I've made these changes to my copy of this patch, thanks.

2019-06-03 19:56:04

by Jan Lübbe

[permalink] [raw]
Subject: Re: [PATCHv3] fs/proc: allow reporting eip/esp for all coredumping threads

On Thu, 2019-05-30 at 02:58 +0200, John Ogness wrote:
> Commit 0a1eb2d474ed ("fs/proc: Stop reporting eip and esp in
> /proc/PID/stat") stopped reporting eip/esp and commit fd7d56270b52
> ("fs/proc: Report eip/esp in /prod/PID/stat for coredumping")
> reintroduced the feature to fix a regression with userspace core dump
> handlers (such as minicoredumper).
>
> Because PF_DUMPCORE is only set for the primary thread, this didn't fix
> the original problem for secondary threads. Allow reporting the eip/esp
> for all threads by checking for PF_EXITING as well. This is set for all
> the other threads when they are killed. coredump_wait() waits for all
> the tasks to become inactive before proceeding to invoke a core dumper.
>
> Fixes: fd7d56270b526ca3 ("fs/proc: Report eip/esp in /prod/PID/stat for coredumping")
> Reported-by: Jan Luebbe <[email protected]>
> Signed-off-by: John Ogness <[email protected]>

Tested-by: Jan Luebbe <[email protected]>

I've tested your patch and can confirm that eip/esp is accessible for
all threads again.

Thanks,
Jan
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |