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