aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeth Jennings <sjenning@redhat.com>2014-12-16 12:58:19 -0500
committerJiri Kosina <jkosina@suse.cz>2014-12-22 09:40:49 -0500
commitb700e7f03df5d92f85fa5247fe1f557528d3363d (patch)
treed6da8186d1bd9c42bbd5db9f23deeb1e47bb6dec
parentc5f4546593e9911800f0926c1090959b58bc5c93 (diff)
livepatch: kernel: add support for live patching
This commit introduces code for the live patching core. It implements an ftrace-based mechanism and kernel interface for doing live patching of kernel and kernel module functions. It represents the greatest common functionality set between kpatch and kgraft and can accept patches built using either method. This first version does not implement any consistency mechanism that ensures that old and new code do not run together. In practice, ~90% of CVEs are safe to apply in this way, since they simply add a conditional check. However, any function change that can not execute safely with the old version of the function can _not_ be safely applied in this version. [ jkosina@suse.cz: due to the number of contributions that got folded into this original patch from Seth Jennings, add SUSE's copyright as well, as discussed via e-mail ] Signed-off-by: Seth Jennings <sjenning@redhat.com> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Reviewed-by: Miroslav Benes <mbenes@suse.cz> Reviewed-by: Petr Mladek <pmladek@suse.cz> Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Signed-off-by: Miroslav Benes <mbenes@suse.cz> Signed-off-by: Petr Mladek <pmladek@suse.cz> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
-rw-r--r--Documentation/ABI/testing/sysfs-kernel-livepatch44
-rw-r--r--MAINTAINERS13
-rw-r--r--arch/x86/Kconfig3
-rw-r--r--arch/x86/include/asm/livepatch.h37
-rw-r--r--arch/x86/kernel/Makefile1
-rw-r--r--arch/x86/kernel/livepatch.c90
-rw-r--r--include/linux/livepatch.h133
-rw-r--r--kernel/Makefile1
-rw-r--r--kernel/livepatch/Kconfig18
-rw-r--r--kernel/livepatch/Makefile3
-rw-r--r--kernel/livepatch/core.c930
11 files changed, 1273 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-kernel-livepatch b/Documentation/ABI/testing/sysfs-kernel-livepatch
new file mode 100644
index 000000000000..5bf42a840b22
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-kernel-livepatch
@@ -0,0 +1,44 @@
1What: /sys/kernel/livepatch
2Date: Nov 2014
3KernelVersion: 3.19.0
4Contact: live-patching@vger.kernel.org
5Description:
6 Interface for kernel live patching
7
8 The /sys/kernel/livepatch directory contains subdirectories for
9 each loaded live patch module.
10
11What: /sys/kernel/livepatch/<patch>
12Date: Nov 2014
13KernelVersion: 3.19.0
14Contact: live-patching@vger.kernel.org
15Description:
16 The patch directory contains subdirectories for each kernel
17 object (vmlinux or a module) in which it patched functions.
18
19What: /sys/kernel/livepatch/<patch>/enabled
20Date: Nov 2014
21KernelVersion: 3.19.0
22Contact: live-patching@vger.kernel.org
23Description:
24 A writable attribute that indicates whether the patched
25 code is currently applied. Writing 0 will disable the patch
26 while writing 1 will re-enable the patch.
27
28What: /sys/kernel/livepatch/<patch>/<object>
29Date: Nov 2014
30KernelVersion: 3.19.0
31Contact: live-patching@vger.kernel.org
32Description:
33 The object directory contains subdirectories for each function
34 that is patched within the object.
35
36What: /sys/kernel/livepatch/<patch>/<object>/<function>
37Date: Nov 2014
38KernelVersion: 3.19.0
39Contact: live-patching@vger.kernel.org
40Description:
41 The function directory contains attributes regarding the
42 properties and state of the patched function.
43
44 There are currently no such attributes.
diff --git a/MAINTAINERS b/MAINTAINERS
index ddb9ac8d32b3..df6a0784b466 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5784,6 +5784,19 @@ F: Documentation/misc-devices/lis3lv02d
5784F: drivers/misc/lis3lv02d/ 5784F: drivers/misc/lis3lv02d/
5785F: drivers/platform/x86/hp_accel.c 5785F: drivers/platform/x86/hp_accel.c
5786 5786
5787LIVE PATCHING
5788M: Josh Poimboeuf <jpoimboe@redhat.com>
5789M: Seth Jennings <sjenning@redhat.com>
5790M: Jiri Kosina <jkosina@suse.cz>
5791M: Vojtech Pavlik <vojtech@suse.cz>
5792S: Maintained
5793F: kernel/livepatch/
5794F: include/linux/livepatch.h
5795F: arch/x86/include/asm/livepatch.h
5796F: arch/x86/kernel/livepatch.c
5797F: Documentation/ABI/testing/sysfs-kernel-livepatch
5798L: live-patching@vger.kernel.org
5799
5787LLC (802.2) 5800LLC (802.2)
5788M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> 5801M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
5789S: Maintained 5802S: Maintained
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ba397bde7948..460b31b79938 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -17,6 +17,7 @@ config X86_64
17 depends on 64BIT 17 depends on 64BIT
18 select X86_DEV_DMA_OPS 18 select X86_DEV_DMA_OPS
19 select ARCH_USE_CMPXCHG_LOCKREF 19 select ARCH_USE_CMPXCHG_LOCKREF
20 select ARCH_HAVE_LIVE_PATCHING
20 21
21### Arch settings 22### Arch settings
22config X86 23config X86
@@ -2008,6 +2009,8 @@ config CMDLINE_OVERRIDE
2008 This is used to work around broken boot loaders. This should 2009 This is used to work around broken boot loaders. This should
2009 be set to 'N' under normal conditions. 2010 be set to 'N' under normal conditions.
2010 2011
2012source "kernel/livepatch/Kconfig"
2013
2011endmenu 2014endmenu
2012 2015
2013config ARCH_ENABLE_MEMORY_HOTPLUG 2016config ARCH_ENABLE_MEMORY_HOTPLUG
diff --git a/arch/x86/include/asm/livepatch.h b/arch/x86/include/asm/livepatch.h
new file mode 100644
index 000000000000..d529db1b1edf
--- /dev/null
+++ b/arch/x86/include/asm/livepatch.h
@@ -0,0 +1,37 @@
1/*
2 * livepatch.h - x86-specific Kernel Live Patching Core
3 *
4 * Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
5 * Copyright (C) 2014 SUSE
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef _ASM_X86_LIVEPATCH_H
22#define _ASM_X86_LIVEPATCH_H
23
24#include <linux/module.h>
25
26#ifdef CONFIG_LIVE_PATCHING
27#ifndef CC_USING_FENTRY
28#error Your compiler must support -mfentry for live patching to work
29#endif
30extern int klp_write_module_reloc(struct module *mod, unsigned long type,
31 unsigned long loc, unsigned long value);
32
33#else
34#error Live patching support is disabled; check CONFIG_LIVE_PATCHING
35#endif
36
37#endif /* _ASM_X86_LIVEPATCH_H */
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 5d4502c8b983..316b34e74c15 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -63,6 +63,7 @@ obj-$(CONFIG_X86_MPPARSE) += mpparse.o
63obj-y += apic/ 63obj-y += apic/
64obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o 64obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o
65obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o 65obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
66obj-$(CONFIG_LIVE_PATCHING) += livepatch.o
66obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o 67obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
67obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o 68obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o
68obj-$(CONFIG_X86_TSC) += trace_clock.o 69obj-$(CONFIG_X86_TSC) += trace_clock.o
diff --git a/arch/x86/kernel/livepatch.c b/arch/x86/kernel/livepatch.c
new file mode 100644
index 000000000000..ff3c3101d003
--- /dev/null
+++ b/arch/x86/kernel/livepatch.c
@@ -0,0 +1,90 @@
1/*
2 * livepatch.c - x86-specific Kernel Live Patching Core
3 *
4 * Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
5 * Copyright (C) 2014 SUSE
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <linux/module.h>
22#include <linux/uaccess.h>
23#include <asm/cacheflush.h>
24#include <asm/page_types.h>
25#include <asm/elf.h>
26#include <asm/livepatch.h>
27
28/**