mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
* remotes/msm-4.9/tmp-39dae59: Linux 4.14-rc8 x86/module: Detect and skip invalid relocations objtool: Prevent GCC from merging annotate_unreachable(), take 2 Revert "x86/mm: Stop calling leave_mm() in idle code" Documentation: Add Frank Rowand to list of enforcement statement endorsers doc: add Willy Tarreau to the list of enforcement statement endorsers tools/headers: Synchronize kernel ABI headers objtool: Resync objtool's instruction decoder source code copy with the kernel's latest version Input: sparse-keymap - send sync event for KE_SW/KE_VSW Input: ar1021_i2c - set INPUT_PROP_DIRECT arch/tile: Implement ->set_state_oneshot_stopped() Update MIPS email addresses x86: CPU: Fix up "cpu MHz" in /proc/cpuinfo mm, swap: fix race between swap count continuation operations mm/huge_memory.c: deposit page table when copying a PMD migration entry initramfs: fix initramfs rebuilds w/ compression after disabling fs/hugetlbfs/inode.c: fix hwpoison reserve accounting ocfs2: fstrim: Fix start offset of first cluster group during fstrim mm, /proc/pid/pagemap: fix soft dirty marking for PMD migration entry userfaultfd: hugetlbfs: prevent UFFDIO_COPY to fill beyond the end of i_size Documentation: Add Tim Bird to list of enforcement statement endorsers net: systemport: Correct IPG length settings tcp: do not mangle skb->cb[] in tcp_make_synack() fib: fib_dump_info can no longer use __in_dev_get_rtnl stmmac: use of_property_read_u32 instead of read_u8 net_sched: hold netns refcnt for each action net_sched: acquire RTNL in tc_action_net_exit() powerpc/perf: Fix core-imc hotplug callback failure during imc initialization Kbuild: don't pass "-C" to preprocessor when processing linker scripts Revert "x86: do not use cpufreq_quick_get() for /proc/cpuinfo "cpu MHz"" arm64: ensure __dump_instr() checks addr_limit KVM: x86: Update APICv on APIC reset KVM: VMX: Do not fully reset PI descriptor on vCPU reset kvm: Return -ENODEV from update_persistent_clock futex: futex_wake_op, do not fail on invalid op MIPS: Update email address for Marcin Nowakowski License cleanup: add SPDX license identifier to uapi header files with a license License cleanup: add SPDX license identifier to uapi header files with no license License cleanup: add SPDX GPL-2.0 license identifier to files with no license KEYS: fix out-of-bounds read during ASN.1 parsing KEYS: trusted: fix writing past end of buffer in trusted_read() KEYS: return full count in keyring_read() if buffer is too small net: vrf: correct FRA_L3MDEV encode type tcp_nv: fix division by zero in tcpnv_acked() drm/amdgpu: allow harvesting check for Polaris VCE drm/amdgpu: return -ENOENT from uvd 6.0 early init for harvesting ARM: add debug ".edata_real" symbol MIPS: smp-cmp: Fix vpe_id build error MAINTAINERS: Update Pistachio platform maintainers MIPS: smp-cmp: Use right include for task_struct signal: Fix name of SIGEMT in #if defined() check MIPS: Update Goldfish RTC driver maintainer email address MIPS: Update RINT emulation maintainer email address MIPS: CPS: Fix use of current_cpu_data in preemptible code x86/mcelog: Get rid of RCU remnants watchdog/hardlockup/perf: Use atomics to track in-use cpu counter watchdog/harclockup/perf: Revert a33d44843d45 ("watchdog/hardlockup/perf: Simplify deferred event destroy") ARM: 8716/1: pass endianness info to sparse drm/i915: Check incoming alignment for unfenced buffers (on i915gm) x86/mm: fix use-after-free of vma during userfaultfd fault ide:ide-cd: fix kernel panic resulting from missing scsi_req_init mmc: dw_mmc: Fix the DTO timeout calculation tcp: fix tcp_mtu_probe() vs highest_sack ipv6: addrconf: increment ifp refcount before ipv6_del_addr() tun/tap: sanitize TUNSETSNDBUF input mlxsw: i2c: Fix buffer increment counter for write transaction netfilter: nf_reject_ipv4: Fix use-after-free in send_reset futex: Fix more put_pi_state() vs. exit_pi_state_list() races powerpc/kprobes: Dereference function pointers only if the address does not belong to kernel text Revert "powerpc64/elfv1: Only dereference function descriptor for non-text symbols" mlxsw: reg: Add high and low temperature thresholds MAINTAINERS: Remove Yotam from mlxfw MAINTAINERS: Update Yotam's E-mail net: hns: set correct return value net: lapbether: fix double free bpf: remove SK_REDIRECT from UAPI net: phy: marvell: Only configure RGMII delays when using RGMII MIPS: SMP: Fix deadlock & online race MIPS: bpf: Fix a typo in build_one_insn() MIPS: microMIPS: Fix incorrect mask in insn_table_MM MIPS: Fix CM region target definitions MIPS: generic: Fix compilation error from include asm/mips-cpc.h MIPS: Fix exception entry when CONFIG_EVA enabled irqchip/irq-mvebu-gicp: Add missing spin_lock init drm/nouveau/kms/nv50: use the correct state for base channel notifier setup MIPS: generic: Fix NI 169445 its build Update MIPS email addresses tile: pass machine size to sparse selftests: lib.mk: print individual test results to console by default RDMA/nldev: Enforce device index check for port callback Revert "PM / QoS: Fix device resume latency PM QoS" Revert "PM / QoS: Fix default runtime_pm device resume latency" scsi: qla2xxx: Fix oops in qla2x00_probe_one error path xfrm: Fix GSO for IPsec with GRE tunnel. ALSA: seq: Fix nested rwsem annotation for lockdep splat ALSA: timer: Add missing mutex lock for compat ioctls tc-testing: fix arg to ip command: -s -> -n net_sched: remove tcf_block_put_deferred() l2tp: hold tunnel in pppol2tp_connect() drm/i915: Hold rcu_read_lock when iterating over the radixtree (vma idr) drm/i915: Hold rcu_read_lock when iterating over the radixtree (objects) drm/i915/edp: read edp display control registers unconditionally drm/i915: Do not rely on wm preservation for ILK watermarks drm/i915: Cancel the modeset retry work during modeset cleanup Mark 'ioremap_page_range()' as possibly sleeping nvme: Fix setting logical block format when revalidating mmc: dw_mmc: Add locking to the CTO timer mmc: dw_mmc: Fix the CTO timeout calculation mmc: dw_mmc: cancel the CTO timer after a voltage switch perf/cgroup: Fix perf cgroup hierarchy support PM / QoS: Fix default runtime_pm device resume latency Revert "ath10k: fix napi_poll budget overflow" ath10k: rebuild crypto header in rx data frames cifs: check MaxPathNameComponentLength != 0 before using it KVM: arm/arm64: vgic-its: Check GITS_BASER Valid bit before saving tables KVM: arm/arm64: vgic-its: Check CBASER/BASER validity before enabling the ITS KVM: arm/arm64: vgic-its: Fix vgic_its_restore_collection_table returned value KVM: arm/arm64: vgic-its: Fix return value for device table restore efi/libstub: arm: omit sorting of the UEFI memory map perf tools: Unwind properly location after REJECT virtio_blk: Fix an SG_IO regression wcn36xx: Remove unnecessary rcu_read_unlock in wcn36xx_bss_info_changed ARM: dts: mvebu: pl310-cache disable double-linefill xfrm: Clear sk_dst_cache when applying per-socket policy. perf symbols: Fix memory corruption because of zero length symbols powerpc/64s/radix: Fix preempt imbalance in TLB flush netfilter: nft_set_hash: disable fast_ops for 2-len keys powerpc: Fix check for copy/paste instructions in alignment handler powerpc/perf: Fix IMC allocation routine xfrm: Fix xfrm_dst_cache memleak ARM: 8715/1: add a private asm/unaligned.h clk: uniphier: fix clock data for PXs3 Documentation: Add my name to kernel enforcement statement nvme-rdma: fix possible hang when issuing commands during ctrl removal arm/arm64: kvm: Disable branch profiling in HYP code arm/arm64: kvm: Move initialization completion message arm/arm64: KVM: set right LR register value for 32 bit guest when inject abort Documentation: kernel-enforcement-statement.rst: proper sort names ASoC: rt5616: fix 0x91 default value Documentation: Add Arm Ltd to kernel-enforcement-statement.rst arm64: dts: uniphier: add STDMAC clock to EHCI nodes ARM: dts: uniphier: add STDMAC clock to EHCI nodes mmc: renesas_sdhi: fix kernel panic in _internal_dmac.c mmc: tmio: fix swiotlb buffer is full Documentation: kernel-enforcement-statement.rst: Remove Red Hat markings Documentation: Add myself to the enforcement statement list Documentation: Sign kernel enforcement statement Add ack for Trond Myklebust to the enforcement statement Documentation: update kernel enforcement support list Documentation: add my name to supporters ASoC: rt5659: connect LOUT Amp with Charge Pump ASoC: rt5659: register power bit of LOUT Amp KVM: arm64: its: Fix missing dynamic allocation check in scan_its_table crypto: x86/chacha20 - satisfy stack validation 2.0 ASoC: rt5663: Change the dev getting function in rt5663_irq ASoC: rt5514: Revert Hotword Model control ASoC: topology: Fix a potential memory leak in 'soc_tplg_dapm_widget_denum_create()' ASoC: topology: Fix a potential NULL pointer dereference in 'soc_tplg_dapm_widget_denum_create()' ASoC: rt5514-spi: check irq status to schedule data copy ASoC: adau17x1: Workaround for noise bug in ADC Conflicts: drivers/gpu/drm/msm/Makefile drivers/soc/qcom/Makefile drivers/staging/android/ion/Makefile include/linux/coresight-stm.h include/trace/events/kmem.h Change-Id: I01f1779762b652b9213924caa3d54f29cf03d285 Signed-off-by: Runmin Wang <runminw@codeaurora.org>
857 lines
21 KiB
C
857 lines
21 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/slab.h>
|
|
#include <linux/file.h>
|
|
#include <linux/fdtable.h>
|
|
#include <linux/freezer.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/stat.h>
|
|
#include <linux/fcntl.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/string.h>
|
|
#include <linux/init.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/perf_event.h>
|
|
#include <linux/highmem.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/key.h>
|
|
#include <linux/personality.h>
|
|
#include <linux/binfmts.h>
|
|
#include <linux/coredump.h>
|
|
#include <linux/sched/coredump.h>
|
|
#include <linux/sched/signal.h>
|
|
#include <linux/sched/task_stack.h>
|
|
#include <linux/utsname.h>
|
|
#include <linux/pid_namespace.h>
|
|
#include <linux/module.h>
|
|
#include <linux/namei.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/security.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/tsacct_kern.h>
|
|
#include <linux/cn_proc.h>
|
|
#include <linux/audit.h>
|
|
#include <linux/tracehook.h>
|
|
#include <linux/kmod.h>
|
|
#include <linux/fsnotify.h>
|
|
#include <linux/fs_struct.h>
|
|
#include <linux/pipe_fs_i.h>
|
|
#include <linux/oom.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/path.h>
|
|
#include <linux/timekeeping.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
#include <asm/mmu_context.h>
|
|
#include <asm/tlb.h>
|
|
#include <asm/exec.h>
|
|
|
|
#include <trace/events/task.h>
|
|
#include "internal.h"
|
|
|
|
#include <trace/events/sched.h>
|
|
|
|
int core_uses_pid;
|
|
unsigned int core_pipe_limit;
|
|
char core_pattern[CORENAME_MAX_SIZE] = "core";
|
|
static int core_name_size = CORENAME_MAX_SIZE;
|
|
|
|
struct core_name {
|
|
char *corename;
|
|
int used, size;
|
|
};
|
|
|
|
/* The maximal length of core_pattern is also specified in sysctl.c */
|
|
|
|
static int expand_corename(struct core_name *cn, int size)
|
|
{
|
|
char *corename = krealloc(cn->corename, size, GFP_KERNEL);
|
|
|
|
if (!corename)
|
|
return -ENOMEM;
|
|
|
|
if (size > core_name_size) /* racy but harmless */
|
|
core_name_size = size;
|
|
|
|
cn->size = ksize(corename);
|
|
cn->corename = corename;
|
|
return 0;
|
|
}
|
|
|
|
static __printf(2, 0) int cn_vprintf(struct core_name *cn, const char *fmt,
|
|
va_list arg)
|
|
{
|
|
int free, need;
|
|
va_list arg_copy;
|
|
|
|
again:
|
|
free = cn->size - cn->used;
|
|
|
|
va_copy(arg_copy, arg);
|
|
need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
|
|
va_end(arg_copy);
|
|
|
|
if (need < free) {
|
|
cn->used += need;
|
|
return 0;
|
|
}
|
|
|
|
if (!expand_corename(cn, cn->size + need - free + 1))
|
|
goto again;
|
|
|
|
return -ENOMEM;
|
|
}
|
|
|
|
static __printf(2, 3) int cn_printf(struct core_name *cn, const char *fmt, ...)
|
|
{
|
|
va_list arg;
|
|
int ret;
|
|
|
|
va_start(arg, fmt);
|
|
ret = cn_vprintf(cn, fmt, arg);
|
|
va_end(arg);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static __printf(2, 3)
|
|
int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
|
|
{
|
|
int cur = cn->used;
|
|
va_list arg;
|
|
int ret;
|
|
|
|
va_start(arg, fmt);
|
|
ret = cn_vprintf(cn, fmt, arg);
|
|
va_end(arg);
|
|
|
|
if (ret == 0) {
|
|
/*
|
|
* Ensure that this coredump name component can't cause the
|
|
* resulting corefile path to consist of a ".." or ".".
|
|
*/
|
|
if ((cn->used - cur == 1 && cn->corename[cur] == '.') ||
|
|
(cn->used - cur == 2 && cn->corename[cur] == '.'
|
|
&& cn->corename[cur+1] == '.'))
|
|
cn->corename[cur] = '!';
|
|
|
|
/*
|
|
* Empty names are fishy and could be used to create a "//" in a
|
|
* corefile name, causing the coredump to happen one directory
|
|
* level too high. Enforce that all components of the core
|
|
* pattern are at least one character long.
|
|
*/
|
|
if (cn->used == cur)
|
|
ret = cn_printf(cn, "!");
|
|
}
|
|
|
|
for (; cur < cn->used; ++cur) {
|
|
if (cn->corename[cur] == '/')
|
|
cn->corename[cur] = '!';
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static int cn_print_exe_file(struct core_name *cn)
|
|
{
|
|
struct file *exe_file;
|
|
char *pathbuf, *path;
|
|
int ret;
|
|
|
|
exe_file = get_mm_exe_file(current->mm);
|
|
if (!exe_file)
|
|
return cn_esc_printf(cn, "%s (path unknown)", current->comm);
|
|
|
|
pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
|
|
if (!pathbuf) {
|
|
ret = -ENOMEM;
|
|
goto put_exe_file;
|
|
}
|
|
|
|
path = file_path(exe_file, pathbuf, PATH_MAX);
|
|
if (IS_ERR(path)) {
|
|
ret = PTR_ERR(path);
|
|
goto free_buf;
|
|
}
|
|
|
|
ret = cn_esc_printf(cn, "%s", path);
|
|
|
|
free_buf:
|
|
kfree(pathbuf);
|
|
put_exe_file:
|
|
fput(exe_file);
|
|
return ret;
|
|
}
|
|
|
|
/* format_corename will inspect the pattern parameter, and output a
|
|
* name into corename, which must have space for at least
|
|
* CORENAME_MAX_SIZE bytes plus one byte for the zero terminator.
|
|
*/
|
|
static int format_corename(struct core_name *cn, struct coredump_params *cprm)
|
|
{
|
|
const struct cred *cred = current_cred();
|
|
const char *pat_ptr = core_pattern;
|
|
int ispipe = (*pat_ptr == '|');
|
|
int pid_in_pattern = 0;
|
|
int err = 0;
|
|
|
|
cn->used = 0;
|
|
cn->corename = NULL;
|
|
if (expand_corename(cn, core_name_size))
|
|
return -ENOMEM;
|
|
cn->corename[0] = '\0';
|
|
|
|
if (ispipe)
|
|
++pat_ptr;
|
|
|
|
/* Repeat as long as we have more pattern to process and more output
|
|
space */
|
|
while (*pat_ptr) {
|
|
if (*pat_ptr != '%') {
|
|
err = cn_printf(cn, "%c", *pat_ptr++);
|
|
} else {
|
|
switch (*++pat_ptr) {
|
|
/* single % at the end, drop that */
|
|
case 0:
|
|
goto out;
|
|
/* Double percent, output one percent */
|
|
case '%':
|
|
err = cn_printf(cn, "%c", '%');
|
|
break;
|
|
/* pid */
|
|
case 'p':
|
|
pid_in_pattern = 1;
|
|
err = cn_printf(cn, "%d",
|
|
task_tgid_vnr(current));
|
|
break;
|
|
/* global pid */
|
|
case 'P':
|
|
err = cn_printf(cn, "%d",
|
|
task_tgid_nr(current));
|
|
break;
|
|
case 'i':
|
|
err = cn_printf(cn, "%d",
|
|
task_pid_vnr(current));
|
|
break;
|
|
case 'I':
|
|
err = cn_printf(cn, "%d",
|
|
task_pid_nr(current));
|
|
break;
|
|
/* uid */
|
|
case 'u':
|
|
err = cn_printf(cn, "%u",
|
|
from_kuid(&init_user_ns,
|
|
cred->uid));
|
|
break;
|
|
/* gid */
|
|
case 'g':
|
|
err = cn_printf(cn, "%u",
|
|
from_kgid(&init_user_ns,
|
|
cred->gid));
|
|
break;
|
|
case 'd':
|
|
err = cn_printf(cn, "%d",
|
|
__get_dumpable(cprm->mm_flags));
|
|
break;
|
|
/* signal that caused the coredump */
|
|
case 's':
|
|
err = cn_printf(cn, "%d",
|
|
cprm->siginfo->si_signo);
|
|
break;
|
|
/* UNIX time of coredump */
|
|
case 't': {
|
|
time64_t time;
|
|
|
|
time = ktime_get_real_seconds();
|
|
err = cn_printf(cn, "%lld", time);
|
|
break;
|
|
}
|
|
/* hostname */
|
|
case 'h':
|
|
down_read(&uts_sem);
|
|
err = cn_esc_printf(cn, "%s",
|
|
utsname()->nodename);
|
|
up_read(&uts_sem);
|
|
break;
|
|
/* executable */
|
|
case 'e':
|
|
err = cn_esc_printf(cn, "%s", current->comm);
|
|
break;
|
|
case 'E':
|
|
err = cn_print_exe_file(cn);
|
|
break;
|
|
/* core limit size */
|
|
case 'c':
|
|
err = cn_printf(cn, "%lu",
|
|
rlimit(RLIMIT_CORE));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
++pat_ptr;
|
|
}
|
|
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
out:
|
|
/* Backward compatibility with core_uses_pid:
|
|
*
|
|
* 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) {
|
|
err = cn_printf(cn, ".%d", task_tgid_vnr(current));
|
|
if (err)
|
|
return err;
|
|
}
|
|
return ispipe;
|
|
}
|
|
|
|
static int zap_process(struct task_struct *start, int exit_code, int flags)
|
|
{
|
|
struct task_struct *t;
|
|
int nr = 0;
|
|
|
|
/* ignore all signals except SIGKILL, see prepare_signal() */
|
|
start->signal->flags = SIGNAL_GROUP_COREDUMP | flags;
|
|
start->signal->group_exit_code = exit_code;
|
|
start->signal->group_stop_count = 0;
|
|
|
|
for_each_thread(start, t) {
|
|
task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK);
|
|
if (t != current && t->mm) {
|
|
sigaddset(&t->pending.signal, SIGKILL);
|
|
signal_wake_up(t, 1);
|
|
nr++;
|
|
}
|
|
}
|
|
|
|
return nr;
|
|
}
|
|
|
|
static int zap_threads(struct task_struct *tsk, struct mm_struct *mm,
|
|
struct core_state *core_state, int exit_code)
|
|
{
|
|
struct task_struct *g, *p;
|
|
unsigned long flags;
|
|
int nr = -EAGAIN;
|
|
|
|
spin_lock_irq(&tsk->sighand->siglock);
|
|
if (!signal_group_exit(tsk->signal)) {
|
|
mm->core_state = core_state;
|
|
tsk->signal->group_exit_task = tsk;
|
|
nr = zap_process(tsk, exit_code, 0);
|
|
clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
|
|
}
|
|
spin_unlock_irq(&tsk->sighand->siglock);
|
|
if (unlikely(nr < 0))
|
|
return nr;
|
|
|
|
tsk->flags |= PF_DUMPCORE;
|
|
if (atomic_read(&mm->mm_users) == nr + 1)
|
|
goto done;
|
|
/*
|
|
* We should find and kill all tasks which use this mm, and we should
|
|
* count them correctly into ->nr_threads. We don't take tasklist
|
|
* lock, but this is safe wrt:
|
|
*
|
|
* fork:
|
|
* None of sub-threads can fork after zap_process(leader). All
|
|
* processes which were created before this point should be
|
|
* visible to zap_threads() because copy_process() adds the new
|
|
* process to the tail of init_task.tasks list, and lock/unlock
|
|
* of ->siglock provides a memory barrier.
|
|
*
|
|
* do_exit:
|
|
* The caller holds mm->mmap_sem. This means that the task which
|
|
* uses this mm can't pass exit_mm(), so it can't exit or clear
|
|
* its ->mm.
|
|
*
|
|
* de_thread:
|
|
* It does list_replace_rcu(&leader->tasks, ¤t->tasks),
|
|
* we must see either old or new leader, this does not matter.
|
|
* However, it can change p->sighand, so lock_task_sighand(p)
|
|
* must be used. Since p->mm != NULL and we hold ->mmap_sem
|
|
* it can't fail.
|
|
*
|
|
* Note also that "g" can be the old leader with ->mm == NULL
|
|
* and already unhashed and thus removed from ->thread_group.
|
|
* This is OK, __unhash_process()->list_del_rcu() does not
|
|
* clear the ->next pointer, we will find the new leader via
|
|
* next_thread().
|
|
*/
|
|
rcu_read_lock();
|
|
for_each_process(g) {
|
|
if (g == tsk->group_leader)
|
|
continue;
|
|
if (g->flags & PF_KTHREAD)
|
|
continue;
|
|
|
|
for_each_thread(g, p) {
|
|
if (unlikely(!p->mm))
|
|
continue;
|
|
if (unlikely(p->mm == mm)) {
|
|
lock_task_sighand(p, &flags);
|
|
nr += zap_process(p, exit_code,
|
|
SIGNAL_GROUP_EXIT);
|
|
unlock_task_sighand(p, &flags);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
rcu_read_unlock();
|
|
done:
|
|
atomic_set(&core_state->nr_threads, nr);
|
|
return nr;
|
|
}
|
|
|
|
static int coredump_wait(int exit_code, struct core_state *core_state)
|
|
{
|
|
struct task_struct *tsk = current;
|
|
struct mm_struct *mm = tsk->mm;
|
|
int core_waiters = -EBUSY;
|
|
|
|
init_completion(&core_state->startup);
|
|
core_state->dumper.task = tsk;
|
|
core_state->dumper.next = NULL;
|
|
|
|
if (down_write_killable(&mm->mmap_sem))
|
|
return -EINTR;
|
|
|
|
if (!mm->core_state)
|
|
core_waiters = zap_threads(tsk, mm, core_state, exit_code);
|
|
up_write(&mm->mmap_sem);
|
|
|
|
if (core_waiters > 0) {
|
|
struct core_thread *ptr;
|
|
|
|
freezer_do_not_count();
|
|
wait_for_completion(&core_state->startup);
|
|
freezer_count();
|
|
/*
|
|
* Wait for all the threads to become inactive, so that
|
|
* all the thread context (extended register state, like
|
|
* fpu etc) gets copied to the memory.
|
|
*/
|
|
ptr = core_state->dumper.next;
|
|
while (ptr != NULL) {
|
|
wait_task_inactive(ptr->task, 0);
|
|
ptr = ptr->next;
|
|
}
|
|
}
|
|
|
|
return core_waiters;
|
|
}
|
|
|
|
static void coredump_finish(struct mm_struct *mm, bool core_dumped)
|
|
{
|
|
struct core_thread *curr, *next;
|
|
struct task_struct *task;
|
|
|
|
spin_lock_irq(¤t->sighand->siglock);
|
|
if (core_dumped && !__fatal_signal_pending(current))
|
|
current->signal->group_exit_code |= 0x80;
|
|
current->signal->group_exit_task = NULL;
|
|
current->signal->flags = SIGNAL_GROUP_EXIT;
|
|
spin_unlock_irq(¤t->sighand->siglock);
|
|
|
|
next = mm->core_state->dumper.next;
|
|
while ((curr = next) != NULL) {
|
|
next = curr->next;
|
|
task = curr->task;
|
|
/*
|
|
* see exit_mm(), curr->task must not see
|
|
* ->task == NULL before we read ->next.
|
|
*/
|
|
smp_mb();
|
|
curr->task = NULL;
|
|
wake_up_process(task);
|
|
}
|
|
|
|
mm->core_state = NULL;
|
|
}
|
|
|
|
static bool dump_interrupted(void)
|
|
{
|
|
/*
|
|
* SIGKILL or freezing() interrupt the coredumping. Perhaps we
|
|
* can do try_to_freeze() and check __fatal_signal_pending(),
|
|
* but then we need to teach dump_write() to restart and clear
|
|
* TIF_SIGPENDING.
|
|
*/
|
|
return signal_pending(current);
|
|
}
|
|
|
|
static void wait_for_dump_helpers(struct file *file)
|
|
{
|
|
struct pipe_inode_info *pipe = file->private_data;
|
|
|
|
pipe_lock(pipe);
|
|
pipe->readers++;
|
|
pipe->writers--;
|
|
wake_up_interruptible_sync(&pipe->wait);
|
|
kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
|
|
pipe_unlock(pipe);
|
|
|
|
/*
|
|
* We actually want wait_event_freezable() but then we need
|
|
* to clear TIF_SIGPENDING and improve dump_interrupted().
|
|
*/
|
|
wait_event_interruptible(pipe->wait, pipe->readers == 1);
|
|
|
|
pipe_lock(pipe);
|
|
pipe->readers--;
|
|
pipe->writers++;
|
|
pipe_unlock(pipe);
|
|
}
|
|
|
|
/*
|
|
* 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)
|
|
* for the process. Returns 0 on success, or
|
|
* PTR_ERR on failure.
|
|
* Note that it also sets the core limit to 1. This
|
|
* is a special value that we use to trap recursive
|
|
* core dumps
|
|
*/
|
|
static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
|
|
{
|
|
struct file *files[2];
|
|
struct coredump_params *cp = (struct coredump_params *)info->data;
|
|
int err = create_pipe_files(files, 0);
|
|
if (err)
|
|
return err;
|
|
|
|
cp->file = files[1];
|
|
|
|
err = replace_fd(0, files[0], 0);
|
|
fput(files[0]);
|
|
/* and disallow core files too */
|
|
current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
|
|
|
|
return err;
|
|
}
|
|
|
|
void do_coredump(const siginfo_t *siginfo)
|
|
{
|
|
struct core_state core_state;
|
|
struct core_name cn;
|
|
struct mm_struct *mm = current->mm;
|
|
struct linux_binfmt * binfmt;
|
|
const struct cred *old_cred;
|
|
struct cred *cred;
|
|
int retval = 0;
|
|
int ispipe;
|
|
struct files_struct *displaced;
|
|
/* require nonrelative corefile path and be extra careful */
|
|
bool need_suid_safe = false;
|
|
bool core_dumped = false;
|
|
static atomic_t core_dump_count = ATOMIC_INIT(0);
|
|
struct coredump_params cprm = {
|
|
.siginfo = siginfo,
|
|
.regs = signal_pt_regs(),
|
|
.limit = rlimit(RLIMIT_CORE),
|
|
/*
|
|
* We must use the same mm->flags while dumping core to avoid
|
|
* inconsistency of bit flags, since this flag is not protected
|
|
* by any locks.
|
|
*/
|
|
.mm_flags = mm->flags,
|
|
};
|
|
|
|
audit_core_dumps(siginfo->si_signo);
|
|
|
|
binfmt = mm->binfmt;
|
|
if (!binfmt || !binfmt->core_dump)
|
|
goto fail;
|
|
if (!__get_dumpable(cprm.mm_flags))
|
|
goto fail;
|
|
|
|
cred = prepare_creds();
|
|
if (!cred)
|
|
goto fail;
|
|
/*
|
|
* We cannot trust fsuid as being the "true" uid of the process
|
|
* nor do we know its entire history. We only know it was tainted
|
|
* so we dump it as root in mode 2, and only into a controlled
|
|
* environment (pipe handler or fully qualified path).
|
|
*/
|
|
if (__get_dumpable(cprm.mm_flags) == SUID_DUMP_ROOT) {
|
|
/* Setuid core dump mode */
|
|
cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
|
|
need_suid_safe = true;
|
|
}
|
|
|
|
retval = coredump_wait(siginfo->si_signo, &core_state);
|
|
if (retval < 0)
|
|
goto fail_creds;
|
|
|
|
old_cred = override_creds(cred);
|
|
|
|
ispipe = format_corename(&cn, &cprm);
|
|
|
|
if (ispipe) {
|
|
int dump_count;
|
|
char **helper_argv;
|
|
struct subprocess_info *sub_info;
|
|
|
|
if (ispipe < 0) {
|
|
printk(KERN_WARNING "format_corename failed\n");
|
|
printk(KERN_WARNING "Aborting core\n");
|
|
goto fail_unlock;
|
|
}
|
|
|
|
if (cprm.limit == 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
|
|
* cprm.limit of 1 here as a special value, this is a
|
|
* consistent way to catch recursive crashes.
|
|
* We can still crash if the core_pattern binary sets
|
|
* RLIM_CORE = !1, but it runs as root, and can do
|
|
* lots of stupid things.
|
|
*
|
|
* Note that we use task_tgid_vnr here to grab the pid
|
|
* of the process group leader. That way we get the
|
|
* right pid if a thread in a multi-threaded
|
|
* core_pattern process dies.
|
|
*/
|
|
printk(KERN_WARNING
|
|
"Process %d(%s) has RLIMIT_CORE set to 1\n",
|
|
task_tgid_vnr(current), current->comm);
|
|
printk(KERN_WARNING "Aborting core\n");
|
|
goto fail_unlock;
|
|
}
|
|
cprm.limit = RLIM_INFINITY;
|
|
|
|
dump_count = atomic_inc_return(&core_dump_count);
|
|
if (core_pipe_limit && (core_pipe_limit < dump_count)) {
|
|
printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
|
|
task_tgid_vnr(current), current->comm);
|
|
printk(KERN_WARNING "Skipping core dump\n");
|
|
goto fail_dropcount;
|
|
}
|
|
|
|
helper_argv = argv_split(GFP_KERNEL, cn.corename, NULL);
|
|
if (!helper_argv) {
|
|
printk(KERN_WARNING "%s failed to allocate memory\n",
|
|
__func__);
|
|
goto fail_dropcount;
|
|
}
|
|
|
|
retval = -ENOMEM;
|
|
sub_info = call_usermodehelper_setup(helper_argv[0],
|
|
helper_argv, NULL, GFP_KERNEL,
|
|
umh_pipe_setup, NULL, &cprm);
|
|
if (sub_info)
|
|
retval = call_usermodehelper_exec(sub_info,
|
|
UMH_WAIT_EXEC);
|
|
|
|
argv_free(helper_argv);
|
|
if (retval) {
|
|
printk(KERN_INFO "Core dump to |%s pipe failed\n",
|
|
cn.corename);
|
|
goto close_fail;
|
|
}
|
|
} else {
|
|
struct inode *inode;
|
|
int open_flags = O_CREAT | O_RDWR | O_NOFOLLOW |
|
|
O_LARGEFILE | O_EXCL;
|
|
|
|
if (cprm.limit < binfmt->min_coredump)
|
|
goto fail_unlock;
|
|
|
|
if (need_suid_safe && cn.corename[0] != '/') {
|
|
printk(KERN_WARNING "Pid %d(%s) can only dump core "\
|
|
"to fully qualified path!\n",
|
|
task_tgid_vnr(current), current->comm);
|
|
printk(KERN_WARNING "Skipping core dump\n");
|
|
goto fail_unlock;
|
|
}
|
|
|
|
/*
|
|
* Unlink the file if it exists unless this is a SUID
|
|
* binary - in that case, we're running around with root
|
|
* privs and don't want to unlink another user's coredump.
|
|
*/
|
|
if (!need_suid_safe) {
|
|
mm_segment_t old_fs;
|
|
|
|
old_fs = get_fs();
|
|
set_fs(KERNEL_DS);
|
|
/*
|
|
* If it doesn't exist, that's fine. If there's some
|
|
* other problem, we'll catch it at the filp_open().
|
|
*/
|
|
(void) sys_unlink((const char __user *)cn.corename);
|
|
set_fs(old_fs);
|
|
}
|
|
|
|
/*
|
|
* There is a race between unlinking and creating the
|
|
* file, but if that causes an EEXIST here, that's
|
|
* fine - another process raced with us while creating
|
|
* the corefile, and the other process won. To userspace,
|
|
* what matters is that at least one of the two processes
|
|
* writes its coredump successfully, not which one.
|
|
*/
|
|
if (need_suid_safe) {
|
|
/*
|
|
* Using user namespaces, normal user tasks can change
|
|
* their current->fs->root to point to arbitrary
|
|
* directories. Since the intention of the "only dump
|
|
* with a fully qualified path" rule is to control where
|
|
* coredumps may be placed using root privileges,
|
|
* current->fs->root must not be used. Instead, use the
|
|
* root directory of init_task.
|
|
*/
|
|
struct path root;
|
|
|
|
task_lock(&init_task);
|
|
get_fs_root(init_task.fs, &root);
|
|
task_unlock(&init_task);
|
|
cprm.file = file_open_root(root.dentry, root.mnt,
|
|
cn.corename, open_flags, 0600);
|
|
path_put(&root);
|
|
} else {
|
|
cprm.file = filp_open(cn.corename, open_flags, 0600);
|
|
}
|
|
if (IS_ERR(cprm.file))
|
|
goto fail_unlock;
|
|
|
|
inode = file_inode(cprm.file);
|
|
if (inode->i_nlink > 1)
|
|
goto close_fail;
|
|
if (d_unhashed(cprm.file->f_path.dentry))
|
|
goto close_fail;
|
|
/*
|
|
* AK: actually i see no reason to not allow this for named
|
|
* pipes etc, but keep the previous behaviour for now.
|
|
*/
|
|
if (!S_ISREG(inode->i_mode))
|
|
goto close_fail;
|
|
/*
|
|
* Don't dump core if the filesystem changed owner or mode
|
|
* of the file during file creation. This is an issue when
|
|
* a process dumps core while its cwd is e.g. on a vfat
|
|
* filesystem.
|
|
*/
|
|
if (!uid_eq(inode->i_uid, current_fsuid()))
|
|
goto close_fail;
|
|
if ((inode->i_mode & 0677) != 0600)
|
|
goto close_fail;
|
|
if (!(cprm.file->f_mode & FMODE_CAN_WRITE))
|
|
goto close_fail;
|
|
if (do_truncate2(cprm.file->f_path.mnt, cprm.file->f_path.dentry, 0, 0, cprm.file))
|
|
goto close_fail;
|
|
}
|
|
|
|
/* get us an unshared descriptor table; almost always a no-op */
|
|
retval = unshare_files(&displaced);
|
|
if (retval)
|
|
goto close_fail;
|
|
if (displaced)
|
|
put_files_struct(displaced);
|
|
if (!dump_interrupted()) {
|
|
file_start_write(cprm.file);
|
|
core_dumped = binfmt->core_dump(&cprm);
|
|
file_end_write(cprm.file);
|
|
}
|
|
if (ispipe && core_pipe_limit)
|
|
wait_for_dump_helpers(cprm.file);
|
|
close_fail:
|
|
if (cprm.file)
|
|
filp_close(cprm.file, NULL);
|
|
fail_dropcount:
|
|
if (ispipe)
|
|
atomic_dec(&core_dump_count);
|
|
fail_unlock:
|
|
kfree(cn.corename);
|
|
coredump_finish(mm, core_dumped);
|
|
revert_creds(old_cred);
|
|
fail_creds:
|
|
put_cred(cred);
|
|
fail:
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* Core dumping helper functions. These are the only things you should
|
|
* do on a core-file: use only these functions to write out all the
|
|
* necessary info.
|
|
*/
|
|
int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
|
|
{
|
|
struct file *file = cprm->file;
|
|
loff_t pos = file->f_pos;
|
|
ssize_t n;
|
|
if (cprm->written + nr > cprm->limit)
|
|
return 0;
|
|
while (nr) {
|
|
if (dump_interrupted())
|
|
return 0;
|
|
n = __kernel_write(file, addr, nr, &pos);
|
|
if (n <= 0)
|
|
return 0;
|
|
file->f_pos = pos;
|
|
cprm->written += n;
|
|
cprm->pos += n;
|
|
nr -= n;
|
|
}
|
|
return 1;
|
|
}
|
|
EXPORT_SYMBOL(dump_emit);
|
|
|
|
int dump_skip(struct coredump_params *cprm, size_t nr)
|
|
{
|
|
static char zeroes[PAGE_SIZE];
|
|
struct file *file = cprm->file;
|
|
if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
|
|
if (dump_interrupted() ||
|
|
file->f_op->llseek(file, nr, SEEK_CUR) < 0)
|
|
return 0;
|
|
cprm->pos += nr;
|
|
return 1;
|
|
} else {
|
|
while (nr > PAGE_SIZE) {
|
|
if (!dump_emit(cprm, zeroes, PAGE_SIZE))
|
|
return 0;
|
|
nr -= PAGE_SIZE;
|
|
}
|
|
return dump_emit(cprm, zeroes, nr);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(dump_skip);
|
|
|
|
int dump_align(struct coredump_params *cprm, int align)
|
|
{
|
|
unsigned mod = cprm->pos & (align - 1);
|
|
if (align & (align - 1))
|
|
return 0;
|
|
return mod ? dump_skip(cprm, align - mod) : 1;
|
|
}
|
|
EXPORT_SYMBOL(dump_align);
|
|
|
|
/*
|
|
* Ensures that file size is big enough to contain the current file
|
|
* postion. This prevents gdb from complaining about a truncated file
|
|
* if the last "write" to the file was dump_skip.
|
|
*/
|
|
void dump_truncate(struct coredump_params *cprm)
|
|
{
|
|
struct file *file = cprm->file;
|
|
loff_t offset;
|
|
|
|
if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
|
|
offset = file->f_op->llseek(file, 0, SEEK_CUR);
|
|
if (i_size_read(file->f_mapping->host) < offset)
|
|
do_truncate(file->f_path.dentry, offset, 0, file);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(dump_truncate);
|