forked from SUSE/qa_test_klp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathklp_test_livepatch.c
99 lines (83 loc) · 1.96 KB
/
klp_test_livepatch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* klp_test_livepatch - test livepatch template
*
* Copyright (c) 2017-2019 SUSE
* Authors: Libor Pechacek, Nicolai Stange
*/
/*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/livepatch.h>
#define PATCH_ID @@PATCH_ID@@
#include "klp_test_support_mod.h"
/* whether or not to identity-patch sys_getpid() */
#define PATCH_GETPID @@PATCH_GETPID@@
#define USE_OLD_REG_API @@USE_OLD_REG_API@@
#if PATCH_GETPID
asmlinkage static long PATCHED_SYM(@@SYSCALL_FN_PREFIX@@sys_getpid)(void)
{
return task_tgid_vnr(current);
}
static struct klp_func vmlinux_funcs[] = {
{
.old_name = "@@SYSCALL_FN_PREFIX@@sys_getpid",
.new_func = PATCHED_SYM(@@SYSCALL_FN_PREFIX@@sys_getpid),
},
{}
};
#endif /* PATCH_GETPID */
static struct klp_func klp_test_support_mod_funcs[] = {
@@PATCH_FUNCS@@
{}
};
static struct klp_object objs[] = {
#if PATCH_GETPID
{
/* name being NULL means vmlinux */
.funcs = vmlinux_funcs,
},
#endif /* PATCH_GETPID */
{
.name = "klp_test_support_mod",
.funcs = klp_test_support_mod_funcs,
},
{}
};
static struct klp_patch patch = {
.mod = THIS_MODULE,
.objs = objs,
.replace = @@PATCH_REPLACE_ALL@@,
};
static int livepatch_init(void)
{
#if USE_OLD_REG_API
int ret;
ret = klp_register_patch(&patch);
if (ret)
return ret;
ret = klp_enable_patch(&patch);
if (ret) {
WARN_ON(klp_unregister_patch(&patch));
return ret;
}
return 0;
#else
return klp_enable_patch(&patch);
#endif /* USE_OLD_REG_API */
}
static void livepatch_exit(void)
{
#if USE_OLD_REG_API
WARN_ON(klp_unregister_patch(&patch));
#endif /* USE_OLD_REG_API */
}
module_init(livepatch_init);
module_exit(livepatch_exit);
MODULE_LICENSE("GPL");
MODULE_INFO(livepatch, "Y");