1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# Copyright (C) 2022 Song Liu <song@kernel.org> 4 5. $(dirname $0)/functions.sh 6 7MOD_LIVEPATCH=test_klp_livepatch 8 9setup_config 10 11# - load a livepatch and verifies the sysfs entries work as expected 12 13start_test "sysfs test" 14 15load_lp $MOD_LIVEPATCH 16 17check_sysfs_rights "$MOD_LIVEPATCH" "" "drwxr-xr-x" 18check_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--" 19check_sysfs_value "$MOD_LIVEPATCH" "enabled" "1" 20check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------" 21check_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--" 22check_sysfs_value "$MOD_LIVEPATCH" "transition" "0" 23check_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/patched" "-r--r--r--" 24check_sysfs_value "$MOD_LIVEPATCH" "vmlinux/patched" "1" 25 26disable_lp $MOD_LIVEPATCH 27 28unload_lp $MOD_LIVEPATCH 29 30check_result "% insmod test_modules/$MOD_LIVEPATCH.ko 31livepatch: enabling patch '$MOD_LIVEPATCH' 32livepatch: '$MOD_LIVEPATCH': initializing patching transition 33livepatch: '$MOD_LIVEPATCH': starting patching transition 34livepatch: '$MOD_LIVEPATCH': completing patching transition 35livepatch: '$MOD_LIVEPATCH': patching complete 36% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled 37livepatch: '$MOD_LIVEPATCH': initializing unpatching transition 38livepatch: '$MOD_LIVEPATCH': starting unpatching transition 39livepatch: '$MOD_LIVEPATCH': completing unpatching transition 40livepatch: '$MOD_LIVEPATCH': unpatching complete 41% rmmod $MOD_LIVEPATCH" 42 43start_test "sysfs test object/patched" 44 45MOD_LIVEPATCH=test_klp_callbacks_demo 46MOD_TARGET=test_klp_callbacks_mod 47load_lp $MOD_LIVEPATCH 48 49# check the "patch" file changes as target module loads/unloads 50check_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARGET/patched" "0" 51load_mod $MOD_TARGET 52check_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARGET/patched" "1" 53unload_mod $MOD_TARGET 54check_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARGET/patched" "0" 55 56disable_lp $MOD_LIVEPATCH 57unload_lp $MOD_LIVEPATCH 58 59check_result "% insmod test_modules/test_klp_callbacks_demo.ko 60livepatch: enabling patch 'test_klp_callbacks_demo' 61livepatch: 'test_klp_callbacks_demo': initializing patching transition 62test_klp_callbacks_demo: pre_patch_callback: vmlinux 63livepatch: 'test_klp_callbacks_demo': starting patching transition 64livepatch: 'test_klp_callbacks_demo': completing patching transition 65test_klp_callbacks_demo: post_patch_callback: vmlinux 66livepatch: 'test_klp_callbacks_demo': patching complete 67% insmod test_modules/test_klp_callbacks_mod.ko 68livepatch: applying patch 'test_klp_callbacks_demo' to loading module 'test_klp_callbacks_mod' 69test_klp_callbacks_demo: pre_patch_callback: test_klp_callbacks_mod -> [MODULE_STATE_COMING] Full formed, running module_init 70test_klp_callbacks_demo: post_patch_callback: test_klp_callbacks_mod -> [MODULE_STATE_COMING] Full formed, running module_init 71test_klp_callbacks_mod: test_klp_callbacks_mod_init 72% rmmod test_klp_callbacks_mod 73test_klp_callbacks_mod: test_klp_callbacks_mod_exit 74test_klp_callbacks_demo: pre_unpatch_callback: test_klp_callbacks_mod -> [MODULE_STATE_GOING] Going away 75livepatch: reverting patch 'test_klp_callbacks_demo' on unloading module 'test_klp_callbacks_mod' 76test_klp_callbacks_demo: post_unpatch_callback: test_klp_callbacks_mod -> [MODULE_STATE_GOING] Going away 77% echo 0 > /sys/kernel/livepatch/test_klp_callbacks_demo/enabled 78livepatch: 'test_klp_callbacks_demo': initializing unpatching transition 79test_klp_callbacks_demo: pre_unpatch_callback: vmlinux 80livepatch: 'test_klp_callbacks_demo': starting unpatching transition 81livepatch: 'test_klp_callbacks_demo': completing unpatching transition 82test_klp_callbacks_demo: post_unpatch_callback: vmlinux 83livepatch: 'test_klp_callbacks_demo': unpatching complete 84% rmmod test_klp_callbacks_demo" 85 86exit 0 87