/proc/kcore lets any process with CAP_SYS_RAWIO read all of kernel memory. That's a pretty large read primitive for anyone who obtains CAP_SYS_RAWIO (and it also gives away the KASLR layout). For this reason on some hosts we want to turn /proc/kcore off. However, on a kernel built with CONFIG_PROC_KCORE=y the only ways to block it today are lockdown=confidentiality (which also disables many other things we perhaps don't want to disable), or LSM. That's annoying, because on the majority of hosts we do want it on for things like drgn/crash, so today we build two separate kernels. Let's add a "kcore=" boot parameter so that this can be disabled at boot. Signed-off-by: Chris Down --- Documentation/admin-guide/kernel-parameters.txt | 6 ++++++ fs/proc/kcore.c | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index e75344f4e0cd..d8acce2878ab 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2915,6 +2915,12 @@ Kernel parameters parameter KASAN will print report only for the first invalid access. + kcore= [KNL,EARLY] + Enable or disable /proc/kcore on kernels built with + CONFIG_PROC_KCORE=y. + Format: + Default: on + keep_bootcon [KNL,EARLY] Do not unregister boot console at start. This is only useful for debugging when something happens in the window diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c index 390547b992ac..6a29a3e0ed92 100644 --- a/fs/proc/kcore.c +++ b/fs/proc/kcore.c @@ -69,6 +69,7 @@ static size_t kcore_notes_len; static size_t kcore_data_offset; DEFINE_STATIC_PERCPU_RWSEM(kclist_lock); static int kcore_need_update = 1; +static bool kcore_enabled __initdata = true; /* * Returns > 0 for RAM pages, 0 for non-RAM pages, < 0 on error @@ -720,8 +721,19 @@ static void __init add_modules_range(void) } #endif +static int __init parse_kcore(char *str) +{ + return kstrtobool(str, &kcore_enabled); +} +early_param("kcore", parse_kcore); + static int __init proc_kcore_init(void) { + if (!kcore_enabled) { + pr_info("/proc/kcore disabled on command line\n"); + return 0; + } + proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &kcore_proc_ops); if (!proc_root_kcore) { pr_err("couldn't create /proc/kcore\n"); base-commit: 01146870c415f6ff70a469fb7ceb962a3f2c8c52 -- 2.54.0