From f4b979262fe08e94875dc5c85a9bd7cef784bf9c Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 5 Jun 2025 14:26:26 +0000 Subject: [PATCH] Revert "coredump: hand a pidfd to the usermode coredump helper" This reverts commit ac190912887386e77d5c95a8e001af7f6838f255 which is commit b5325b2a270fcaf7b2a9a0f23d422ca8a5a8bdea upstream. It breaks the Android kernel abi and can be brought back in the future in an abi-safe way if it is really needed. Bug: 161946584 Change-Id: I79cda13392f475443cb9b0aa701b9224df1fa39e Signed-off-by: Greg Kroah-Hartman --- fs/coredump.c | 78 ++++------------------------------------ include/linux/coredump.h | 1 - 2 files changed, 7 insertions(+), 72 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index b0d782367fcc..2e2b66aed59d 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include @@ -57,13 +56,6 @@ static bool dump_vma_snapshot(struct coredump_params *cprm); static void free_vma_snapshot(struct coredump_params *cprm); -/* - * 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; static char core_pattern[CORENAME_MAX_SIZE] = "core"; @@ -333,27 +325,6 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm, err = cn_printf(cn, "%lu", rlimit(RLIMIT_CORE)); 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; } @@ -508,7 +479,7 @@ static void wait_for_dump_helpers(struct file *file) } /* - * umh_coredump_setup + * umh_pipe_setup * helper function to customize the process used * to collect the core in userspace. Specifically * it sets up a pipe and installs it as fd 0 (stdin) @@ -518,62 +489,27 @@ static void wait_for_dump_helpers(struct file *file) * is a special value that we use to trap recursive * core dumps */ -static int umh_coredump_setup(struct subprocess_info *info, struct cred *new) +static int umh_pipe_setup(struct subprocess_info *info, struct cred *new) { struct file *files[2]; - struct file *pidfs_file = NULL; struct coredump_params *cp = (struct coredump_params *)info->data; int err; - if (cp->pid) { - int fd; - - fd = pidfd_prepare(cp->pid, 0, &pidfs_file); - if (fd < 0) - return fd; - - /* - * We don't care about the fd. We also cannot simply - * replace it below because dup2() will refuse to close - * this file descriptor if its in a larval state. So - * close it! - */ - put_unused_fd(fd); - - /* - * Usermode helpers are childen of either - * system_unbound_wq or of kthreadd. So we know that - * we're starting off with a clean file descriptor - * table. So we should always be able to use - * COREDUMP_PIDFD_NUMBER as our file descriptor value. - */ - err = replace_fd(COREDUMP_PIDFD_NUMBER, pidfs_file, 0); - if (err < 0) - goto out_fail; - - pidfs_file = NULL; - } - err = create_pipe_files(files, 0); if (err) - goto out_fail; + return err; cp->file = files[1]; err = replace_fd(0, files[0], 0); fput(files[0]); if (err < 0) - goto out_fail; + return err; /* and disallow core files too */ current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1}; - err = 0; - -out_fail: - if (pidfs_file) - fput(pidfs_file); - return err; + return 0; } void do_coredump(const kernel_siginfo_t *siginfo) @@ -649,7 +585,7 @@ void do_coredump(const kernel_siginfo_t *siginfo) } if (cprm.limit == 1) { - /* See umh_coredump_setup() which sets RLIMIT_CORE = 1. + /* See umh_pipe_setup() which sets RLIMIT_CORE = 1. * * Normally core limits are irrelevant to pipes, since * we're not writing to the file system, but we use @@ -694,7 +630,7 @@ void do_coredump(const kernel_siginfo_t *siginfo) retval = -ENOMEM; sub_info = call_usermodehelper_setup(helper_argv[0], helper_argv, NULL, GFP_KERNEL, - umh_coredump_setup, NULL, &cprm); + umh_pipe_setup, NULL, &cprm); if (sub_info) retval = call_usermodehelper_exec(sub_info, UMH_WAIT_EXEC); diff --git a/include/linux/coredump.h b/include/linux/coredump.h index 2b7ec58299ca..08a1d3e7e46d 100644 --- a/include/linux/coredump.h +++ b/include/linux/coredump.h @@ -28,7 +28,6 @@ struct coredump_params { int vma_count; size_t vma_data_size; struct core_vma_metadata *vma_meta; - struct pid *pid; }; /*