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