• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3# Copyright (C) 2019 Joe Lawrence <joe.lawrence@redhat.com>
4
5. $(dirname $0)/functions.sh
6
7MOD_LIVEPATCH=test_klp_livepatch
8
9setup_config
10
11
12# TEST: livepatch interaction with ftrace_enabled sysctl
13# - turn ftrace_enabled OFF and verify livepatches can't load
14# - turn ftrace_enabled ON and verify livepatch can load
15# - verify that ftrace_enabled can't be turned OFF while a livepatch is loaded
16
17echo -n "TEST: livepatch interaction with ftrace_enabled sysctl ... "
18dmesg -C
19
20set_ftrace_enabled 0
21load_failing_mod $MOD_LIVEPATCH
22
23set_ftrace_enabled 1
24load_lp $MOD_LIVEPATCH
25if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then
26	echo -e "FAIL\n\n"
27	die "livepatch kselftest(s) failed"
28fi
29
30set_ftrace_enabled 0
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
35disable_lp $MOD_LIVEPATCH
36unload_lp $MOD_LIVEPATCH
37
38check_result "livepatch: kernel.ftrace_enabled = 0
39% modprobe $MOD_LIVEPATCH
40livepatch: enabling patch '$MOD_LIVEPATCH'
41livepatch: '$MOD_LIVEPATCH': initializing patching transition
42livepatch: failed to register ftrace handler for function 'cmdline_proc_show' (-16)
43livepatch: failed to patch object 'vmlinux'
44livepatch: failed to enable patch '$MOD_LIVEPATCH'
45livepatch: '$MOD_LIVEPATCH': canceling patching transition, going to unpatch
46livepatch: '$MOD_LIVEPATCH': completing unpatching transition
47livepatch: '$MOD_LIVEPATCH': unpatching complete
48modprobe: ERROR: could not insert '$MOD_LIVEPATCH': Device or resource busy
49livepatch: kernel.ftrace_enabled = 1
50% modprobe $MOD_LIVEPATCH
51livepatch: enabling patch '$MOD_LIVEPATCH'
52livepatch: '$MOD_LIVEPATCH': initializing patching transition
53livepatch: '$MOD_LIVEPATCH': starting patching transition
54livepatch: '$MOD_LIVEPATCH': completing patching transition
55livepatch: '$MOD_LIVEPATCH': patching complete
56livepatch: sysctl: setting key \"kernel.ftrace_enabled\": Device or resource busy kernel.ftrace_enabled = 0
57% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled
58livepatch: '$MOD_LIVEPATCH': initializing unpatching transition
59livepatch: '$MOD_LIVEPATCH': starting unpatching transition
60livepatch: '$MOD_LIVEPATCH': completing unpatching transition
61livepatch: '$MOD_LIVEPATCH': unpatching complete
62% rmmod $MOD_LIVEPATCH"
63
64
65exit 0
66