diff options
| author | Seth Jennings <sjenning@redhat.com> | 2014-12-16 12:58:19 -0500 |
|---|---|---|
| committer | Jiri Kosina <jkosina@suse.cz> | 2014-12-22 09:40:49 -0500 |
| commit | b700e7f03df5d92f85fa5247fe1f557528d3363d (patch) | |
| tree | d6da8186d1bd9c42bbd5db9f23deeb1e47bb6dec | |
| parent | c5f4546593e9911800f0926c1090959b58bc5c93 (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-livepatch | 44 | ||||
| -rw-r--r-- | MAINTAINERS | 13 | ||||
| -rw-r--r-- | arch/x86/Kconfig | 3 | ||||
| -rw-r--r-- | arch/x86/include/asm/livepatch.h | 37 | ||||
| -rw-r--r-- | arch/x86/kernel/Makefile | 1 | ||||
| -rw-r--r-- | arch/x86/kernel/livepatch.c | 90 | ||||
| -rw-r--r-- | include/linux/livepatch.h | 133 | ||||
| -rw-r--r-- | kernel/Makefile | 1 | ||||
| -rw-r--r-- | kernel/livepatch/Kconfig | 18 | ||||
| -rw-r--r-- | kernel/livepatch/Makefile | 3 | ||||
| -rw-r--r-- | kernel/livepatch/core.c | 930 |
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 @@ | |||
| 1 | What: /sys/kernel/livepatch | ||
| 2 | Date: Nov 2014 | ||
| 3 | KernelVersion: 3.19.0 | ||
| 4 | Contact: live-patching@vger.kernel.org | ||
| 5 | Description: | ||
| 6 | Interface for kernel live patching | ||
| 7 | |||
| 8 | The /sys/kernel/livepatch directory contains subdirectories for | ||
| 9 | each loaded live patch module. | ||
| 10 | |||
| 11 | What: /sys/kernel/livepatch/<patch> | ||
| 12 | Date: Nov 2014 | ||
| 13 | KernelVersion: 3.19.0 | ||
| 14 | Contact: live-patching@vger.kernel.org | ||
| 15 | Description: | ||
| 16 | The patch directory contains subdirectories for each kernel | ||
| 17 | object (vmlinux or a module) in which it patched functions. | ||
| 18 | |||
| 19 | What: /sys/kernel/livepatch/<patch>/enabled | ||
| 20 | Date: Nov 2014 | ||
| 21 | KernelVersion: 3.19.0 | ||
| 22 | Contact: live-patching@vger.kernel.org | ||
| 23 | Description: | ||
| 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 | |||
| 28 | What: /sys/kernel/livepatch/<patch>/<object> | ||
| 29 | Date: Nov 2014 | ||
| 30 | KernelVersion: 3.19.0 | ||
| 31 | Contact: live-patching@vger.kernel.org | ||
| 32 | Description: | ||
| 33 | The object directory contains subdirectories for each function | ||
| 34 | that is patched within the object. | ||
| 35 | |||
| 36 | What: /sys/kernel/livepatch/<patch>/<object>/<function> | ||
| 37 | Date: Nov 2014 | ||
| 38 | KernelVersion: 3.19.0 | ||
| 39 | Contact: live-patching@vger.kernel.org | ||
| 40 | Description: | ||
| 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 | |||
| 5784 | F: drivers/misc/lis3lv02d/ | 5784 | F: drivers/misc/lis3lv02d/ |
| 5785 | F: drivers/platform/x86/hp_accel.c | 5785 | F: drivers/platform/x86/hp_accel.c |
| 5786 | 5786 | ||
| 5787 | LIVE PATCHING | ||
| 5788 | M: Josh Poimboeuf <jpoimboe@redhat.com> | ||
| 5789 | M: Seth Jennings <sjenning@redhat.com> | ||
| 5790 | M: Jiri Kosina <jkosina@suse.cz> | ||
| 5791 | M: Vojtech Pavlik <vojtech@suse.cz> | ||
| 5792 | S: Maintained | ||
| 5793 | F: kernel/livepatch/ | ||
| 5794 | F: include/linux/livepatch.h | ||
| 5795 | F: arch/x86/include/asm/livepatch.h | ||
| 5796 | F: arch/x86/kernel/livepatch.c | ||
| 5797 | F: Documentation/ABI/testing/sysfs-kernel-livepatch | ||
| 5798 | L: live-patching@vger.kernel.org | ||
| 5799 | |||
| 5787 | LLC (802.2) | 5800 | LLC (802.2) |
| 5788 | M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> | 5801 | M: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> |
| 5789 | S: Maintained | 5802 | S: 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 |
| 22 | config X86 | 23 | config 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 | ||
| 2012 | source "kernel/livepatch/Kconfig" | ||
| 2013 | |||
| 2011 | endmenu | 2014 | endmenu |
| 2012 | 2015 | ||
| 2013 | config ARCH_ENABLE_MEMORY_HOTPLUG | 2016 | config 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 | ||
| 30 | extern 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 | |||
| 63 | obj-y += apic/ | 63 | obj-y += apic/ |
| 64 | obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o | 64 | obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o |
| 65 | obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o | 65 | obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o |
| 66 | obj-$(CONFIG_LIVE_PATCHING) += livepatch.o | ||
| 66 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o | 67 | obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o |
| 67 | obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o | 68 | obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o |
| 68 | obj-$(CONFIG_X86_TSC) += trace_clock.o | 69 | obj-$(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 | /** | ||
