1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * livepatch-sample.c - Kernel Live Patching Sample Module
5 * Copyright (C) 2014 Seth Jennings <sjenning@redhat.com>
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/livepatch.h>
15 * This (dumb) live patch overrides the function that prints the
16 * kernel boot cmdline when /proc/cmdline is read.
23 * $ insmod livepatch-sample.ko
25 * this has been live patched
27 * $ echo 0 > /sys/kernel/livepatch/livepatch_sample/enabled
32 #include <linux/seq_file.h>
33 static int livepatch_cmdline_proc_show(struct seq_file
*m
, void *v
)
35 seq_printf(m
, "%s\n", "this has been live patched");
39 static struct klp_func funcs
[] = {
41 .old_name
= "cmdline_proc_show",
42 .new_func
= livepatch_cmdline_proc_show
,
46 static struct klp_object objs
[] = {
48 /* name being NULL means vmlinux */
53 static struct klp_patch patch
= {
58 static int livepatch_init(void)
60 return klp_enable_patch(&patch
);
63 static void livepatch_exit(void)
67 module_init(livepatch_init
);
68 module_exit(livepatch_exit
);
69 MODULE_LICENSE("GPL");
70 MODULE_INFO(livepatch
, "Y");