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) 2022 Song Liu <[email protected]> 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_livepatch 8*053f45beSAndroid Build Coastguard Worker 9*053f45beSAndroid Build Coastguard Workersetup_config 10*053f45beSAndroid Build Coastguard Worker 11*053f45beSAndroid Build Coastguard Worker# - load a livepatch and verifies the sysfs entries work as expected 12*053f45beSAndroid Build Coastguard Worker 13*053f45beSAndroid Build Coastguard Workerstart_test "sysfs test" 14*053f45beSAndroid Build Coastguard Worker 15*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH 16*053f45beSAndroid Build Coastguard Worker 17*053f45beSAndroid Build Coastguard Workercheck_sysfs_rights "$MOD_LIVEPATCH" "" "drwxr-xr-x" 18*053f45beSAndroid Build Coastguard Workercheck_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--" 19*053f45beSAndroid Build Coastguard Workercheck_sysfs_value "$MOD_LIVEPATCH" "enabled" "1" 20*053f45beSAndroid Build Coastguard Workercheck_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------" 21*053f45beSAndroid Build Coastguard Workercheck_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--" 22*053f45beSAndroid Build Coastguard Workercheck_sysfs_value "$MOD_LIVEPATCH" "transition" "0" 23*053f45beSAndroid Build Coastguard Workercheck_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/patched" "-r--r--r--" 24*053f45beSAndroid Build Coastguard Workercheck_sysfs_value "$MOD_LIVEPATCH" "vmlinux/patched" "1" 25*053f45beSAndroid Build Coastguard Worker 26*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH 27*053f45beSAndroid Build Coastguard Worker 28*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH 29*053f45beSAndroid Build Coastguard Worker 30*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe $MOD_LIVEPATCH 31*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch '$MOD_LIVEPATCH' 32*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing patching transition 33*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting patching transition 34*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing patching transition 35*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': patching complete 36*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled 37*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': initializing unpatching transition 38*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': starting unpatching transition 39*053f45beSAndroid Build Coastguard Workerlivepatch: '$MOD_LIVEPATCH': completing unpatching transition 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 Workerstart_test "sysfs test object/patched" 44*053f45beSAndroid Build Coastguard Worker 45*053f45beSAndroid Build Coastguard WorkerMOD_LIVEPATCH=test_klp_callbacks_demo 46*053f45beSAndroid Build Coastguard WorkerMOD_TARGET=test_klp_callbacks_mod 47*053f45beSAndroid Build Coastguard Workerload_lp $MOD_LIVEPATCH 48*053f45beSAndroid Build Coastguard Worker 49*053f45beSAndroid Build Coastguard Worker# check the "patch" file changes as target module loads/unloads 50*053f45beSAndroid Build Coastguard Workercheck_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARGET/patched" "0" 51*053f45beSAndroid Build Coastguard Workerload_mod $MOD_TARGET 52*053f45beSAndroid Build Coastguard Workercheck_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARGET/patched" "1" 53*053f45beSAndroid Build Coastguard Workerunload_mod $MOD_TARGET 54*053f45beSAndroid Build Coastguard Workercheck_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARGET/patched" "0" 55*053f45beSAndroid Build Coastguard Worker 56*053f45beSAndroid Build Coastguard Workerdisable_lp $MOD_LIVEPATCH 57*053f45beSAndroid Build Coastguard Workerunload_lp $MOD_LIVEPATCH 58*053f45beSAndroid Build Coastguard Worker 59*053f45beSAndroid Build Coastguard Workercheck_result "% modprobe test_klp_callbacks_demo 60*053f45beSAndroid Build Coastguard Workerlivepatch: enabling patch 'test_klp_callbacks_demo' 61*053f45beSAndroid Build Coastguard Workerlivepatch: 'test_klp_callbacks_demo': initializing patching transition 62*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_demo: pre_patch_callback: vmlinux 63*053f45beSAndroid Build Coastguard Workerlivepatch: 'test_klp_callbacks_demo': starting patching transition 64*053f45beSAndroid Build Coastguard Workerlivepatch: 'test_klp_callbacks_demo': completing patching transition 65*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_demo: post_patch_callback: vmlinux 66*053f45beSAndroid Build Coastguard Workerlivepatch: 'test_klp_callbacks_demo': patching complete 67*053f45beSAndroid Build Coastguard Worker% modprobe test_klp_callbacks_mod 68*053f45beSAndroid Build Coastguard Workerlivepatch: applying patch 'test_klp_callbacks_demo' to loading module 'test_klp_callbacks_mod' 69*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_demo: pre_patch_callback: test_klp_callbacks_mod -> [MODULE_STATE_COMING] Full formed, running module_init 70*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_demo: post_patch_callback: test_klp_callbacks_mod -> [MODULE_STATE_COMING] Full formed, running module_init 71*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_mod: test_klp_callbacks_mod_init 72*053f45beSAndroid Build Coastguard Worker% rmmod test_klp_callbacks_mod 73*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_mod: test_klp_callbacks_mod_exit 74*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_demo: pre_unpatch_callback: test_klp_callbacks_mod -> [MODULE_STATE_GOING] Going away 75*053f45beSAndroid Build Coastguard Workerlivepatch: reverting patch 'test_klp_callbacks_demo' on unloading module 'test_klp_callbacks_mod' 76*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_demo: post_unpatch_callback: test_klp_callbacks_mod -> [MODULE_STATE_GOING] Going away 77*053f45beSAndroid Build Coastguard Worker% echo 0 > /sys/kernel/livepatch/test_klp_callbacks_demo/enabled 78*053f45beSAndroid Build Coastguard Workerlivepatch: 'test_klp_callbacks_demo': initializing unpatching transition 79*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_demo: pre_unpatch_callback: vmlinux 80*053f45beSAndroid Build Coastguard Workerlivepatch: 'test_klp_callbacks_demo': starting unpatching transition 81*053f45beSAndroid Build Coastguard Workerlivepatch: 'test_klp_callbacks_demo': completing unpatching transition 82*053f45beSAndroid Build Coastguard Workertest_klp_callbacks_demo: post_unpatch_callback: vmlinux 83*053f45beSAndroid Build Coastguard Workerlivepatch: 'test_klp_callbacks_demo': unpatching complete 84*053f45beSAndroid Build Coastguard Worker% rmmod test_klp_callbacks_demo" 85*053f45beSAndroid Build Coastguard Worker 86*053f45beSAndroid Build Coastguard Workerexit 0 87