From: Christian Brauner <brauner@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-aio@kvack.org, linux-unionfs@vger.kernel.org,
linux-erofs@lists.ozlabs.org, linux-nfs@vger.kernel.org,
linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
cgroups@vger.kernel.org, netdev@vger.kernel.org,
linux-crypto@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
Christian Brauner <brauner@kernel.org>
Subject: [PATCH 08/12] coredump: split out do_coredump() from vfs_coredump()
Date: Mon, 03 Nov 2025 15:57:34 +0100 [thread overview]
Message-ID: <20251103-work-creds-guards-prepare_creds-v1-8-b447b82f2c9b@kernel.org> (raw)
In-Reply-To: <20251103-work-creds-guards-prepare_creds-v1-0-b447b82f2c9b@kernel.org>
Make the function easier to follow and prepare for some of the following
changes.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/coredump.c | 131 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 68 insertions(+), 63 deletions(-)
diff --git a/fs/coredump.c b/fs/coredump.c
index 8253b28bc728..79c681f1d647 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -1086,6 +1086,73 @@ static inline bool coredump_skip(const struct coredump_params *cprm,
return false;
}
+static void do_coredump(struct core_name *cn, struct coredump_params *cprm,
+ size_t **argv, int *argc, const struct linux_binfmt *binfmt)
+{
+ if (!coredump_parse(cn, cprm, argv, argc)) {
+ coredump_report_failure("format_corename failed, aborting core");
+ return;
+ }
+
+ switch (cn->core_type) {
+ case COREDUMP_FILE:
+ if (!coredump_file(cn, cprm, binfmt))
+ return;
+ break;
+ case COREDUMP_PIPE:
+ if (!coredump_pipe(cn, cprm, *argv, *argc))
+ return;
+ break;
+ case COREDUMP_SOCK_REQ:
+ fallthrough;
+ case COREDUMP_SOCK:
+ if (!coredump_socket(cn, cprm))
+ return;
+ break;
+ default:
+ WARN_ON_ONCE(true);
+ return;
+ }
+
+ /* Don't even generate the coredump. */
+ if (cn->mask & COREDUMP_REJECT)
+ return;
+
+ /* get us an unshared descriptor table; almost always a no-op */
+ /* The cell spufs coredump code reads the file descriptor tables */
+ if (unshare_files())
+ return;
+
+ if ((cn->mask & COREDUMP_KERNEL) && !coredump_write(cn, cprm, binfmt))
+ return;
+
+ coredump_sock_shutdown(cprm->file);
+
+ /* Let the parent know that a coredump was generated. */
+ if (cn->mask & COREDUMP_USERSPACE)
+ cn->core_dumped = true;
+
+ /*
+ * When core_pipe_limit is set we wait for the coredump server
+ * or usermodehelper to finish before exiting so it can e.g.,
+ * inspect /proc/<pid>.
+ */
+ if (cn->mask & COREDUMP_WAIT) {
+ switch (cn->core_type) {
+ case COREDUMP_PIPE:
+ wait_for_dump_helpers(cprm->file);
+ break;
+ case COREDUMP_SOCK_REQ:
+ fallthrough;
+ case COREDUMP_SOCK:
+ coredump_sock_wait(cprm->file);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
void vfs_coredump(const kernel_siginfo_t *siginfo)
{
struct cred *cred __free(put_cred) = NULL;
@@ -1133,70 +1200,8 @@ void vfs_coredump(const kernel_siginfo_t *siginfo)
old_cred = override_creds(cred);
- if (!coredump_parse(&cn, &cprm, &argv, &argc)) {
- coredump_report_failure("format_corename failed, aborting core");
- goto close_fail;
- }
-
- switch (cn.core_type) {
- case COREDUMP_FILE:
- if (!coredump_file(&cn, &cprm, binfmt))
- goto close_fail;
- break;
- case COREDUMP_PIPE:
- if (!coredump_pipe(&cn, &cprm, argv, argc))
- goto close_fail;
- break;
- case COREDUMP_SOCK_REQ:
- fallthrough;
- case COREDUMP_SOCK:
- if (!coredump_socket(&cn, &cprm))
- goto close_fail;
- break;
- default:
- WARN_ON_ONCE(true);
- goto close_fail;
- }
-
- /* Don't even generate the coredump. */
- if (cn.mask & COREDUMP_REJECT)
- goto close_fail;
-
- /* get us an unshared descriptor table; almost always a no-op */
- /* The cell spufs coredump code reads the file descriptor tables */
- if (unshare_files())
- goto close_fail;
-
- if ((cn.mask & COREDUMP_KERNEL) && !coredump_write(&cn, &cprm, binfmt))
- goto close_fail;
-
- coredump_sock_shutdown(cprm.file);
-
- /* Let the parent know that a coredump was generated. */
- if (cn.mask & COREDUMP_USERSPACE)
- cn.core_dumped = true;
-
- /*
- * When core_pipe_limit is set we wait for the coredump server
- * or usermodehelper to finish before exiting so it can e.g.,
- * inspect /proc/<pid>.
- */
- if (cn.mask & COREDUMP_WAIT) {
- switch (cn.core_type) {
- case COREDUMP_PIPE:
- wait_for_dump_helpers(cprm.file);
- break;
- case COREDUMP_SOCK_REQ:
- fallthrough;
- case COREDUMP_SOCK:
- coredump_sock_wait(cprm.file);
- break;
- default:
- break;
- }
- }
+ do_coredump(&cn, &cprm, &argv, &argc, binfmt);
-close_fail:
revert_creds(old_cred);
coredump_cleanup(&cn, &cprm);
return;
--
2.47.3
next prev parent reply other threads:[~2025-11-03 14:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-03 14:57 [PATCH 00/12] credential guards: credential preparation Christian Brauner
2025-11-03 14:57 ` [PATCH 01/12] cred: add prepare credential guard Christian Brauner
2025-11-03 14:57 ` [PATCH 02/12] sev-dev: use guard for path Christian Brauner
2025-11-03 14:57 ` [PATCH 03/12] sev-dev: use prepare credential guard Christian Brauner
2025-11-03 14:57 ` [PATCH 04/12] sev-dev: use override credential guards Christian Brauner
2025-11-03 14:57 ` [PATCH 05/12] coredump: move revert_cred() before coredump_cleanup() Christian Brauner
2025-11-03 14:57 ` [PATCH 06/12] coredump: pass struct linux_binfmt as const Christian Brauner
2025-11-03 14:57 ` [PATCH 07/12] coredump: mark struct mm_struct " Christian Brauner
2025-11-03 14:57 ` Christian Brauner [this message]
2025-11-03 14:57 ` [PATCH 09/12] coredump: use prepare credential guard Christian Brauner
2025-11-03 14:57 ` [PATCH 10/12] coredump: use override " Christian Brauner
2025-11-03 14:57 ` [PATCH 11/12] trace: use prepare " Christian Brauner
2025-11-03 16:09 ` Steven Rostedt
2025-11-03 14:57 ` [PATCH 12/12] trace: use override " Christian Brauner
2025-11-03 16:10 ` Steven Rostedt
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=20251103-work-creds-guards-prepare_creds-v1-8-b447b82f2c9b@kernel.org \
--to=brauner@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=linux-aio@kvack.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=samba-technical@lists.samba.org \
--cc=torvalds@linux-foundation.org \
/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