1 #include <linux/slab.h>
5 #include <linux/stat.h>
6 #include <linux/fcntl.h>
8 #include <linux/string.h>
11 #include <linux/perf_event.h>
15 #include <linux/personality.h>
16 #include <linux/binfmts.h>
18 #include <linux/utsname.h>
20 #include <linux/module.h>
26 #include <linux/cn_proc.h>
27 #include <linux/audit.h>
33 #include <linux/oom.h>
36 #include <asm/uaccess.h>
37 #include <asm/mmu_context.h>
59 static int expand_corename(
struct core_name *cn)
74 static int cn_printf(
struct core_name *cn,
const char *
fmt, ...)
88 ret = expand_corename(cn);
104 static void cn_escape(
char *
str)
111 static int cn_print_exe_file(
struct core_name *cn)
113 struct file *exe_file;
114 char *pathbuf, *
path;
120 ret = cn_printf(cn,
"%s (path unknown)",
current->comm);
121 cn_escape(commstart);
139 ret = cn_printf(cn,
"%s", path);
156 int ispipe = (*pat_ptr ==
'|');
157 int pid_in_pattern = 0;
170 if (*pat_ptr !=
'%') {
173 err = cn_printf(cn,
"%c", *pat_ptr++);
175 switch (*++pat_ptr) {
181 err = cn_printf(cn,
"%c",
'%');
186 err = cn_printf(cn,
"%d",
191 err = cn_printf(cn,
"%d", cred->
uid);
195 err = cn_printf(cn,
"%d", cred->
gid);
198 err = cn_printf(cn,
"%d",
209 err = cn_printf(cn,
"%lu", tv.tv_sec);
216 err = cn_printf(cn,
"%s",
217 utsname()->nodename);
219 cn_escape(namestart);
225 err = cn_printf(cn,
"%s",
current->comm);
226 cn_escape(commstart);
230 err = cn_print_exe_file(cn);
234 err = cn_printf(cn,
"%lu",
253 err = cn_printf(cn,
".%d", task_tgid_vnr(
current));
268 start->
signal->group_stop_count = 0;
290 spin_lock_irq(&tsk->
sighand->siglock);
291 if (!signal_group_exit(tsk->
signal)) {
293 nr = zap_process(tsk, exit_code);
295 spin_unlock_irq(&tsk->
sighand->siglock);
341 lock_task_sighand(p, &flags);
342 nr += zap_process(p, exit_code);
343 unlock_task_sighand(p, &flags);
355 static int coredump_wait(
int exit_code,
struct core_state *core_state)
359 int core_waiters = -
EBUSY;
361 init_completion(&core_state->
startup);
362 core_state->
dumper.task = tsk;
367 core_waiters = zap_threads(tsk, mm, core_state, exit_code);
370 if (core_waiters > 0) {
379 ptr = core_state->
dumper.next;
380 while (ptr !=
NULL) {
381 wait_task_inactive(ptr->
task, 0);
389 static void coredump_finish(
struct mm_struct *mm)
395 while ((curr = next) !=
NULL) {
410 static void wait_for_dump_helpers(
struct file *
file)
414 pipe = file->
f_path.dentry->d_inode->i_pipe;
445 struct file *
files[2];
463 struct core_state core_state;
467 const struct cred *old_cred;
473 bool need_nonrelative =
false;
484 .mm_flags = mm->
flags,
508 need_nonrelative =
true;
511 retval = coredump_wait(siginfo->
si_signo, &core_state);
523 ispipe = format_corename(&cn, &cprm);
535 if (cprm.
limit == 1) {
552 "Process %d(%s) has RLIMIT_CORE set to 1\n",
589 if (need_nonrelative && cn.
corename[0] !=
'/') {
591 "to fully qualified path!\n",
600 if (IS_ERR(cprm.
file))
603 inode = cprm.
file->f_path.dentry->d_inode;
606 if (d_unhashed(cprm.
file->f_path.dentry))
620 if (!cprm.
file->f_op || !cprm.
file->f_op->write)
634 current->signal->group_exit_code |= 0x80;
637 wait_for_dump_helpers(cprm.
file);
679 unsigned long n = off;