From nobody Sat Feb 7 21:15:55 2026 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 5B9AC254AE5; Fri, 2 May 2025 12:42:48 +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=1746189769; cv=none; b=FIYm7JpSyae8ovwOe1SLisPPWXNAzR39turWroQ+APDxR76ry6m9H+IaGpWGehTkd5BUvwXR38doZ853IsAyPjQfs8SOv5v1ra1q/LopJYuvkq4MrYlZEQH/8kLlAafg4vvFABr/GtWyprbQI60r1gr8TjvKD2nlBM6c4S9QL88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746189769; c=relaxed/simple; bh=d48rlIeb55kv9LHwHtfILNbBpVSvS+cV2//Rf2p6cRQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o5BTeM278GQRndNioT73uyyWsgde6jg0nWIm4KDjIospQrZVpBU1GjjfO1/MceQQHL2/QupL4lffyRLhXEl26J02gIx2DFY95+BmKYp8Rv++LimEUtE5oBHyd0rvsLLVfdPTngyvSFIjzPSMx5hPm94IwGPcVAg0/T0Y+E0ptA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ym9rhXJ6; 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="Ym9rhXJ6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBDF5C4CEE4; Fri, 2 May 2025 12:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746189768; bh=d48rlIeb55kv9LHwHtfILNbBpVSvS+cV2//Rf2p6cRQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ym9rhXJ6YqnYaVLgRVBOZoLLxp2uyI5BOAtHdk4rT9y79qu+bZjhdvbYEHXYf15xA OXpMttX1a4yz4vUulrf1mAP0l6TYhaJ9501KZ8OWEAAP7WaKPXK2fTA5gZfQXA3ydq tFkGEprVNIKJf7ZXxSXCCqMZL7vZTcZoiTJJk7T40ofBXTn2K54hC5u3h5o+4ORjIz 1gTnVuvKZtUF0TO2q6tLXJ0Q2mDQVJcOwau4toSVtIxVN2SBiUqx5Apywi5ILGYHu3 3EieaFb1j/lK31oUUV11syvNuct3rYAzTQ7j0WDVztIvNWpynbvy7Zs+4c9l2grpBU 2s5xiP7rzJPbQ== From: Christian Brauner Date: Fri, 02 May 2025 14:42:32 +0200 Subject: [PATCH RFC v2 1/6] coredump: massage format_corname() 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-Transfer-Encoding: quoted-printable Message-Id: <20250502-work-coredump-socket-v2-1-43259042ffc7@kernel.org> References: <20250502-work-coredump-socket-v2-0-43259042ffc7@kernel.org> In-Reply-To: <20250502-work-coredump-socket-v2-0-43259042ffc7@kernel.org> To: Eric Dumazet , Kuniyuki Iwashima , Oleg Nesterov , linux-fsdevel@vger.kernel.org, Jann Horn Cc: "David S. Miller" , Alexander Viro , Daan De Meyer , David Rheinsberg , Jakub Kicinski , Jan Kara , Lennart Poettering , Luca Boccassi , Mike Yuan , Paolo Abeni , Simon Horman , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=4656; i=brauner@kernel.org; h=from:subject:message-id; bh=d48rlIeb55kv9LHwHtfILNbBpVSvS+cV2//Rf2p6cRQ=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWSI7N3/8Tzn7oU+ouf935kc6pu1UlEyfM2OWJGliQ/Xf L7+mcvJvKOUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAim24w/DO4XP1nwzeRiTqd Z767ruKK+5WSzubr8NtCjnXjL8GL8w8x/A/9fC0+a5Ki5CQu+2dTWko0yw+tbuHrCHVassN9deN 2VgYA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 We're going to extend the coredump code in follow-up patches. Clean it up so we can do this more easily. Signed-off-by: Christian Brauner --- fs/coredump.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index d740a0411266..281320ea351f 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -76,9 +76,15 @@ static char core_pattern[CORENAME_MAX_SIZE] =3D "core"; static int core_name_size =3D CORENAME_MAX_SIZE; unsigned int core_file_note_size_limit =3D CORE_FILE_NOTE_SIZE_DEFAULT; =20 +enum coredump_type_t { + COREDUMP_FILE =3D 1, + COREDUMP_PIPE =3D 2, +}; + struct core_name { char *corename; int used, size; + enum coredump_type_t core_type; }; =20 static int expand_corename(struct core_name *cn, int size) @@ -218,18 +224,21 @@ static int format_corename(struct core_name *cn, stru= ct coredump_params *cprm, { const struct cred *cred =3D current_cred(); const char *pat_ptr =3D core_pattern; - int ispipe =3D (*pat_ptr =3D=3D '|'); bool was_space =3D false; int pid_in_pattern =3D 0; int err =3D 0; =20 cn->used =3D 0; cn->corename =3D NULL; + if (*pat_ptr =3D=3D '|') + cn->core_type =3D COREDUMP_PIPE; + else + cn->core_type =3D COREDUMP_FILE; if (expand_corename(cn, core_name_size)) return -ENOMEM; cn->corename[0] =3D '\0'; =20 - if (ispipe) { + if (cn->core_type =3D=3D COREDUMP_PIPE) { int argvs =3D sizeof(core_pattern) / 2; (*argv) =3D kmalloc_array(argvs, sizeof(**argv), GFP_KERNEL); if (!(*argv)) @@ -247,7 +256,7 @@ static int format_corename(struct core_name *cn, struct= coredump_params *cprm, * Split on spaces before doing template expansion so that * %e and %E don't get split if they have spaces in them */ - if (ispipe) { + if (cn->core_type =3D=3D COREDUMP_PIPE) { if (isspace(*pat_ptr)) { if (cn->used !=3D 0) was_space =3D true; @@ -353,7 +362,7 @@ static int format_corename(struct core_name *cn, struct= coredump_params *cprm, * Installing a pidfd only makes sense if * we actually spawn a usermode helper. */ - if (!ispipe) + if (!(cn->core_type !=3D COREDUMP_PIPE)) break; =20 /* @@ -384,12 +393,12 @@ static int format_corename(struct core_name *cn, stru= ct coredump_params *cprm, * If core_pattern does not include a %p (as is the default) * and core_uses_pid is set, then .%pid will be appended to * the filename. Do not do this for piped commands. */ - if (!ispipe && !pid_in_pattern && core_uses_pid) { + if (!(cn->core_type =3D=3D COREDUMP_PIPE) && !pid_in_pattern && core_uses= _pid) { err =3D cn_printf(cn, ".%d", task_tgid_vnr(current)); if (err) return err; } - return ispipe; + return 0; } =20 static int zap_process(struct signal_struct *signal, int exit_code) @@ -583,7 +592,6 @@ void do_coredump(const kernel_siginfo_t *siginfo) const struct cred *old_cred; struct cred *cred; int retval =3D 0; - int ispipe; size_t *argv =3D NULL; int argc =3D 0; /* require nonrelative corefile path and be extra careful */ @@ -632,19 +640,18 @@ void do_coredump(const kernel_siginfo_t *siginfo) =20 old_cred =3D override_creds(cred); =20 - ispipe =3D format_corename(&cn, &cprm, &argv, &argc); + retval =3D format_corename(&cn, &cprm, &argv, &argc); + if (retval < 0) { + coredump_report_failure("format_corename failed, aborting core"); + goto fail_unlock; + } =20 - if (ispipe) { + if (cn.core_type =3D=3D COREDUMP_PIPE) { int argi; int dump_count; char **helper_argv; struct subprocess_info *sub_info; =20 - if (ispipe < 0) { - coredump_report_failure("format_corename failed, aborting core"); - goto fail_unlock; - } - if (cprm.limit =3D=3D 1) { /* See umh_coredump_setup() which sets RLIMIT_CORE =3D 1. * @@ -695,7 +702,7 @@ void do_coredump(const kernel_siginfo_t *siginfo) coredump_report_failure("|%s pipe failed", cn.corename); goto close_fail; } - } else { + } else if (cn.core_type =3D=3D COREDUMP_FILE) { struct mnt_idmap *idmap; struct inode *inode; int open_flags =3D O_CREAT | O_WRONLY | O_NOFOLLOW | @@ -823,13 +830,13 @@ void do_coredump(const kernel_siginfo_t *siginfo) file_end_write(cprm.file); free_vma_snapshot(&cprm); } - if (ispipe && core_pipe_limit) + if ((cn.core_type =3D=3D COREDUMP_PIPE) && core_pipe_limit) wait_for_dump_helpers(cprm.file); close_fail: if (cprm.file) filp_close(cprm.file, NULL); fail_dropcount: - if (ispipe) + if (cn.core_type =3D=3D COREDUMP_PIPE) atomic_dec(&core_dump_count); fail_unlock: kfree(argv); --=20 2.47.2