Fix access_ok() fallout for sparc32 and powerpc
[linux/fpc-iii.git] / samples / livepatch / livepatch-sample.c
blob2d554dd930e2857435bdb41f43335bfcc773fd5b
1 /*
2 * livepatch-sample.c - Kernel Live Patching Sample Module
4 * Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
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.
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.
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/>.
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/livepatch.h>
27 * This (dumb) live patch overrides the function that prints the
28 * kernel boot cmdline when /proc/cmdline is read.
30 * Example:
32 * $ cat /proc/cmdline
33 * <your cmdline>
35 * $ insmod livepatch-sample.ko
36 * $ cat /proc/cmdline
37 * this has been live patched
39 * $ echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled
40 * $ cat /proc/cmdline
41 * <your cmdline>
44 #include <linux/seq_file.h>
45 static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
47 seq_printf(m, "%s\n", "this has been live patched");
48 return 0;
51 static struct klp_func funcs[] = {
53 .old_name = "cmdline_proc_show",
54 .new_func = livepatch_cmdline_proc_show,
55 }, { }
58 static struct klp_object objs[] = {
60 /* name being NULL means vmlinux */
61 .funcs = funcs,
62 }, { }
65 static struct klp_patch patch = {
66 .mod = THIS_MODULE,
67 .objs = objs,
70 static int livepatch_init(void)
72 int ret;
74 ret = klp_register_patch(&patch);
75 if (ret)
76 return ret;
77 ret = klp_enable_patch(&patch);
78 if (ret) {
79 WARN_ON(klp_unregister_patch(&patch));
80 return ret;
82 return 0;
85 static void livepatch_exit(void)
87 WARN_ON(klp_unregister_patch(&patch));
90 module_init(livepatch_init);
91 module_exit(livepatch_exit);
92 MODULE_LICENSE("GPL");
93 MODULE_INFO(livepatch, "Y");