1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/livepatch.h>
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42#include <linux/seq_file.h>
43static int livepatch_cmdline_proc_show(struct seq_file *m, void *v)
44{
45 seq_printf(m, "%s\n", "this has been live patched");
46 return 0;
47}
48
49static struct klp_func funcs[] = {
50 {
51 .old_name = "cmdline_proc_show",
52 .new_func = livepatch_cmdline_proc_show,
53 }, { }
54};
55
56static struct klp_object objs[] = {
57 {
58
59 .funcs = funcs,
60 }, { }
61};
62
63static struct klp_patch patch = {
64 .mod = THIS_MODULE,
65 .objs = objs,
66};
67
68static int livepatch_init(void)
69{
70 int ret;
71
72 ret = klp_register_patch(&patch);
73 if (ret)
74 return ret;
75 ret = klp_enable_patch(&patch);
76 if (ret) {
77 WARN_ON(klp_unregister_patch(&patch));
78 return ret;
79 }
80 return 0;
81}
82
83static void livepatch_exit(void)
84{
85 WARN_ON(klp_disable_patch(&patch));
86 WARN_ON(klp_unregister_patch(&patch));
87}
88
89module_init(livepatch_init);
90module_exit(livepatch_exit);
91MODULE_LICENSE("GPL");
92MODULE_INFO(livepatch, "Y");
93