Revert "coredump: hand a pidfd to the usermode coredump helper"
This reverts commit cdb61a705f
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: I9ab9c7ee427a717644d3bce8f6a6b89839658be1
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
This commit is contained in:
@@ -42,7 +42,6 @@
|
|||||||
#include <linux/timekeeping.h>
|
#include <linux/timekeeping.h>
|
||||||
#include <linux/sysctl.h>
|
#include <linux/sysctl.h>
|
||||||
#include <linux/elf.h>
|
#include <linux/elf.h>
|
||||||
#include <uapi/linux/pidfd.h>
|
|
||||||
|
|
||||||
#include <linux/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
#include <asm/mmu_context.h>
|
#include <asm/mmu_context.h>
|
||||||
@@ -57,13 +56,6 @@
|
|||||||
static bool dump_vma_snapshot(struct coredump_params *cprm);
|
static bool dump_vma_snapshot(struct coredump_params *cprm);
|
||||||
static void free_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 int core_uses_pid;
|
||||||
static unsigned int core_pipe_limit;
|
static unsigned int core_pipe_limit;
|
||||||
static char core_pattern[CORENAME_MAX_SIZE] = "core";
|
static char core_pattern[CORENAME_MAX_SIZE] = "core";
|
||||||
@@ -340,27 +332,6 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm,
|
|||||||
case 'C':
|
case 'C':
|
||||||
err = cn_printf(cn, "%d", cprm->cpu);
|
err = cn_printf(cn, "%d", cprm->cpu);
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -517,7 +488,7 @@ static void wait_for_dump_helpers(struct file *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* umh_coredump_setup
|
* umh_pipe_setup
|
||||||
* helper function to customize the process used
|
* helper function to customize the process used
|
||||||
* to collect the core in userspace. Specifically
|
* to collect the core in userspace. Specifically
|
||||||
* it sets up a pipe and installs it as fd 0 (stdin)
|
* it sets up a pipe and installs it as fd 0 (stdin)
|
||||||
@@ -527,62 +498,27 @@ static void wait_for_dump_helpers(struct file *file)
|
|||||||
* is a special value that we use to trap recursive
|
* is a special value that we use to trap recursive
|
||||||
* core dumps
|
* 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 *files[2];
|
||||||
struct file *pidfs_file = NULL;
|
|
||||||
struct coredump_params *cp = (struct coredump_params *)info->data;
|
struct coredump_params *cp = (struct coredump_params *)info->data;
|
||||||
int err;
|
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);
|
err = create_pipe_files(files, 0);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_fail;
|
return err;
|
||||||
|
|
||||||
cp->file = files[1];
|
cp->file = files[1];
|
||||||
|
|
||||||
err = replace_fd(0, files[0], 0);
|
err = replace_fd(0, files[0], 0);
|
||||||
fput(files[0]);
|
fput(files[0]);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto out_fail;
|
return err;
|
||||||
|
|
||||||
/* and disallow core files too */
|
/* and disallow core files too */
|
||||||
current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
|
current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
|
||||||
|
|
||||||
err = 0;
|
return 0;
|
||||||
|
|
||||||
out_fail:
|
|
||||||
if (pidfs_file)
|
|
||||||
fput(pidfs_file);
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_coredump(const kernel_siginfo_t *siginfo)
|
void do_coredump(const kernel_siginfo_t *siginfo)
|
||||||
@@ -658,7 +594,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cprm.limit == 1) {
|
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
|
* Normally core limits are irrelevant to pipes, since
|
||||||
* we're not writing to the file system, but we use
|
* we're not writing to the file system, but we use
|
||||||
@@ -703,7 +639,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)
|
|||||||
retval = -ENOMEM;
|
retval = -ENOMEM;
|
||||||
sub_info = call_usermodehelper_setup(helper_argv[0],
|
sub_info = call_usermodehelper_setup(helper_argv[0],
|
||||||
helper_argv, NULL, GFP_KERNEL,
|
helper_argv, NULL, GFP_KERNEL,
|
||||||
umh_coredump_setup, NULL, &cprm);
|
umh_pipe_setup, NULL, &cprm);
|
||||||
if (sub_info)
|
if (sub_info)
|
||||||
retval = call_usermodehelper_exec(sub_info,
|
retval = call_usermodehelper_exec(sub_info,
|
||||||
UMH_WAIT_EXEC);
|
UMH_WAIT_EXEC);
|
||||||
|
@@ -28,7 +28,6 @@ struct coredump_params {
|
|||||||
int vma_count;
|
int vma_count;
|
||||||
size_t vma_data_size;
|
size_t vma_data_size;
|
||||||
struct core_vma_metadata *vma_meta;
|
struct core_vma_metadata *vma_meta;
|
||||||
struct pid *pid;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user