diff options
| -rw-r--r-- | MAINTAINERS | 1 | ||||
| -rw-r--r-- | samples/Kconfig | 7 | ||||
| -rw-r--r-- | samples/Makefile | 2 | ||||
| -rw-r--r-- | samples/livepatch/Makefile | 1 | ||||
| -rw-r--r-- | samples/livepatch/livepatch-sample.c | 87 |
5 files changed, 97 insertions, 1 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index df6a0784b466..afe93ead73f7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
| @@ -5795,6 +5795,7 @@ F: include/linux/livepatch.h | |||
| 5795 | F: arch/x86/include/asm/livepatch.h | 5795 | F: arch/x86/include/asm/livepatch.h |
| 5796 | F: arch/x86/kernel/livepatch.c | 5796 | F: arch/x86/kernel/livepatch.c |
| 5797 | F: Documentation/ABI/testing/sysfs-kernel-livepatch | 5797 | F: Documentation/ABI/testing/sysfs-kernel-livepatch |
| 5798 | F: samples/livepatch/ | ||
| 5798 | L: live-patching@vger.kernel.org | 5799 | L: live-patching@vger.kernel.org |
| 5799 | 5800 | ||
| 5800 | LLC (802.2) | 5801 | LLC (802.2) |
diff --git a/samples/Kconfig b/samples/Kconfig index 6181c2cc9ca0..0aed20df5f0b 100644 --- a/samples/Kconfig +++ b/samples/Kconfig | |||
| @@ -63,4 +63,11 @@ config SAMPLE_RPMSG_CLIENT | |||
| 63 | to communicate with an AMP-configured remote processor over | 63 | to communicate with an AMP-configured remote processor over |
| 64 | the rpmsg bus. | 64 | the rpmsg bus. |
| 65 | 65 | ||
| 66 | config SAMPLE_LIVE_PATCHING | ||
| 67 | tristate "Build live patching sample -- loadable modules only" | ||
| 68 | depends on LIVE_PATCHING && m | ||
| 69 | help | ||
| 70 | Builds a sample live patch that replaces the procfs handler | ||
| 71 | for /proc/cmdline to print "this has been live patched". | ||
| 72 | |||
| 66 | endif # SAMPLES | 73 | endif # SAMPLES |
diff --git a/samples/Makefile b/samples/Makefile index 1a60c62e2045..f00257bcc5a7 100644 --- a/samples/Makefile +++ b/samples/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # Makefile for Linux samples code | 1 | # Makefile for Linux samples code |
| 2 | 2 | ||
| 3 | obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ \ | 3 | obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \ |
| 4 | hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ | 4 | hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ |
diff --git a/samples/livepatch/Makefile b/samples/livepatch/Makefile new file mode 100644 index 000000000000..7f1cdc131a02 --- /dev/null +++ b/samples/livepatch/Makefile | |||
| @@ -0,0 +1 @@ | |||
| obj-$(CONFIG_SAMPLE_LIVE_PATCHING) += livepatch-sample.o | |||
diff --git a/samples/livepatch/livepatch-sample.c b/samples/livepatch/livepatch-sample.c new file mode 100644 index 000000000000..21f159d51074 --- /dev/null +++ b/samples/livepatch/livepatch-sample.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* | ||
| 2 | * livepatch-sample.c - Kernel Live Patching Sample Module | ||
| 3 | * | ||
| 4 | * Copyright (C) 2014 Seth Jennings <sjenning@redhat.com> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU General Public License | ||
| 8 | * as published by the Free Software Foundation; either version 2 | ||
| 9 | * of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <linux/module.h> | ||
| 21 | #include <linux/kernel.h> | ||
| 22 | #include <linux/livepatch.h> | ||
| 23 | |||
| 24 | /* | ||
| 25 | * This (dumb) live patch overrides the function that prints the | ||
| 26 | * kernel boot cmdline when /proc/cmdline is read. | ||
| 27 | * | ||
| 28 | * Example: | ||
| 29 | * $ cat /proc/cmdline | ||
| 30 | * <your cmdline> | ||
| 31 | * $ insmod livepatch-sample.ko | ||
| 32 | * $ cat /proc/cmdline | ||
| 33 | * this has been live patched | ||
| 34 | * $ echo 0 > /sys/kernel/livepatch/klp_sample/enabled | ||
| 35 | * <your cmdline> | ||
| 36 | */ | ||
| 37 | |||
| 38 | #include <linux/seq_file.h> | ||
| 39 | static int livepatch_cmdline_proc_show(struct seq_file *m, void *v) | ||
| 40 | { | ||
| 41 | seq_printf(m, "%s\n", "this has been live patched"); | ||
| 42 | return 0; | ||
| 43 | } | ||
| 44 | |||
| 45 | static struct klp_func funcs[] = { | ||
| 46 | { | ||
| 47 | .old_name = "cmdline_proc_show", | ||
| 48 | .new_func = livepatch_cmdline_proc_show, | ||
| 49 | }, { } | ||
| 50 | }; | ||
| 51 | |||
| 52 | static struct klp_object objs[] = { | ||
| 53 | { | ||
| 54 | /* name being NULL means vmlinux */ | ||
| 55 | .funcs = funcs, | ||
| 56 | }, { } | ||
| 57 | }; | ||
| 58 | |||
| 59 | static struct klp_patch patch = { | ||
| 60 | .mod = THIS_MODULE, | ||
| 61 | .objs = objs, | ||
| 62 | }; | ||
| 63 | |||
| 64 | static int livepatch_init(void) | ||
| 65 | { | ||
| 66 | int ret; | ||
| 67 | |||
| 68 | ret = klp_register_patch(&patch); | ||
| 69 | if (ret) | ||
| 70 | return ret; | ||
| 71 | ret = klp_enable_patch(&patch); | ||
| 72 | if (ret) { | ||
| 73 | WARN_ON(klp_unregister_patch(&patch)); | ||
| 74 | return ret; | ||
| 75 | } | ||
| 76 | return 0; | ||
| 77 | } | ||
| 78 | |||
| 79 | static void livepatch_exit(void) | ||
| 80 | { | ||
| 81 | WARN_ON(klp_disable_patch(&patch)); | ||
| 82 | WARN_ON(klp_unregister_patch(&patch)); | ||
| 83 | } | ||
| 84 | |||
| 85 | module_init(livepatch_init); | ||
| 86 | module_exit(livepatch_exit); | ||
| 87 | MODULE_LICENSE("GPL"); | ||
