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
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* Copyright (c) 2019 Amazon.com, Inc. or its affiliates. All rights reserved.
*
*/
#include "config.h"
#include <xen/lib.h>
#include <xen/types.h>
#include <xen/version.h>
#include <xen/livepatch.h>
#include <xen/livepatch_payload.h>
#include <public/sysctl.h>
static const char hello_world_patch_this_fnc[] = "xen_extra_version";
extern const char *xen_hello_world(void);
static int pre_apply_hook(livepatch_payload_t *payload)
{
int i;
printk(KERN_DEBUG "%s: Hook starting.\n", __func__);
for (i = 0; i < payload->nfuncs; i++)
{
struct livepatch_func *func = &payload->funcs[i];
BUG_ON(func->applied == LIVEPATCH_FUNC_APPLIED);
printk(KERN_DEBUG "%s: pre applied: %s\n", __func__, func->name);
}
printk(KERN_DEBUG "%s: Hook done.\n", __func__);
return 0;
}
static void post_apply_hook(livepatch_payload_t *payload)
{
int i;
printk(KERN_DEBUG "%s: Hook starting.\n", __func__);
for (i = 0; i < payload->nfuncs; i++)
{
struct livepatch_func *func = &payload->funcs[i];
BUG_ON(func->applied != LIVEPATCH_FUNC_APPLIED);
printk(KERN_DEBUG "%s: post applied: %s\n", __func__, func->name);
}
printk(KERN_DEBUG "%s: Hook done.\n", __func__);
}
static int pre_revert_hook(livepatch_payload_t *payload)
{
int i;
printk(KERN_DEBUG "%s: Hook starting.\n", __func__);
for (i = 0; i < payload->nfuncs; i++)
{
struct livepatch_func *func = &payload->funcs[i];
BUG_ON(func->applied != LIVEPATCH_FUNC_APPLIED);
printk(KERN_DEBUG "%s: pre reverted: %s\n", __func__, func->name);
}
printk(KERN_DEBUG "%s: Hook done.\n", __func__);
return 0;
}
static void post_revert_hook(livepatch_payload_t *payload)
{
int i;
printk(KERN_DEBUG "%s: Hook starting.\n", __func__);
for (i = 0; i < payload->nfuncs; i++)
{
struct livepatch_func *func = &payload->funcs[i];
BUG_ON(func->applied == LIVEPATCH_FUNC_APPLIED);
printk(KERN_DEBUG "%s: post reverted: %s\n", __func__, func->name);
}
printk(KERN_DEBUG "%s: Hook done.\n", __func__);
}
LIVEPATCH_PREAPPLY_HOOK(pre_apply_hook);
LIVEPATCH_POSTAPPLY_HOOK(post_apply_hook);
LIVEPATCH_PREREVERT_HOOK(pre_revert_hook);
LIVEPATCH_POSTREVERT_HOOK(post_revert_hook);
struct livepatch_func __section(".livepatch.funcs") livepatch_xen_hello_world = {
.version = LIVEPATCH_PAYLOAD_VERSION,
.name = hello_world_patch_this_fnc,
.new_addr = xen_hello_world,
.old_addr = xen_extra_version,
.new_size = NEW_CODE_SZ,
.old_size = OLD_CODE_SZ,
};
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
|