Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1195217pxv; Fri, 9 Jul 2021 21:16:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgIIDuWnHeuf641xBa8nTlq/NQXGqa+VMYP935GAgD4tODpHvdUGHNWs56edD7qXYOKOAE X-Received: by 2002:a02:3b26:: with SMTP id c38mr35497503jaa.12.1625890597860; Fri, 09 Jul 2021 21:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625890597; cv=none; d=google.com; s=arc-20160816; b=v3iZY/sHRXzcEqObRMM2fWs2YeLttx+dYpvKpbBjx7545dpBXkT/S/0RRGl58Kboat pKZ/s4MtwTud/2EFhthMplsa2RBT/p0rss5vweGEtlBF2F38vhY7TJn8MTzRH52EObr5 8HeGFuXFhzjpy4aBpSYfJL/K1BeJ9BEWHIAwJyQKVhEEL4pZ8D24S7HJ3sZQi9lKxLMA e3sBziIic/ajoGQvb7i4S/Z6J9eTkX4yRNNq5IzjcndltROJ9XzZv3OcvC84t0MV4lkQ h36wwSKEzEj8t2imem9dYa1YPB4ntEDtza8q+y4j8SSF0cI2Hg5IGbonKyRTBqrwBQLe UOlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=5lodiBigrRDE9aMhCs1X3w02y3y7nebETp4qvtbjeEg=; b=mtbJNX2She+cwusfHbTMY9BNsCawNSTgb8ZBWX+WcwNexm7h7feUWSJaNlweTYQUPA nxnA5fFrwB6+EyvOWgKqdBxorjNiVEsvCl9HsfS9RMeQi8H5cB8yBQqSNq69a3gLfQq+ YEl7UVvBD6sHenb9h5pLN4TcJ/WehzJQTdvtxjuLLTofEL2d2MzCcfgLW6kkTogJ5flK NQGaeA0G3YixybhxZ8DaFHvr/fWV/TqLqmXOOre5jyPBr03pTqx5A4tSUWmTraEZga0+ jIXu3ZzuU670Xs/lU0s61kdqcumykjfCfhgzAnA7YERFwHi2wIyPdrRtUFTNEV0ZYAyd il6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b="Cb8b/2o6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si9483061jav.63.2021.07.09.21.16.26; Fri, 09 Jul 2021 21:16:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b="Cb8b/2o6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbhGJESP (ORCPT + 99 others); Sat, 10 Jul 2021 00:18:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:43426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbhGJESP (ORCPT ); Sat, 10 Jul 2021 00:18:15 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DB1FA613DC; Sat, 10 Jul 2021 04:15:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1625890530; bh=fZW06Fo1ne0XzT2jTLDKAZu0qD9DOCEYSaRxO9QMayU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Cb8b/2o682zFUYS/y/s7vKsrzR9+ktfhhFIjfzZdz0x+NTJ653SPVhWnM0KSi68fR kyP7eWeEkdPLOBmmJizPRzRK/DGNX140wu71Es3vHxJPReVrMZBJ5nNPq5m+Kd0Jh2 +KrQ5vGe9+7qkoFGXS5FhbQVKg144rnfZm8Y5Y/w= Date: Fri, 9 Jul 2021 21:15:29 -0700 From: Andrew Morton To: Vladimir Divjak Cc: , , , , Subject: Re: [PATCH] coredump: allow PTRACE_ATTACH to coredump user mode helper Message-Id: <20210709211529.59d4263a4780da8de14f351b@linux-foundation.org> In-Reply-To: <20210705151019.989929-1-vladimir.divjak@bmw.de> References: <20210705151019.989929-1-vladimir.divjak@bmw.de> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 5 Jul 2021 17:10:19 +0200 Vladimir Divjak 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 > #include > #include > +#include > > #include > #include > @@ -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.