* [PATCH v3] proc/kcore: allow disabling /proc/kcore at boot
@ 2026-11-17 10:20 Chris Down
2026-11-18 13:11 ` Christian Brauner
0 siblings, 1 reply; 3+ messages in thread
From: Chris Down @ 2026-11-17 10:20 UTC (permalink / raw)
To: Omar Sandoval, Andrew Morton
Cc: Jonathan Corbet, Shuah Khan, Randy Dunlap, linux-debuggers,
linux-fsdevel, linux-doc, linux-kernel, kernel-team
/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. In terms
of what it can read, /proc/kcore isn't any more concerning than other
ways to read kernel memory, like BPF with CAP_BPF and CAP_PERFMON. The
distinction is that a process with CAP_SYS_RAWIO doesn't necessarily
have CAP_BPF and CAP_PERFMON, because CAP_SYS_RAWIO may be needed for
hardware access without necessarily wanting to grant general RAM access.
CONFIG_STRICT_DEVMEM already makes that possible for /dev/mem, but
/proc/kcore gives the same capability to do general purpose RAM reading
anyway.
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, like kprobes and
bpf_probe_read_kernel()), or an 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, which lets us preserve those choices while using the same kernel
image.
Signed-off-by: Chris Down <chris@chrisdown.name>
---
v2 at https://lore.kernel.org/r/a8474f0e2d0ef5ea9d53aa6649c7e9c9ea6f15c2.1794800574.git.chris@chrisdown.name
v3: Make kcore_enabled __ro_after_init (Kees)
v2: Give more justification in changelog (Omar)
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 176648941aec..205228294fc2 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2902,6 +2902,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: <bool>
+ 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 3264c99bd68a..786c1209e224 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 __ro_after_init = true;
/*
* Returns > 0 for RAM pages, 0 for non-RAM pages, < 0 on error
@@ -722,8 +723,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: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] proc/kcore: allow disabling /proc/kcore at boot
2026-11-17 10:20 [PATCH v3] proc/kcore: allow disabling /proc/kcore at boot Chris Down
@ 2026-11-18 13:11 ` Christian Brauner
2026-11-23 6:11 ` Chris Down
0 siblings, 1 reply; 3+ messages in thread
From: Christian Brauner @ 2026-11-18 13:11 UTC (permalink / raw)
To: Chris Down
Cc: Omar Sandoval, Andrew Morton, Jonathan Corbet, Shuah Khan,
Randy Dunlap, linux-debuggers, linux-fsdevel, linux-doc,
linux-kernel, kernel-team
On Tue, Nov 17, 2026 at 02:20:38AM -0800, Chris Down wrote:
> /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. In terms
> of what it can read, /proc/kcore isn't any more concerning than other
> ways to read kernel memory, like BPF with CAP_BPF and CAP_PERFMON. The
> distinction is that a process with CAP_SYS_RAWIO doesn't necessarily
> have CAP_BPF and CAP_PERFMON, because CAP_SYS_RAWIO may be needed for
> hardware access without necessarily wanting to grant general RAM access.
> CONFIG_STRICT_DEVMEM already makes that possible for /dev/mem, but
> /proc/kcore gives the same capability to do general purpose RAM reading
> anyway.
>
> 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, like kprobes and
> bpf_probe_read_kernel()), or an 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, which lets us preserve those choices while using the same kernel
> image.
>
> Signed-off-by: Chris Down <chris@chrisdown.name>
> ---
> v2 at https://lore.kernel.org/r/a8474f0e2d0ef5ea9d53aa6649c7e9c9ea6f15c2.1794800574.git.chris@chrisdown.name
>
> v3: Make kcore_enabled __ro_after_init (Kees)
> v2: Give more justification in changelog (Omar)
>
> 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 176648941aec..205228294fc2 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -2902,6 +2902,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: <bool>
> + Default: on
So I'm happy to take this on top of vfs-7.5.procfs but I'm really
unhappy about this proliferation of various hyper-specific opt-outs.
For example, we already have:
enum proc_mem_force {
PROC_MEM_FORCE_ALWAYS,
PROC_MEM_FORCE_PTRACE,
PROC_MEM_FORCE_NEVER
};
static enum proc_mem_force proc_mem_force_override __ro_after_init =
IS_ENABLED(CONFIG_PROC_MEM_NO_FORCE) ? PROC_MEM_FORCE_NEVER :
IS_ENABLED(CONFIG_PROC_MEM_FORCE_PTRACE) ? PROC_MEM_FORCE_PTRACE :
PROC_MEM_FORCE_ALWAYS;
to block FOLL_FORCE access on kernels which is another huge proc-based
attack surface. My thesis is that if one is worried about /proc/kcore
readout attacks they should be equally worried about these types of
attacks.
Iow, it would be nicer if someone took the time and came up with some
boot setting that is a list of memory protection settings instead of
spraying ever more kernel command line switches that nobody can
reasonably remember or use.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] proc/kcore: allow disabling /proc/kcore at boot
2026-11-18 13:11 ` Christian Brauner
@ 2026-11-23 6:11 ` Chris Down
0 siblings, 0 replies; 3+ messages in thread
From: Chris Down @ 2026-11-23 6:11 UTC (permalink / raw)
To: Christian Brauner
Cc: Omar Sandoval, Andrew Morton, Jonathan Corbet, Shuah Khan,
Randy Dunlap, linux-debuggers, linux-fsdevel, linux-doc,
linux-kernel, kernel-team
Hi Christian,
Thanks for picking this up!
Christian Brauner writes:
>Iow, it would be nicer if someone took the time and came up with some
>boot setting that is a list of memory protection settings instead of
>spraying ever more kernel command line switches that nobody can
>reasonably remember or use.
Hmm, I agree that would be nicer, but I don't see a good way to do it. How
would you suggest going about it?
In my mind, the model one would have for a list like that is mitigations=,
but it didn't replace the specific switches, right? For example, retbleed=
and mds= have nevertheless stayed. In that case, the list sets their
defaults, but more specific switches win out over it.
These are the problems I see with a list like that:
1. I don't know where the list would live. A list of memory protection
settings in procfs would cover two switches today (that is, kcore= and
proc_mem.force_override=). Anything wider crosses into mm and security
(I have similar switches out for slab hardening and mseal, for example),
and it isn't clear to me who would own that or decide what goes on it.
2. Lockdown already has a list of what gives access to kernel memory,
with entries for /proc/kcore, /dev/mem, kprobes and so on (although
not for FOLL_FORCE), but lockdown= only takes the two levels.
Selecting individual entries was proposed last year, and the lockdown
maintainers turned it down because most entries can be bypassed when
they are used on their own [1]. So a wider list would have to be a
second one next to lockdown's.
Did you have something specific in mind in terms of a design and what it
would encompass?
Chris
[1] https://lore.kernel.org/r/2vldrnqs6fbljqqp6vbwmkushx6dxcpephgb6svmu5i64lijpy@lg37aflddv3b
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-23 6:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 10:20 [PATCH v3] proc/kcore: allow disabling /proc/kcore at boot Chris Down
2026-11-18 13:11 ` Christian Brauner
2026-11-23 6:11 ` Chris Down
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®