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