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