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 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/livepatch.h>
25 * This (dumb) live patch overrides the function that prints the
26 * kernel boot cmdline when /proc/cmdline is read.
33 * $ insmod livepatch-sample.ko
35 * this has been live patched
37 * $ echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled
42 #include <linux/seq_file.h>
43 static int livepatch_cmdline_proc_show(struct seq_file
*m
, void *v
)
45 seq_printf(m
, "%s\n", "this has been live patched");
49 static struct klp_func funcs
[] = {
51 .old_name
= "cmdline_proc_show",
52 .new_func
= livepatch_cmdline_proc_show
,
56 static struct klp_object objs
[] = {
58 /* name being NULL means vmlinux */
63 static struct klp_patch patch
= {
68 static int livepatch_init(void)
72 ret
= klp_register_patch(&patch
);
75 ret
= klp_enable_patch(&patch
);
77 WARN_ON(klp_unregister_patch(&patch
));
83 static void livepatch_exit(void)
85 WARN_ON(klp_disable_patch(&patch
));
86 WARN_ON(klp_unregister_patch(&patch
));
89 module_init(livepatch_init
);
90 module_exit(livepatch_exit
);
91 MODULE_LICENSE("GPL");