fs/coredump.c
Source file repositories/reference/linux-study-clean/fs/coredump.c
File Facts
- System
- Linux kernel
- Corpus path
fs/coredump.c- Extension
.c- Size
- 44947 bytes
- Lines
- 1784
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/file.hlinux/fdtable.hlinux/freezer.hlinux/mm.hlinux/stat.hlinux/fcntl.hlinux/swap.hlinux/ctype.hlinux/string.hlinux/init.hlinux/pagemap.hlinux/perf_event.hlinux/highmem.hlinux/spinlock.hlinux/key.hlinux/personality.hlinux/binfmts.hlinux/coredump.hlinux/sort.hlinux/sched/coredump.hlinux/sched/signal.hlinux/sched/task_stack.hlinux/utsname.hlinux/pid_namespace.hlinux/module.hlinux/namei.hlinux/mount.hlinux/security.hlinux/syscalls.hlinux/tsacct_kern.hlinux/cn_proc.h
Detected Declarations
struct core_nameenum coredump_type_tfunction expand_corenamefunction __printffunction __printffunction __printffunction cn_print_exe_filefunction coredump_parsefunction zap_processfunction __for_each_threadfunction zap_threadsfunction coredump_waitfunction coredump_finishfunction dump_interruptedfunction wait_for_dump_helpersfunction umh_coredump_setupfunction coredump_sock_connectfunction coredump_sock_recvfunction coredump_sock_sendfunction coredump_sock_markfunction coredump_sock_waitfunction coredump_sock_shutdownfunction coredump_sock_requestfunction coredump_socketfunction coredump_sock_waitfunction coredump_force_suid_safefunction coredump_filefunction coredump_pipefunction coredump_writefunction coredump_cleanupfunction coredump_skipfunction do_coredumpfunction vfs_coredumpfunction __dump_emitfunction __dump_skipfunction dump_emitfunction dump_skip_tofunction dump_skipfunction dump_emit_pagefunction dump_user_rangefunction dump_alignfunction validate_coredump_safetyfunction check_coredump_socketfunction proc_dostring_coredumpfunction init_fs_coredump_sysctlsfunction always_dump_vmafunction vma_dump_sizefunction free_vma_snapshot
Annotated Snippet
struct core_name {
char *corename __counted_by_ptr(size);
int used, size;
unsigned int core_pipe_limit;
bool core_dumped;
enum coredump_type_t core_type;
u64 mask;
};
static int expand_corename(struct core_name *cn, int size)
{
char *corename;
size = kmalloc_size_roundup(size);
corename = krealloc(cn->corename, size, GFP_KERNEL);
if (!corename)
return -ENOMEM;
cn->corename = corename;
cn->size = size;
if (size > core_name_size) /* racy but harmless */
core_name_size = size;
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.
*/
Annotation
- Immediate include surface: `linux/slab.h`, `linux/file.h`, `linux/fdtable.h`, `linux/freezer.h`, `linux/mm.h`, `linux/stat.h`, `linux/fcntl.h`, `linux/swap.h`.
- Detected declarations: `struct core_name`, `enum coredump_type_t`, `function expand_corename`, `function __printf`, `function __printf`, `function __printf`, `function cn_print_exe_file`, `function coredump_parse`, `function zap_process`, `function __for_each_thread`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.