Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kexec: add sysctl to disable kexec
@ 2013-12-09 23:38 Kees Cook
  2013-12-09 23:53 ` Rik van Riel
  2013-12-10  0:19 ` Khalid Aziz
  0 siblings, 2 replies; 4+ messages in thread
From: Kees Cook @ 2013-12-09 23:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Matthew Garrett, Rik van Riel, Peter Zijlstra, kexec,
	Eric Biederman, Andrew Morton, Ingo Molnar, Vivek Goyal,
	Mel Gorman

For general-purpose (i.e. distro) kernel builds it makes sense to build with
CONFIG_KEXEC to allow end users to choose what kind of things they want to do
with kexec. However, in the face of trying to lock down a system with such
a kernel, there needs to be a way to disable kexec (much like module loading
can be disabled). Without this, it is too easy for the root user to modify
kernel memory even when CONFIG_STRICT_DEVMEM and modules_disabled are set.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 include/linux/kexec.h |    1 +
 kernel/kexec.c        |    3 ++-
 kernel/sysctl.c       |   13 +++++++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index d78d28a733b1..a1503ed4dde5 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -170,6 +170,7 @@ unsigned long paddr_vmcoreinfo_note(void);
 
 extern struct kimage *kexec_image;
 extern struct kimage *kexec_crash_image;
+extern int kexec_disabled;
 
 #ifndef kexec_flush_icache_page
 #define kexec_flush_icache_page(page)
diff --git a/kernel/kexec.c b/kernel/kexec.c
index 490afc03627e..9d44ed203ee7 100644
--- a/kernel/kexec.c
+++ b/kernel/kexec.c
@@ -929,6 +929,7 @@ static int kimage_load_segment(struct kimage *image,
  */
 struct kimage *kexec_image;
 struct kimage *kexec_crash_image;
+int kexec_disabled;
 
 static DEFINE_MUTEX(kexec_mutex);
 
@@ -939,7 +940,7 @@ SYSCALL_DEFINE4(kexec_load, unsigned long, entry, unsigned long, nr_segments,
 	int result;
 
 	/* We only trust the superuser with rebooting the system. */
-	if (!capable(CAP_SYS_BOOT))
+	if (!capable(CAP_SYS_BOOT) || kexec_disabled)
 		return -EPERM;
 
 	/*
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 34a604726d0b..07869ce3642d 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -62,6 +62,7 @@
 #include <linux/capability.h>
 #include <linux/binfmts.h>
 #include <linux/sched/sysctl.h>
+#include <linux/kexec.h>
 
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -614,6 +615,18 @@ static struct ctl_table kern_table[] = {
 		.proc_handler	= proc_dointvec,
 	},
 #endif
+#ifdef CONFIG_KEXEC
+	{
+		.procname	= "kexec_disabled",
+		.data		= &kexec_disabled,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		/* only handle a transition from default "0" to "1" */
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= &one,
+		.extra2		= &one,
+	},
+#endif
 #ifdef CONFIG_MODULES
 	{
 		.procname	= "modprobe",
-- 
1.7.9.5


-- 
Kees Cook
Chrome OS Security

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kexec: add sysctl to disable kexec
  2013-12-09 23:38 [PATCH] kexec: add sysctl to disable kexec Kees Cook
@ 2013-12-09 23:53 ` Rik van Riel
  2013-12-10  0:15   ` Kees Cook
  2013-12-10  0:19 ` Khalid Aziz
  1 sibling, 1 reply; 4+ messages in thread
From: Rik van Riel @ 2013-12-09 23:53 UTC (permalink / raw)
  To: Kees Cook
  Cc: Matthew Garrett, Peter Zijlstra, kexec, linux-kernel,
	Eric Biederman, Andrew Morton, Ingo Molnar, Vivek Goyal,
	Mel Gorman

On 12/09/2013 06:38 PM, Kees Cook wrote:
> For general-purpose (i.e. distro) kernel builds it makes sense to build with
> CONFIG_KEXEC to allow end users to choose what kind of things they want to do
> with kexec. However, in the face of trying to lock down a system with such
> a kernel, there needs to be a way to disable kexec (much like module loading
> can be disabled). Without this, it is too easy for the root user to modify
> kernel memory even when CONFIG_STRICT_DEVMEM and modules_disabled are set.

Not everybody will be running with selinux, or another LSM security
policy, so having this simple knob probably makes sense.

OTOH, are the people who run without a fancy security people the
same people who are interested in locking down the system?

I guess I'll ack the patch, since I see no real downside to having
the knob...

> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Rik van Riel <riel@redhat.com>


-- 
All rights reversed

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kexec: add sysctl to disable kexec
  2013-12-09 23:53 ` Rik van Riel
@ 2013-12-10  0:15   ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2013-12-10  0:15 UTC (permalink / raw)
  To: Rik van Riel
  Cc: Matthew Garrett, Peter Zijlstra, kexec, LKML, Eric Biederman,
	Andrew Morton, Ingo Molnar, Vivek Goyal, Mel Gorman

On Mon, Dec 9, 2013 at 3:53 PM, Rik van Riel <riel@redhat.com> wrote:
> On 12/09/2013 06:38 PM, Kees Cook wrote:
>> For general-purpose (i.e. distro) kernel builds it makes sense to build with
>> CONFIG_KEXEC to allow end users to choose what kind of things they want to do
>> with kexec. However, in the face of trying to lock down a system with such
>> a kernel, there needs to be a way to disable kexec (much like module loading
>> can be disabled). Without this, it is too easy for the root user to modify
>> kernel memory even when CONFIG_STRICT_DEVMEM and modules_disabled are set.
>
> Not everybody will be running with selinux, or another LSM security
> policy, so having this simple knob probably makes sense.
>
> OTOH, are the people who run without a fancy security people the
> same people who are interested in locking down the system?
>
> I guess I'll ack the patch, since I see no real downside to having
> the knob...

Thanks! Yeah, there are cases of machines that are trying to be as
locked down as possible while still not having secure boot, etc. This
helps raise the bar for them.

>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>
> Acked-by: Rik van Riel <riel@redhat.com>

Thanks! I'm sending a v2 since I spaced out on updating the sysctl docs.

-Kees

-- 
Kees Cook
Chrome OS Security

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kexec: add sysctl to disable kexec
  2013-12-09 23:38 [PATCH] kexec: add sysctl to disable kexec Kees Cook
  2013-12-09 23:53 ` Rik van Riel
@ 2013-12-10  0:19 ` Khalid Aziz
  1 sibling, 0 replies; 4+ messages in thread
From: Khalid Aziz @ 2013-12-10  0:19 UTC (permalink / raw)
  To: Kees Cook
  Cc: Matthew Garrett, Rik van Riel, Peter Zijlstra, kexec,
	linux-kernel, Eric Biederman, Andrew Morton, Ingo Molnar,
	Vivek Goyal, Mel Gorman

On Mon, 2013-12-09 at 15:38 -0800, Kees Cook wrote:
> For general-purpose (i.e. distro) kernel builds it makes sense to build with
> CONFIG_KEXEC to allow end users to choose what kind of things they want to do
> with kexec. However, in the face of trying to lock down a system with such
> a kernel, there needs to be a way to disable kexec (much like module loading
> can be disabled). Without this, it is too easy for the root user to modify
> kernel memory even when CONFIG_STRICT_DEVMEM and modules_disabled are set.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>

Giving Sys admins more control to secure their system is a good idea.
This addition looks good to me.

--
Khalid


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-12-10  0:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-09 23:38 [PATCH] kexec: add sysctl to disable kexec Kees Cook
2013-12-09 23:53 ` Rik van Riel
2013-12-10  0:15   ` Kees Cook
2013-12-10  0:19 ` Khalid Aziz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox