Skip to content

Commit 046d662

Browse files
Alex Kellytorvalds
authored andcommitted
coredump: make core dump functionality optional
Adds an expert Kconfig option, CONFIG_COREDUMP, which allows disabling of core dump. This saves approximately 2.6k in the compiled kernel, and complements CONFIG_ELF_CORE, which now depends on it. CONFIG_COREDUMP also disables coredump-related sysctls, except for suid_dumpable and related functions, which are necessary for ptrace. [akpm@linux-foundation.org: fix binfmt_aout.c build] Signed-off-by: Alex Kelly <alex.page.kelly@gmail.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Acked-by: Kees Cook <keescook@chromium.org> Cc: Randy Dunlap <rdunlap@xenotime.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent db9aeca commit 046d662

6 files changed

Lines changed: 53 additions & 27 deletions

File tree

‎fs/Kconfig.binfmt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,11 @@ config BINFMT_MISC
164164
You may say M here for module support and later load the module when
165165
you have use for it; the module is called binfmt_misc. If you
166166
don't know what to answer at this point, say Y.
167+
168+
config COREDUMP
169+
bool "Enable core dump support" if EXPERT
170+
default y
171+
help
172+
This option enables support for performing core dumps. You almost
173+
certainly want to say Y here. Not necessary on systems that never
174+
need debugging or only ever run flawless code.

‎fs/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ obj-y := open.o read_write.o file_table.o super.o \
1111
attr.o bad_inode.o file.o filesystems.o namespace.o \
1212
seq_file.o xattr.o libfs.o fs-writeback.o \
1313
pnode.o drop_caches.o splice.o sync.o utimes.o \
14-
stack.o fs_struct.o statfs.o coredump.o
14+
stack.o fs_struct.o statfs.o
1515

1616
ifeq ($(CONFIG_BLOCK),y)
1717
obj-y += buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
@@ -48,6 +48,7 @@ obj-$(CONFIG_FS_MBCACHE) += mbcache.o
4848
obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o xattr_acl.o
4949
obj-$(CONFIG_NFS_COMMON) += nfs_common/
5050
obj-$(CONFIG_GENERIC_ACL) += generic_acl.o
51+
obj-$(CONFIG_COREDUMP) += coredump.o
5152

5253
obj-$(CONFIG_FHANDLE) += fhandle.o
5354

‎fs/binfmt_aout.c‎

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,8 @@
3232

3333
static int load_aout_binary(struct linux_binprm *, struct pt_regs * regs);
3434
static int load_aout_library(struct file*);
35-
static int aout_core_dump(struct coredump_params *cprm);
36-
37-
static struct linux_binfmt aout_format = {
38-
.module = THIS_MODULE,
39-
.load_binary = load_aout_binary,
40-
.load_shlib = load_aout_library,
41-
.core_dump = aout_core_dump,
42-
.min_coredump = PAGE_SIZE
43-
};
44-
45-
#define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
46-
47-
static int set_brk(unsigned long start, unsigned long end)
48-
{
49-
start = PAGE_ALIGN(start);
50-
end = PAGE_ALIGN(end);
51-
if (end > start) {
52-
unsigned long addr;
53-
addr = vm_brk(start, end - start);
54-
if (BAD_ADDR(addr))
55-
return addr;
56-
}
57-
return 0;
58-
}
5935

36+
#ifdef CONFIG_COREDUMP
6037
/*
6138
* Routine writes a core dump image in the current directory.
6239
* Currently only a stub-function.
@@ -66,7 +43,6 @@ static int set_brk(unsigned long start, unsigned long end)
6643
* field, which also makes sure the core-dumps won't be recursive if the
6744
* dumping of the process results in another error..
6845
*/
69-
7046
static int aout_core_dump(struct coredump_params *cprm)
7147
{
7248
struct file *file = cprm->file;
@@ -135,6 +111,32 @@ static int aout_core_dump(struct coredump_params *cprm)
135111
set_fs(fs);
136112
return has_dumped;
137113
}
114+
#else
115+
#define aout_core_dump NULL
116+
#endif
117+
118+
static struct linux_binfmt aout_format = {
119+
.module = THIS_MODULE,
120+
.load_binary = load_aout_binary,
121+
.load_shlib = load_aout_library,
122+
.core_dump = aout_core_dump,
123+
.min_coredump = PAGE_SIZE
124+
};
125+
126+
#define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
127+
128+
static int set_brk(unsigned long start, unsigned long end)
129+
{
130+
start = PAGE_ALIGN(start);
131+
end = PAGE_ALIGN(end);
132+
if (end > start) {
133+
unsigned long addr;
134+
addr = vm_brk(start, end - start);
135+
if (BAD_ADDR(addr))
136+
return addr;
137+
}
138+
return 0;
139+
}
138140

139141
/*
140142
* create_aout_tables() parses the env- and arg-strings in new user

‎include/linux/binfmts.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ extern int copy_strings_kernel(int argc, const char *const *argv,
132132
struct linux_binprm *bprm);
133133
extern int prepare_bprm_creds(struct linux_binprm *bprm);
134134
extern void install_exec_creds(struct linux_binprm *bprm);
135+
#ifdef CONFIG_COREDUMP
135136
extern void do_coredump(long signr, int exit_code, struct pt_regs *regs);
137+
#else
138+
static inline void do_coredump(long signr, int exit_code, struct pt_regs *regs) {}
139+
#endif
136140
extern void set_binfmt(struct linux_binfmt *new);
137141
extern void free_bprm(struct linux_binprm *);
138142

‎init/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,7 @@ config BUG
11991199
Just say Y.
12001200

12011201
config ELF_CORE
1202+
depends on COREDUMP
12021203
default y
12031204
bool "Enable ELF core dumps" if EXPERT
12041205
help

‎kernel/sysctl.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@
9797
extern int sysctl_overcommit_memory;
9898
extern int sysctl_overcommit_ratio;
9999
extern int max_threads;
100-
extern int core_uses_pid;
101100
extern int suid_dumpable;
101+
#ifdef CONFIG_COREDUMP
102+
extern int core_uses_pid;
102103
extern char core_pattern[];
103104
extern unsigned int core_pipe_limit;
105+
#endif
104106
extern int pid_max;
105107
extern int min_free_kbytes;
106108
extern int pid_max_min, pid_max_max;
@@ -177,8 +179,10 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
177179

178180
static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
179181
void __user *buffer, size_t *lenp, loff_t *ppos);
182+
#ifdef CONFIG_COREDUMP
180183
static int proc_dostring_coredump(struct ctl_table *table, int write,
181184
void __user *buffer, size_t *lenp, loff_t *ppos);
185+
#endif
182186

183187
#ifdef CONFIG_MAGIC_SYSRQ
184188
/* Note: sysrq code uses it's own private copy */
@@ -404,6 +408,7 @@ static struct ctl_table kern_table[] = {
404408
.mode = 0644,
405409
.proc_handler = proc_dointvec,
406410
},
411+
#ifdef CONFIG_COREDUMP
407412
{
408413
.procname = "core_uses_pid",
409414
.data = &core_uses_pid,
@@ -425,6 +430,7 @@ static struct ctl_table kern_table[] = {
425430
.mode = 0644,
426431
.proc_handler = proc_dointvec,
427432
},
433+
#endif
428434
#ifdef CONFIG_PROC_SYSCTL
429435
{
430436
.procname = "tainted",
@@ -2036,12 +2042,14 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
20362042

20372043
static void validate_coredump_safety(void)
20382044
{
2045+
#ifdef CONFIG_COREDUMP
20392046
if (suid_dumpable == SUID_DUMPABLE_SAFE &&
20402047
core_pattern[0] != '/' && core_pattern[0] != '|') {
20412048
printk(KERN_WARNING "Unsafe core_pattern used with "\
20422049
"suid_dumpable=2. Pipe handler or fully qualified "\
20432050
"core dump path required.\n");
20442051
}
2052+
#endif
20452053
}
20462054

20472055
static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
@@ -2053,6 +2061,7 @@ static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
20532061
return error;
20542062
}
20552063

2064+
#ifdef CONFIG_COREDUMP
20562065
static int proc_dostring_coredump(struct ctl_table *table, int write,
20572066
void __user *buffer, size_t *lenp, loff_t *ppos)
20582067
{
@@ -2061,6 +2070,7 @@ static int proc_dostring_coredump(struct ctl_table *table, int write,
20612070
validate_coredump_safety();
20622071
return error;
20632072
}
2073+
#endif
20642074

20652075
static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
20662076
void __user *buffer,

0 commit comments

Comments
 (0)