|
41 | 41 | #include <linux/fs.h> |
42 | 42 | #include <linux/path.h> |
43 | 43 | #include <linux/timekeeping.h> |
| 44 | +#include <linux/sysctl.h> |
44 | 45 |
|
45 | 46 | #include <linux/uaccess.h> |
46 | 47 | #include <asm/mmu_context.h> |
|
52 | 53 |
|
53 | 54 | #include <trace/events/sched.h> |
54 | 55 |
|
55 | | -int core_uses_pid; |
56 | | -unsigned int core_pipe_limit; |
57 | | -char core_pattern[CORENAME_MAX_SIZE] = "core"; |
| 56 | +static int core_uses_pid; |
| 57 | +static unsigned int core_pipe_limit; |
| 58 | +static char core_pattern[CORENAME_MAX_SIZE] = "core"; |
58 | 59 | static int core_name_size = CORENAME_MAX_SIZE; |
59 | 60 |
|
60 | 61 | struct core_name { |
61 | 62 | char *corename; |
62 | 63 | int used, size; |
63 | 64 | }; |
64 | 65 |
|
65 | | -/* The maximal length of core_pattern is also specified in sysctl.c */ |
66 | | - |
67 | 66 | static int expand_corename(struct core_name *cn, int size) |
68 | 67 | { |
69 | 68 | char *corename = krealloc(cn->corename, size, GFP_KERNEL); |
@@ -893,6 +892,63 @@ int dump_align(struct coredump_params *cprm, int align) |
893 | 892 | } |
894 | 893 | EXPORT_SYMBOL(dump_align); |
895 | 894 |
|
| 895 | +#ifdef CONFIG_SYSCTL |
| 896 | + |
| 897 | +void validate_coredump_safety(void) |
| 898 | +{ |
| 899 | + if (suid_dumpable == SUID_DUMP_ROOT && |
| 900 | + core_pattern[0] != '/' && core_pattern[0] != '|') { |
| 901 | + pr_warn( |
| 902 | +"Unsafe core_pattern used with fs.suid_dumpable=2.\n" |
| 903 | +"Pipe handler or fully qualified core dump path required.\n" |
| 904 | +"Set kernel.core_pattern before fs.suid_dumpable.\n" |
| 905 | + ); |
| 906 | + } |
| 907 | +} |
| 908 | + |
| 909 | +static int proc_dostring_coredump(struct ctl_table *table, int write, |
| 910 | + void *buffer, size_t *lenp, loff_t *ppos) |
| 911 | +{ |
| 912 | + int error = proc_dostring(table, write, buffer, lenp, ppos); |
| 913 | + |
| 914 | + if (!error) |
| 915 | + validate_coredump_safety(); |
| 916 | + return error; |
| 917 | +} |
| 918 | + |
| 919 | +static struct ctl_table coredump_sysctls[] = { |
| 920 | + { |
| 921 | + .procname = "core_uses_pid", |
| 922 | + .data = &core_uses_pid, |
| 923 | + .maxlen = sizeof(int), |
| 924 | + .mode = 0644, |
| 925 | + .proc_handler = proc_dointvec, |
| 926 | + }, |
| 927 | + { |
| 928 | + .procname = "core_pattern", |
| 929 | + .data = core_pattern, |
| 930 | + .maxlen = CORENAME_MAX_SIZE, |
| 931 | + .mode = 0644, |
| 932 | + .proc_handler = proc_dostring_coredump, |
| 933 | + }, |
| 934 | + { |
| 935 | + .procname = "core_pipe_limit", |
| 936 | + .data = &core_pipe_limit, |
| 937 | + .maxlen = sizeof(unsigned int), |
| 938 | + .mode = 0644, |
| 939 | + .proc_handler = proc_dointvec, |
| 940 | + }, |
| 941 | + { } |
| 942 | +}; |
| 943 | + |
| 944 | +static int __init init_fs_coredump_sysctls(void) |
| 945 | +{ |
| 946 | + register_sysctl_init("kernel", coredump_sysctls); |
| 947 | + return 0; |
| 948 | +} |
| 949 | +fs_initcall(init_fs_coredump_sysctls); |
| 950 | +#endif /* CONFIG_SYSCTL */ |
| 951 | + |
896 | 952 | /* |
897 | 953 | * The purpose of always_dump_vma() is to make sure that special kernel mappings |
898 | 954 | * that are useful for post-mortem analysis are included in every core dump. |
|
0 commit comments