From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86AB21DB127; Fri, 25 Apr 2025 16:49:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745599764; cv=none; b=AlKFz+tGidT/vy+XqKW2VW+tSrPHdaxZAYmES60k4jq/AGe5P8jz7qp/XTpPyXvBBTLfJG3ioZ6aSmsOLa/b64ajUQQ8Z2i/IhcNycv5SC/2rTJfklNcsNstEAwJQcDtRFrtVl6iKJBkXYHYF58S00rRSv2AB7NI3wBjGKaqoV4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745599764; c=relaxed/simple; bh=461+pUfno2hTIbCXCu9nP1x7M0HrZserREq+i6zkxp0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Hqh4Hvcu8R10qquQf/DMRMz7zq/9AOTgF5hdbCv4fhdgmwUYW8T6LgShCUGDLRjuVq6P99KzHSBD+rCfVgvzuzh4CYmsrXhntpzhCwkdXn96fEf0u3u740IXnyDcmXVrqvsiK7bpqU6rxgX+fh0l57aHCdoFkXs6eGfFAz4okPM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Llnyj+X+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Llnyj+X+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6723C4CEE4; Fri, 25 Apr 2025 16:49:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745599764; bh=461+pUfno2hTIbCXCu9nP1x7M0HrZserREq+i6zkxp0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Llnyj+X+6CK/sPAqAggsHaHa7jXYnwl6GrRnj7DKn1eo6DxL2rPpiNAw5W/JIsoXw K1oCVDwtv+O6b9bb5MfIsgFIfk1L9EeQJyKInb/mD9NseF+7wZehkCBUtK7BzmdwKF Q+m4q4eZwYBTxzvUkak7j2Dm7w9tySNB4yjGw1ugumu/OXOoZcmnUIlzt4bkoBDsOz T5E7KhY1fzSE7i5rE063TkQ/+dqYJtMNIA8AYj82TF3R5sI/z0CXtcEz7Ebk/eKfqH Mo5x9g84BoTaKtlXvhCxBRycD246nllcg5U+BeU9aqVZIFIJfdm/WjkllLjHzqpsHQ 0n2BzQvHnhJFQ== Date: Fri, 25 Apr 2025 18:49:19 +0200 From: Christian Brauner To: Benjamin Drung Cc: linux-fsdevel@vger.kernel.org, Oleg Nesterov , Luca Boccassi , Lennart Poettering , Daan De Meyer , Mike Yuan , Zbigniew =?utf-8?Q?J=C4=99drzejewski-Szmek?= , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/3] coredump: hand a pidfd to the usermode coredump helper Message-ID: <20250425-erbschaft-nummer-8ddbe420ae22@brauner> References: <20250414-work-coredump-v2-0-685bf231f828@kernel.org> <20250414-work-coredump-v2-3-685bf231f828@kernel.org> <20250425-eskapaden-regnen-4534af2aef11@brauner> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On Fri, Apr 25, 2025 at 02:03:34PM +0200, Benjamin Drung wrote: > On Fri, 2025-04-25 at 13:57 +0200, Christian Brauner wrote: > > On Fri, Apr 25, 2025 at 01:31:56PM +0200, Benjamin Drung wrote: > > > Hi, > > > > > > On Mon, 2025-04-14 at 15:55 +0200, Christian Brauner wrote: > > > > Give userspace a way to instruct the kernel to install a pidfd into the > > > > usermode helper process. This makes coredump handling a lot more > > > > reliable for userspace. In parallel with this commit we already have > > > > systemd adding support for this in [1]. > > > > > > > > We create a pidfs file for the coredumping process when we process the > > > > corename pattern. When the usermode helper process is forked we then > > > > install the pidfs file as file descriptor three into the usermode > > > > helpers file descriptor table so it's available to the exec'd program. > > > > > > > > Since usermode helpers are either children of the system_unbound_wq > > > > workqueue or kthreadd we know that the file descriptor table is empty > > > > and can thus always use three as the file descriptor number. > > > > > > > > Note, that we'll install a pidfd for the thread-group leader even if a > > > > subthread is calling do_coredump(). We know that task linkage hasn't > > > > been removed due to delay_group_leader() and even if this @current isn't > > > > the actual thread-group leader we know that the thread-group leader > > > > cannot be reaped until @current has exited. > > > > > > > > Link: https://github.com/systemd/systemd/pull/37125 [1] > > > > Tested-by: Luca Boccassi > > > > Signed-off-by: Christian Brauner > > > > --- > > > > fs/coredump.c | 59 ++++++++++++++++++++++++++++++++++++++++++++---- > > > > include/linux/coredump.h | 1 + > > > > 2 files changed, 56 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/fs/coredump.c b/fs/coredump.c > > > > index 9da592aa8f16..403be0ff780e 100644 > > > > --- a/fs/coredump.c > > > > +++ b/fs/coredump.c > > > > @@ -43,6 +43,9 @@ > > > > #include > > > > #include > > > > #include > > > > +#include > > > > +#include > > > > +#include > > > > > > > > #include > > > > #include > > > > @@ -60,6 +63,12 @@ static void free_vma_snapshot(struct coredump_params *cprm); > > > > #define CORE_FILE_NOTE_SIZE_DEFAULT (4*1024*1024) > > > > /* Define a reasonable max cap */ > > > > #define CORE_FILE_NOTE_SIZE_MAX (16*1024*1024) > > > > +/* > > > > + * File descriptor number for the pidfd for the thread-group leader of > > > > + * the coredumping task installed into the usermode helper's file > > > > + * descriptor table. > > > > + */ > > > > +#define COREDUMP_PIDFD_NUMBER 3 > > > > > > > > static int core_uses_pid; > > > > static unsigned int core_pipe_limit; > > > > @@ -339,6 +348,27 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm, > > > > case 'C': > > > > err = cn_printf(cn, "%d", cprm->cpu); > > > > break; > > > > + /* pidfd number */ > > > > + case 'F': { > > > > + /* > > > > + * Installing a pidfd only makes sense if > > > > + * we actually spawn a usermode helper. > > > > + */ > > > > + if (!ispipe) > > > > + break; > > > > + > > > > + /* > > > > + * Note that we'll install a pidfd for the > > > > + * thread-group leader. We know that task > > > > + * linkage hasn't been removed yet and even if > > > > + * this @current isn't the actual thread-group > > > > + * leader we know that the thread-group leader > > > > + * cannot be reaped until @current has exited. > > > > + */ > > > > + cprm->pid = task_tgid(current); > > > > + err = cn_printf(cn, "%d", COREDUMP_PIDFD_NUMBER); > > > > + break; > > > > + } > > > > default: > > > > break; > > > > } > > > > > > > > > > I tried this change with Apport: I took the Ubuntu mainline kernel build > > > https://kernel.ubuntu.com/mainline/daily/2025-04-24/ (that refers to > > > mainline commit e54f9b0410347c49b7ffdd495578811e70d7a407) and applied > > > these three patches on top. Then I modified Apport to take the > > > additional `-F%F` and tested that on Ubuntu 25.04 (plucky). The result > > > is the coredump failed as long as there was `-F%F` on > > > > I have no clue what -F%F is and whether that leading -F is something > > specific to Apport but the specifier is %F not -F%F. For example: > > > > > cat /proc/sys/kernel/core_pattern > > |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %F > > > > And note that this requires the pipe logic to be used, aka "|" needs to > > be specified. Without it this doesn't make sense. > > Apport takes short option parameters. They match the kernel template > specifiers. The failing pattern: > > $ cat /proc/sys/kernel/core_pattern > |/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -F%F -- %E > > Once I drop %F Apport is called without issues: > > $ cat /proc/sys/kernel/core_pattern > |/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E Youm must have CONFIG_DEBUG_VFS=y enabled where we trample the pidfs file we just allocated. It's a debug only assert. I've removed it now and pushed it to vfs-6.16.coredump. Can you either try with that or simply unset CONFIG_DEBUG_VFS and retest.