• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3# Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
4
5. $(dirname $0)/functions.sh
6
7MOD_LIVEPATCH=test_klp_livepatch
8MOD_REPLACE=test_klp_atomic_replace
9
10setup_config
11
12
13# TEST: basic function patching
14# - load a livepatch that modifies the output from /proc/cmdline and
15#   verify correct behavior
16# - unload the livepatch and make sure the patch was removed
17
18echo -n "TEST: basic function patching ... "
19dmesg -C
20
21load_lp $MOD_LIVEPATCH
22
23if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then
24	echo -e "FAIL\n\n"
25	die "livepatch kselftest(s) failed"
26fi
27
28disable_lp $MOD_LIVEPATCH
29unload_lp $MOD_LIVEPATCH
30
31if [[ "$(cat /proc/cmdline)" == "$MOD_LIVEPATCH: this has been live patched" ]] ; then
32	echo -e "FAIL\n\n"
33	die "livepatch kselftest(s) failed"
34fi
35
36check_result "% modprobe $MOD_LIVEPATCH
37livepatch: enabling patch '$MOD_LIVEPATCH'
38livepatch: '$MOD_LIVEPATCH': initializing patching transition
39livepatch: '$MOD_LIVEPATCH': starting patching transition
40livepatch: '$MOD_LIVEPATCH': completing patching transition
41livepatch: '$MOD_LIVEPATCH': patching complete
42% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
43livepatch: '$MOD_LIVEPATCH': initializing unpatching transition
44livepatch: '$MOD_LIVEPATCH': starting unpatching transition
45livepatch: '$MOD_LIVEPATCH': completing unpatching transition
46livepatch: '$MOD_LIVEPATCH': unpatching complete
47% rmmod $MOD_LIVEPATCH"
48
49
50# TEST: multiple livepatches
51# - load a livepatch that modifies the output from /proc/cmdline and
52#   verify correct behavior
53# - load another livepatch and verify that both livepatches are active
54# - unload the second livepatch and verify that the first is still active
55# - unload the first livepatch and verify none are active
56
57echo -n "TEST: multiple livepatches ... "
58dmesg -C
59
60load_lp $MOD_LIVEPATCH
61
62grep 'live patched' /proc/cmdline > /dev/kmsg
63grep 'live patched' /proc/meminfo > /dev/kmsg
64
65load_lp $MOD_REPLACE replace=0
66
67grep 'live patched' /proc/cmdline > /dev/kmsg
68grep 'live patched' /proc/meminfo > /dev/kmsg
69
70disable_lp $MOD_REPLACE
71unload_lp $MOD_REPLACE
72
73grep 'live patched' /proc/cmdline > /dev/kmsg
74grep 'live patched' /proc/meminfo > /dev/kmsg
75
76disable_lp $MOD_LIVEPATCH
77unload_lp $MOD_LIVEPATCH
78
79grep 'live patched' /proc/cmdline > /dev/kmsg
80grep 'live patched' /proc/meminfo > /dev/kmsg
81
82check_result "% modprobe $MOD_LIVEPATCH
83livepatch: enabling patch '$MOD_LIVEPATCH'
84livepatch: '$MOD_LIVEPATCH': initializing patching transition
85livepatch: '$MOD_LIVEPATCH': starting patching transition
86livepatch: '$MOD_LIVEPATCH': completing patching transition
87livepatch: '$MOD_LIVEPATCH': patching complete
88$MOD_LIVEPATCH: this has been live patched
89% modprobe $MOD_REPLACE replace=0
90livepatch: enabling patch '$MOD_REPLACE'
91livepatch: '$MOD_REPLACE': initializing patching transition
92livepatch: '$MOD_REPLACE': starting patching transition
93livepatch: '$MOD_REPLACE': completing patching transition
94livepatch: '$MOD_REPLACE': patching complete
95$MOD_LIVEPATCH: this has been live patched
96$MOD_REPLACE: this has been live patched
97% echo 0 > /sys/kernel/livepatch/$MOD_REPLACE/enabled
98livepatch: '$MOD_REPLACE': initializing unpatching transition
99livepatch: '$MOD_REPLACE': starting unpatching transition
100livepatch: '$MOD_REPLACE': completing unpatching transition
101livepatch: '$MOD_REPLACE': unpatching complete
102% rmmod $MOD_REPLACE
103$MOD_LIVEPATCH: this has been live patched
104% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
105livepatch: '$MOD_LIVEPATCH': initializing unpatching transition
106livepatch: '$MOD_LIVEPATCH': starting unpatching transition
107livepatch: '$MOD_LIVEPATCH': completing unpatching transition
108livepatch: '$MOD_LIVEPATCH': unpatching complete
109% rmmod $MOD_LIVEPATCH"
110
111
112# TEST: atomic replace livepatch
113# - load a livepatch that modifies the output from /proc/cmdline and
114#   verify correct behavior
115# - load an atomic replace livepatch and verify that only the second is active
116# - remove the first livepatch and verify that the atomic replace livepatch
117#   is still active
118# - remove the atomic replace livepatch and verify that none are active
119
120echo -n "TEST: atomic replace livepatch ... "
121dmesg -C
122
123load_lp $MOD_LIVEPATCH
124
125grep 'live patched' /proc/cmdline > /dev/kmsg
126grep 'live patched' /proc/meminfo > /dev/kmsg
127
128load_lp $MOD_REPLACE replace=1
129
130grep 'live patched' /proc/cmdline > /dev/kmsg
131grep 'live patched' /proc/meminfo > /dev/kmsg
132
133unload_lp $MOD_LIVEPATCH
134
135grep 'live patched' /proc/cmdline > /dev/kmsg
136grep 'live patched' /proc/meminfo > /dev/kmsg
137
138disable_lp $MOD_REPLACE
139unload_lp $MOD_REPLACE
140
141grep 'live patched' /proc/cmdline > /dev/kmsg
142grep 'live patched' /proc/meminfo > /dev/kmsg
143
144check_result "% modprobe $MOD_LIVEPATCH
145livepatch: enabling patch '$MOD_LIVEPATCH'
146livepatch: '$MOD_LIVEPATCH': initializing patching transition
147livepatch: '$MOD_LIVEPATCH': starting patching transition
148livepatch: '$MOD_LIVEPATCH': completing patching transition
149livepatch: '$MOD_LIVEPATCH': patching complete
150$MOD_LIVEPATCH: this has been live patched
151% modprobe $MOD_REPLACE replace=1
152livepatch: enabling patch '$MOD_REPLACE'
153livepatch: '$MOD_REPLACE': initializing patching transition
154livepatch: '$MOD_REPLACE': starting patching transition
155livepatch: '$MOD_REPLACE': completing patching transition
156livepatch: '$MOD_REPLACE': patching complete
157$MOD_REPLACE: this has been live patched
158% rmmod $MOD_LIVEPATCH
159$MOD_REPLACE: this has been live patched
160% echo 0 > /sys/kernel/livepatch/$MOD_REPLACE/enabled
161livepatch: '$MOD_REPLACE': initializing unpatching transition
162livepatch: '$MOD_REPLACE': starting unpatching transition
163livepatch: '$MOD_REPLACE': completing unpatching transition
164livepatch: '$MOD_REPLACE': unpatching complete
165% rmmod $MOD_REPLACE"
166
167
168exit 0
169