From: Andrew Morton <akpm@linux-foundation.org>
To: Vladimir Divjak <vladimir.divjak@bmw.de>
Cc: <linux-fsdevel@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<viro@zeniv.linux.org.uk>, <mcgrof@kernel.org>, <oleg@redhat.com>
Subject: Re: [PATCH] coredump: allow PTRACE_ATTACH to coredump user mode helper
Date: Fri, 9 Jul 2021 21:15:29 -0700 [thread overview]
Message-ID: <20210709211529.59d4263a4780da8de14f351b@linux-foundation.org> (raw)
In-Reply-To: <20210705151019.989929-1-vladimir.divjak@bmw.de>
On Mon, 5 Jul 2021 17:10:19 +0200 Vladimir Divjak <vladimir.divjak@bmw.de> wrote:
> This patch allows the coredump user mode helper process,
> if one is configured (in core_pattern),
> to perform ptrace operations on the dying process
> whose cordump it's handling.
>
> The user mode helper process is expected to do so
> before consuming the coredump data from the pipe,
> and thereby, before the dying process is reaped by kernel.
>
> Issuing a PTRACE_ATTACH request will pause the coredumping
> for that task until ptrace operation is finished.
>
> The user mode helper process is also expected to
> issue a PTRACE_CONT request to the dying process,
> when it is done ptracing it, signaling the dying process
> coredumping can be resumed.
>
> * Problem description / Rationale:
> In automotive and/or embedded environments,
> the storage capacity to store, and/or
> network capabilities to upload
> a complete core file can easily be a limiting factor,
> making offline issue analysis difficult.
>
> * Solution:
> Allow the user mode coredump helper process
> to perform ptrace on the dying process in order to obtain
> useful information such as user mode stacktrace, and
> thereby greatly improve the offline debugging possibilities
> for such environments.
>
> * Impact / Risk:
> The user mode helper process is already entrusted
> with handling the coredump data, so allowing it to read or even change
> the dying process memory should not pose an additional risk.
>
> Furthermore, this change makes coredump emission somewhat slower
> due to the additional step of iterating over the core dump helper list
> and checking if ptrace completion needs to be awaited,
> during coredump emission.
>
Seems useful.
>
> ...
>
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -41,6 +41,7 @@
> #include <linux/fs.h>
> #include <linux/path.h>
> #include <linux/timekeeping.h>
> +#include <linux/jiffies.h>
>
> #include <linux/uaccess.h>
> #include <asm/mmu_context.h>
> @@ -62,6 +63,64 @@ struct core_name {
> int used, size;
> };
>
> +DEFINE_MUTEX(cdh_mutex);
> +LIST_HEAD(cdh_list);
I think this could be static?
> + struct task_struct *task_being_dumped;
> + struct completion ptrace_done;
> + pid_t helper_pid;
> +};
>
> ...
>
> @@ -692,9 +751,14 @@ void do_coredump(const kernel_siginfo_t *siginfo)
> sub_info = call_usermodehelper_setup(helper_argv[0],
> helper_argv, NULL, GFP_KERNEL,
> umh_pipe_setup, NULL, &cprm);
> - if (sub_info)
> + if (sub_info) {
> + mutex_lock(&cdh_mutex);
> retval = call_usermodehelper_exec(sub_info,
> UMH_WAIT_EXEC);
> + if (!retval)
> + cdh_link_current_locked(sub_info->pid);
> + mutex_unlock(&cdh_mutex);
Dumb question: can the usermode helper coredump and then try to take
cdh_mutex, causing a deadlock?
> + }
>
> kfree(helper_argv);
> if (retval) {
>
> ...
>
> --- a/kernel/ptrace.c
> +++ b/kernel/ptrace.c
It seems regrettable that the ptrace code has to be aware of the
coredump code in this fashion.
prev parent reply other threads:[~2021-07-10 4:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-05 15:10 [PATCH] coredump: allow PTRACE_ATTACH to coredump user mode helper Vladimir Divjak
2021-07-08 12:02 ` Oleg Nesterov
2021-07-10 4:15 ` Andrew Morton [this message]
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=20210709211529.59d4263a4780da8de14f351b@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=oleg@redhat.com \
--cc=viro@zeniv.linux.org.uk \
--cc=vladimir.divjak@bmw.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox