mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ptrace: exit: re-trigger PTRACE_EVENT_EXIT after coredump finished
@ 2021-11-22  0:53 Vladimir Divjak
  2021-11-22 15:02 ` Eric W. Biederman
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Divjak @ 2021-11-22  0:53 UTC (permalink / raw)
  To: vladimir.divjak, oleg, jnewsome, tglx, akpm, asml.silence,
	linux-kernel, ebiederm

Re-trigger PTRACE_EVENT_EXIT
(if one is requested with PTRACE_SEIZE setting PTRACE_O_TRACEEXIT option)
for a process being core-dumped, after the coredump is finished.

This enables a potential tracer - coredump user mode helper
(or any other tracer started after the coredump was initiated)
to receive the PTRACE_EVENT_EXIT for all threads of the crashing process.

Rationale:

For zapped threads, PTRACE_EVENT_EXIT is triggered early during do_exit(),
before the point at which they sleep, waiting for
coredump to finish - in exit_mm(), and before a potential
coredump user mode helper process is launched.

That makes it impossible for the coredump user mode helper process to
receive PTRACE_EVENT_EXIT events for all threads of the crashing process,
except for the thread handling the core-dump, which will trigger
the PTRACE_EVENT_EXIT after the coredump has been finished.

Signed-off-by: Vladimir Divjak <vladimir.divjak@bmw.de>
---
 kernel/exit.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/exit.c b/kernel/exit.c
index fd1c04193e18..0157507e75a2 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -473,6 +473,13 @@ static void exit_mm(void)
 				break;
 			freezable_schedule();
 		}
+		/*
+		 * Re-trigger PTRACE_EVENT_EXIT for a process being core-dumped,
+		 * after the coredump finished (see above).
+		 * This enables the coredump user mode helper to receive PTRACE_EVENT_EXIT
+		 * for each thread of the dying process.
+		 */
+		ptrace_event(PTRACE_EVENT_EXIT, current->exit_code);
 		__set_current_state(TASK_RUNNING);
 		mmap_read_lock(mm);
 	}
-- 
2.25.1


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

* Re: [PATCH] ptrace: exit: re-trigger PTRACE_EVENT_EXIT after coredump finished
  2021-11-22  0:53 [PATCH] ptrace: exit: re-trigger PTRACE_EVENT_EXIT after coredump finished Vladimir Divjak
@ 2021-11-22 15:02 ` Eric W. Biederman
  0 siblings, 0 replies; 2+ messages in thread
From: Eric W. Biederman @ 2021-11-22 15:02 UTC (permalink / raw)
  To: Vladimir Divjak; +Cc: oleg, jnewsome, tglx, akpm, asml.silence, linux-kernel

Vladimir Divjak <vladimir.divjak@bmw.de> writes:

> Re-trigger PTRACE_EVENT_EXIT
> (if one is requested with PTRACE_SEIZE setting PTRACE_O_TRACEEXIT option)
> for a process being core-dumped, after the coredump is finished.
>
> This enables a potential tracer - coredump user mode helper
> (or any other tracer started after the coredump was initiated)
> to receive the PTRACE_EVENT_EXIT for all threads of the crashing process.
>
> Rationale:
>
> For zapped threads, PTRACE_EVENT_EXIT is triggered early during do_exit(),
> before the point at which they sleep, waiting for
> coredump to finish - in exit_mm(), and before a potential
> coredump user mode helper process is launched.
>
> That makes it impossible for the coredump user mode helper process to
> receive PTRACE_EVENT_EXIT events for all threads of the crashing process,
> except for the thread handling the core-dump, which will trigger
> the PTRACE_EVENT_EXIT after the coredump has been finished.

Please test the latest kernel.

The coredump now stops much earlier than exit_mm, and PTRACE_EVENT_EXIT
is after the point the coredump stops.

If you need this functionality on older kernels it should be possible to
backport a subset of my changes without too much trouble

Eric

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

end of thread, other threads:[~2021-11-22 15:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22  0:53 [PATCH] ptrace: exit: re-trigger PTRACE_EVENT_EXIT after coredump finished Vladimir Divjak
2021-11-22 15:02 ` Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®