1 #!/bin/bash 1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # Copyright (C) 2022 Song Liu <song@kernel.org> 3 # Copyright (C) 2022 Song Liu <song@kernel.org> 4 4 5 . $(dirname $0)/functions.sh 5 . $(dirname $0)/functions.sh 6 6 7 MOD_LIVEPATCH=test_klp_livepatch 7 MOD_LIVEPATCH=test_klp_livepatch 8 8 9 setup_config 9 setup_config 10 10 11 # - load a livepatch and verifies the sysfs en 11 # - load a livepatch and verifies the sysfs entries work as expected 12 12 13 start_test "sysfs test" 13 start_test "sysfs test" 14 14 15 load_lp $MOD_LIVEPATCH 15 load_lp $MOD_LIVEPATCH 16 16 17 check_sysfs_rights "$MOD_LIVEPATCH" "" "drwxr- 17 check_sysfs_rights "$MOD_LIVEPATCH" "" "drwxr-xr-x" 18 check_sysfs_rights "$MOD_LIVEPATCH" "enabled" 18 check_sysfs_rights "$MOD_LIVEPATCH" "enabled" "-rw-r--r--" 19 check_sysfs_value "$MOD_LIVEPATCH" "enabled" 19 check_sysfs_value "$MOD_LIVEPATCH" "enabled" "1" 20 check_sysfs_rights "$MOD_LIVEPATCH" "force" "- 20 check_sysfs_rights "$MOD_LIVEPATCH" "force" "--w-------" 21 check_sysfs_rights "$MOD_LIVEPATCH" "replace" 21 check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--" 22 check_sysfs_rights "$MOD_LIVEPATCH" "transitio 22 check_sysfs_rights "$MOD_LIVEPATCH" "transition" "-r--r--r--" 23 check_sysfs_value "$MOD_LIVEPATCH" "transitio 23 check_sysfs_value "$MOD_LIVEPATCH" "transition" "0" 24 check_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/p 24 check_sysfs_rights "$MOD_LIVEPATCH" "vmlinux/patched" "-r--r--r--" 25 check_sysfs_value "$MOD_LIVEPATCH" "vmlinux/p 25 check_sysfs_value "$MOD_LIVEPATCH" "vmlinux/patched" "1" 26 26 27 disable_lp $MOD_LIVEPATCH 27 disable_lp $MOD_LIVEPATCH 28 28 29 unload_lp $MOD_LIVEPATCH 29 unload_lp $MOD_LIVEPATCH 30 30 31 check_result "% insmod test_modules/$MOD_LIVEP 31 check_result "% insmod test_modules/$MOD_LIVEPATCH.ko 32 livepatch: enabling patch '$MOD_LIVEPATCH' 32 livepatch: enabling patch '$MOD_LIVEPATCH' 33 livepatch: '$MOD_LIVEPATCH': initializing patc 33 livepatch: '$MOD_LIVEPATCH': initializing patching transition 34 livepatch: '$MOD_LIVEPATCH': starting patching 34 livepatch: '$MOD_LIVEPATCH': starting patching transition 35 livepatch: '$MOD_LIVEPATCH': completing patchi 35 livepatch: '$MOD_LIVEPATCH': completing patching transition 36 livepatch: '$MOD_LIVEPATCH': patching complete 36 livepatch: '$MOD_LIVEPATCH': patching complete 37 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATC 37 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled 38 livepatch: '$MOD_LIVEPATCH': initializing unpa 38 livepatch: '$MOD_LIVEPATCH': initializing unpatching transition 39 livepatch: '$MOD_LIVEPATCH': starting unpatchi 39 livepatch: '$MOD_LIVEPATCH': starting unpatching transition 40 livepatch: '$MOD_LIVEPATCH': completing unpatc 40 livepatch: '$MOD_LIVEPATCH': completing unpatching transition 41 livepatch: '$MOD_LIVEPATCH': unpatching comple 41 livepatch: '$MOD_LIVEPATCH': unpatching complete 42 % rmmod $MOD_LIVEPATCH" 42 % rmmod $MOD_LIVEPATCH" 43 43 44 start_test "sysfs test object/patched" 44 start_test "sysfs test object/patched" 45 45 46 MOD_LIVEPATCH=test_klp_callbacks_demo 46 MOD_LIVEPATCH=test_klp_callbacks_demo 47 MOD_TARGET=test_klp_callbacks_mod 47 MOD_TARGET=test_klp_callbacks_mod 48 load_lp $MOD_LIVEPATCH 48 load_lp $MOD_LIVEPATCH 49 49 50 # check the "patch" file changes as target mod 50 # check the "patch" file changes as target module loads/unloads 51 check_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARG 51 check_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARGET/patched" "0" 52 load_mod $MOD_TARGET 52 load_mod $MOD_TARGET 53 check_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARG 53 check_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARGET/patched" "1" 54 unload_mod $MOD_TARGET 54 unload_mod $MOD_TARGET 55 check_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARG 55 check_sysfs_value "$MOD_LIVEPATCH" "$MOD_TARGET/patched" "0" 56 56 57 disable_lp $MOD_LIVEPATCH 57 disable_lp $MOD_LIVEPATCH 58 unload_lp $MOD_LIVEPATCH 58 unload_lp $MOD_LIVEPATCH 59 59 60 check_result "% insmod test_modules/test_klp_c 60 check_result "% insmod test_modules/test_klp_callbacks_demo.ko 61 livepatch: enabling patch 'test_klp_callbacks_ 61 livepatch: enabling patch 'test_klp_callbacks_demo' 62 livepatch: 'test_klp_callbacks_demo': initiali 62 livepatch: 'test_klp_callbacks_demo': initializing patching transition 63 test_klp_callbacks_demo: pre_patch_callback: v 63 test_klp_callbacks_demo: pre_patch_callback: vmlinux 64 livepatch: 'test_klp_callbacks_demo': starting 64 livepatch: 'test_klp_callbacks_demo': starting patching transition 65 livepatch: 'test_klp_callbacks_demo': completi 65 livepatch: 'test_klp_callbacks_demo': completing patching transition 66 test_klp_callbacks_demo: post_patch_callback: 66 test_klp_callbacks_demo: post_patch_callback: vmlinux 67 livepatch: 'test_klp_callbacks_demo': patching 67 livepatch: 'test_klp_callbacks_demo': patching complete 68 % insmod test_modules/test_klp_callbacks_mod.k 68 % insmod test_modules/test_klp_callbacks_mod.ko 69 livepatch: applying patch 'test_klp_callbacks_ 69 livepatch: applying patch 'test_klp_callbacks_demo' to loading module 'test_klp_callbacks_mod' 70 test_klp_callbacks_demo: pre_patch_callback: t 70 test_klp_callbacks_demo: pre_patch_callback: test_klp_callbacks_mod -> [MODULE_STATE_COMING] Full formed, running module_init 71 test_klp_callbacks_demo: post_patch_callback: 71 test_klp_callbacks_demo: post_patch_callback: test_klp_callbacks_mod -> [MODULE_STATE_COMING] Full formed, running module_init 72 test_klp_callbacks_mod: test_klp_callbacks_mod 72 test_klp_callbacks_mod: test_klp_callbacks_mod_init 73 % rmmod test_klp_callbacks_mod 73 % rmmod test_klp_callbacks_mod 74 test_klp_callbacks_mod: test_klp_callbacks_mod 74 test_klp_callbacks_mod: test_klp_callbacks_mod_exit 75 test_klp_callbacks_demo: pre_unpatch_callback: 75 test_klp_callbacks_demo: pre_unpatch_callback: test_klp_callbacks_mod -> [MODULE_STATE_GOING] Going away 76 livepatch: reverting patch 'test_klp_callbacks 76 livepatch: reverting patch 'test_klp_callbacks_demo' on unloading module 'test_klp_callbacks_mod' 77 test_klp_callbacks_demo: post_unpatch_callback 77 test_klp_callbacks_demo: post_unpatch_callback: test_klp_callbacks_mod -> [MODULE_STATE_GOING] Going away 78 % echo 0 > /sys/kernel/livepatch/test_klp_call 78 % echo 0 > /sys/kernel/livepatch/test_klp_callbacks_demo/enabled 79 livepatch: 'test_klp_callbacks_demo': initiali 79 livepatch: 'test_klp_callbacks_demo': initializing unpatching transition 80 test_klp_callbacks_demo: pre_unpatch_callback: 80 test_klp_callbacks_demo: pre_unpatch_callback: vmlinux 81 livepatch: 'test_klp_callbacks_demo': starting 81 livepatch: 'test_klp_callbacks_demo': starting unpatching transition 82 livepatch: 'test_klp_callbacks_demo': completi 82 livepatch: 'test_klp_callbacks_demo': completing unpatching transition 83 test_klp_callbacks_demo: post_unpatch_callback 83 test_klp_callbacks_demo: post_unpatch_callback: vmlinux 84 livepatch: 'test_klp_callbacks_demo': unpatchi 84 livepatch: 'test_klp_callbacks_demo': unpatching complete 85 % rmmod test_klp_callbacks_demo" 85 % rmmod test_klp_callbacks_demo" 86 86 87 start_test "sysfs test replace enabled" 87 start_test "sysfs test replace enabled" 88 88 89 MOD_LIVEPATCH=test_klp_atomic_replace 89 MOD_LIVEPATCH=test_klp_atomic_replace 90 load_lp $MOD_LIVEPATCH replace=1 90 load_lp $MOD_LIVEPATCH replace=1 91 91 92 check_sysfs_rights "$MOD_LIVEPATCH" "replace" 92 check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--" 93 check_sysfs_value "$MOD_LIVEPATCH" "replace" 93 check_sysfs_value "$MOD_LIVEPATCH" "replace" "1" 94 94 95 disable_lp $MOD_LIVEPATCH 95 disable_lp $MOD_LIVEPATCH 96 unload_lp $MOD_LIVEPATCH 96 unload_lp $MOD_LIVEPATCH 97 97 98 check_result "% insmod test_modules/$MOD_LIVEP 98 check_result "% insmod test_modules/$MOD_LIVEPATCH.ko replace=1 99 livepatch: enabling patch '$MOD_LIVEPATCH' 99 livepatch: enabling patch '$MOD_LIVEPATCH' 100 livepatch: '$MOD_LIVEPATCH': initializing patc 100 livepatch: '$MOD_LIVEPATCH': initializing patching transition 101 livepatch: '$MOD_LIVEPATCH': starting patching 101 livepatch: '$MOD_LIVEPATCH': starting patching transition 102 livepatch: '$MOD_LIVEPATCH': completing patchi 102 livepatch: '$MOD_LIVEPATCH': completing patching transition 103 livepatch: '$MOD_LIVEPATCH': patching complete 103 livepatch: '$MOD_LIVEPATCH': patching complete 104 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATC 104 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled 105 livepatch: '$MOD_LIVEPATCH': initializing unpa 105 livepatch: '$MOD_LIVEPATCH': initializing unpatching transition 106 livepatch: '$MOD_LIVEPATCH': starting unpatchi 106 livepatch: '$MOD_LIVEPATCH': starting unpatching transition 107 livepatch: '$MOD_LIVEPATCH': completing unpatc 107 livepatch: '$MOD_LIVEPATCH': completing unpatching transition 108 livepatch: '$MOD_LIVEPATCH': unpatching comple 108 livepatch: '$MOD_LIVEPATCH': unpatching complete 109 % rmmod $MOD_LIVEPATCH" 109 % rmmod $MOD_LIVEPATCH" 110 110 111 start_test "sysfs test replace disabled" 111 start_test "sysfs test replace disabled" 112 112 113 load_lp $MOD_LIVEPATCH replace=0 113 load_lp $MOD_LIVEPATCH replace=0 114 114 115 check_sysfs_rights "$MOD_LIVEPATCH" "replace" 115 check_sysfs_rights "$MOD_LIVEPATCH" "replace" "-r--r--r--" 116 check_sysfs_value "$MOD_LIVEPATCH" "replace" 116 check_sysfs_value "$MOD_LIVEPATCH" "replace" "0" 117 117 118 disable_lp $MOD_LIVEPATCH 118 disable_lp $MOD_LIVEPATCH 119 unload_lp $MOD_LIVEPATCH 119 unload_lp $MOD_LIVEPATCH 120 120 121 check_result "% insmod test_modules/$MOD_LIVEP 121 check_result "% insmod test_modules/$MOD_LIVEPATCH.ko replace=0 122 livepatch: enabling patch '$MOD_LIVEPATCH' 122 livepatch: enabling patch '$MOD_LIVEPATCH' 123 livepatch: '$MOD_LIVEPATCH': initializing patc 123 livepatch: '$MOD_LIVEPATCH': initializing patching transition 124 livepatch: '$MOD_LIVEPATCH': starting patching 124 livepatch: '$MOD_LIVEPATCH': starting patching transition 125 livepatch: '$MOD_LIVEPATCH': completing patchi 125 livepatch: '$MOD_LIVEPATCH': completing patching transition 126 livepatch: '$MOD_LIVEPATCH': patching complete 126 livepatch: '$MOD_LIVEPATCH': patching complete 127 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATC 127 % echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled 128 livepatch: '$MOD_LIVEPATCH': initializing unpa 128 livepatch: '$MOD_LIVEPATCH': initializing unpatching transition 129 livepatch: '$MOD_LIVEPATCH': starting unpatchi 129 livepatch: '$MOD_LIVEPATCH': starting unpatching transition 130 livepatch: '$MOD_LIVEPATCH': completing unpatc 130 livepatch: '$MOD_LIVEPATCH': completing unpatching transition 131 livepatch: '$MOD_LIVEPATCH': unpatching comple 131 livepatch: '$MOD_LIVEPATCH': unpatching complete 132 % rmmod $MOD_LIVEPATCH" 132 % rmmod $MOD_LIVEPATCH" 133 133 134 exit 0 134 exit 0
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.