2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE
5 . $
(dirname $0)/functions.sh
7 MOD_LIVEPATCH
=test_klp_state
8 MOD_LIVEPATCH2
=test_klp_state2
9 MOD_LIVEPATCH3
=test_klp_state3
13 # TEST: Loading and removing a module that modifies the system state
15 echo -n "TEST: system state modification ... "
18 load_lp
$MOD_LIVEPATCH
19 disable_lp
$MOD_LIVEPATCH
20 unload_lp
$MOD_LIVEPATCH
22 check_result
"% modprobe $MOD_LIVEPATCH
23 livepatch: enabling patch '$MOD_LIVEPATCH'
24 livepatch: '$MOD_LIVEPATCH': initializing patching transition
25 $MOD_LIVEPATCH: pre_patch_callback: vmlinux
26 $MOD_LIVEPATCH: allocate_loglevel_state: allocating space to store console_loglevel
27 livepatch: '$MOD_LIVEPATCH': starting patching transition
28 livepatch: '$MOD_LIVEPATCH': completing patching transition
29 $MOD_LIVEPATCH: post_patch_callback: vmlinux
30 $MOD_LIVEPATCH: fix_console_loglevel: fixing console_loglevel
31 livepatch: '$MOD_LIVEPATCH': patching complete
32 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
33 livepatch: '$MOD_LIVEPATCH': initializing unpatching transition
34 $MOD_LIVEPATCH: pre_unpatch_callback: vmlinux
35 $MOD_LIVEPATCH: restore_console_loglevel: restoring console_loglevel
36 livepatch: '$MOD_LIVEPATCH': starting unpatching transition
37 livepatch: '$MOD_LIVEPATCH': completing unpatching transition
38 $MOD_LIVEPATCH: post_unpatch_callback: vmlinux
39 $MOD_LIVEPATCH: free_loglevel_state: freeing space for the stored console_loglevel
40 livepatch: '$MOD_LIVEPATCH': unpatching complete
41 % rmmod $MOD_LIVEPATCH"
44 # TEST: Take over system state change by a cumulative patch
46 echo -n "TEST: taking over system state modification ... "
49 load_lp
$MOD_LIVEPATCH
50 load_lp
$MOD_LIVEPATCH2
51 unload_lp
$MOD_LIVEPATCH
52 disable_lp
$MOD_LIVEPATCH2
53 unload_lp
$MOD_LIVEPATCH2
55 check_result
"% modprobe $MOD_LIVEPATCH
56 livepatch: enabling patch '$MOD_LIVEPATCH'
57 livepatch: '$MOD_LIVEPATCH': initializing patching transition
58 $MOD_LIVEPATCH: pre_patch_callback: vmlinux
59 $MOD_LIVEPATCH: allocate_loglevel_state: allocating space to store console_loglevel
60 livepatch: '$MOD_LIVEPATCH': starting patching transition
61 livepatch: '$MOD_LIVEPATCH': completing patching transition
62 $MOD_LIVEPATCH: post_patch_callback: vmlinux
63 $MOD_LIVEPATCH: fix_console_loglevel: fixing console_loglevel
64 livepatch: '$MOD_LIVEPATCH': patching complete
65 % modprobe $MOD_LIVEPATCH2
66 livepatch: enabling patch '$MOD_LIVEPATCH2'
67 livepatch: '$MOD_LIVEPATCH2': initializing patching transition
68 $MOD_LIVEPATCH2: pre_patch_callback: vmlinux
69 $MOD_LIVEPATCH2: allocate_loglevel_state: space to store console_loglevel already allocated
70 livepatch: '$MOD_LIVEPATCH2': starting patching transition
71 livepatch: '$MOD_LIVEPATCH2': completing patching transition
72 $MOD_LIVEPATCH2: post_patch_callback: vmlinux
73 $MOD_LIVEPATCH2: fix_console_loglevel: taking over the console_loglevel change
74 livepatch: '$MOD_LIVEPATCH2': patching complete
75 % rmmod $MOD_LIVEPATCH
76 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH2/enabled
77 livepatch: '$MOD_LIVEPATCH2': initializing unpatching transition
78 $MOD_LIVEPATCH2: pre_unpatch_callback: vmlinux
79 $MOD_LIVEPATCH2: restore_console_loglevel: restoring console_loglevel
80 livepatch: '$MOD_LIVEPATCH2': starting unpatching transition
81 livepatch: '$MOD_LIVEPATCH2': completing unpatching transition
82 $MOD_LIVEPATCH2: post_unpatch_callback: vmlinux
83 $MOD_LIVEPATCH2: free_loglevel_state: freeing space for the stored console_loglevel
84 livepatch: '$MOD_LIVEPATCH2': unpatching complete
85 % rmmod $MOD_LIVEPATCH2"
88 # TEST: Take over system state change by a cumulative patch
90 echo -n "TEST: compatible cumulative livepatches ... "
93 load_lp
$MOD_LIVEPATCH2
94 load_lp
$MOD_LIVEPATCH3
95 unload_lp
$MOD_LIVEPATCH2
96 load_lp
$MOD_LIVEPATCH2
97 disable_lp
$MOD_LIVEPATCH2
98 unload_lp
$MOD_LIVEPATCH2
99 unload_lp
$MOD_LIVEPATCH3
101 check_result
"% modprobe $MOD_LIVEPATCH2
102 livepatch: enabling patch '$MOD_LIVEPATCH2'
103 livepatch: '$MOD_LIVEPATCH2': initializing patching transition
104 $MOD_LIVEPATCH2: pre_patch_callback: vmlinux
105 $MOD_LIVEPATCH2: allocate_loglevel_state: allocating space to store console_loglevel
106 livepatch: '$MOD_LIVEPATCH2': starting patching transition
107 livepatch: '$MOD_LIVEPATCH2': completing patching transition
108 $MOD_LIVEPATCH2: post_patch_callback: vmlinux
109 $MOD_LIVEPATCH2: fix_console_loglevel: fixing console_loglevel
110 livepatch: '$MOD_LIVEPATCH2': patching complete
111 % modprobe $MOD_LIVEPATCH3
112 livepatch: enabling patch '$MOD_LIVEPATCH3'
113 livepatch: '$MOD_LIVEPATCH3': initializing patching transition
114 $MOD_LIVEPATCH3: pre_patch_callback: vmlinux
115 $MOD_LIVEPATCH3: allocate_loglevel_state: space to store console_loglevel already allocated
116 livepatch: '$MOD_LIVEPATCH3': starting patching transition
117 livepatch: '$MOD_LIVEPATCH3': completing patching transition
118 $MOD_LIVEPATCH3: post_patch_callback: vmlinux
119 $MOD_LIVEPATCH3: fix_console_loglevel: taking over the console_loglevel change
120 livepatch: '$MOD_LIVEPATCH3': patching complete
121 % rmmod $MOD_LIVEPATCH2
122 % modprobe $MOD_LIVEPATCH2
123 livepatch: enabling patch '$MOD_LIVEPATCH2'
124 livepatch: '$MOD_LIVEPATCH2': initializing patching transition
125 $MOD_LIVEPATCH2: pre_patch_callback: vmlinux
126 $MOD_LIVEPATCH2: allocate_loglevel_state: space to store console_loglevel already allocated
127 livepatch: '$MOD_LIVEPATCH2': starting patching transition
128 livepatch: '$MOD_LIVEPATCH2': completing patching transition
129 $MOD_LIVEPATCH2: post_patch_callback: vmlinux
130 $MOD_LIVEPATCH2: fix_console_loglevel: taking over the console_loglevel change
131 livepatch: '$MOD_LIVEPATCH2': patching complete
132 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH2/enabled
133 livepatch: '$MOD_LIVEPATCH2': initializing unpatching transition
134 $MOD_LIVEPATCH2: pre_unpatch_callback: vmlinux
135 $MOD_LIVEPATCH2: restore_console_loglevel: restoring console_loglevel
136 livepatch: '$MOD_LIVEPATCH2': starting unpatching transition
137 livepatch: '$MOD_LIVEPATCH2': completing unpatching transition
138 $MOD_LIVEPATCH2: post_unpatch_callback: vmlinux
139 $MOD_LIVEPATCH2: free_loglevel_state: freeing space for the stored console_loglevel
140 livepatch: '$MOD_LIVEPATCH2': unpatching complete
141 % rmmod $MOD_LIVEPATCH2
142 % rmmod $MOD_LIVEPATCH3"
145 # TEST: Failure caused by incompatible cumulative livepatches
147 echo -n "TEST: incompatible cumulative livepatches ... "
150 load_lp
$MOD_LIVEPATCH2
151 load_failing_mod
$MOD_LIVEPATCH
152 disable_lp
$MOD_LIVEPATCH2
153 unload_lp
$MOD_LIVEPATCH2
155 check_result
"% modprobe $MOD_LIVEPATCH2
156 livepatch: enabling patch '$MOD_LIVEPATCH2'
157 livepatch: '$MOD_LIVEPATCH2': initializing patching transition
158 $MOD_LIVEPATCH2: pre_patch_callback: vmlinux
159 $MOD_LIVEPATCH2: allocate_loglevel_state: allocating space to store console_loglevel
160 livepatch: '$MOD_LIVEPATCH2': starting patching transition
161 livepatch: '$MOD_LIVEPATCH2': completing patching transition
162 $MOD_LIVEPATCH2: post_patch_callback: vmlinux
163 $MOD_LIVEPATCH2: fix_console_loglevel: fixing console_loglevel
164 livepatch: '$MOD_LIVEPATCH2': patching complete
165 % modprobe $MOD_LIVEPATCH
166 livepatch: Livepatch patch ($MOD_LIVEPATCH) is not compatible with the already installed livepatches.
167 modprobe: ERROR: could not insert '$MOD_LIVEPATCH': Invalid argument
168 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH2/enabled
169 livepatch: '$MOD_LIVEPATCH2': initializing unpatching transition
170 $MOD_LIVEPATCH2: pre_unpatch_callback: vmlinux
171 $MOD_LIVEPATCH2: restore_console_loglevel: restoring console_loglevel
172 livepatch: '$MOD_LIVEPATCH2': starting unpatching transition
173 livepatch: '$MOD_LIVEPATCH2': completing unpatching transition
174 $MOD_LIVEPATCH2: post_unpatch_callback: vmlinux
175 $MOD_LIVEPATCH2: free_loglevel_state: freeing space for the stored console_loglevel
176 livepatch: '$MOD_LIVEPATCH2': unpatching complete
177 % rmmod $MOD_LIVEPATCH2"