// 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/ctype.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/sort.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/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/sysctl.h>#include<linux/elf.h>#include<linux/pidfs.h>#include<uapi/linux/pidfd.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>staticbooldump_vma_snapshot(structcoredump_params*cprm);staticvoidfree_vma_snapshot(structcoredump_params*cprm);#define CORE_FILE_NOTE_SIZE_DEFAULT (4*1024*1024)/* Define a reasonable max cap */#define CORE_FILE_NOTE_SIZE_MAX (16*1024*1024)/* * 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 3staticintcore_uses_pid;staticunsignedintcore_pipe_limit;staticunsignedintcore_sort_vma;staticcharcore_pattern[CORENAME_MAX_SIZE]="core";staticintcore_name_size=CORENAME_MAX_SIZE;unsignedintcore_file_note_size_limit=CORE_FILE_NOTE_SIZE_DEFAULT;structcore_name{char*corename;intused,size;};staticintexpand_corename(structcore_name*cn,intsize){char*corename;size=kmalloc_size_roundup(size);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=size;cn->corename=corename