Merge tag 'livepatching-for-5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching

Pull livepatching updates from Petr Mladek:

- Forced transitions block only to-be-removed livepatches [Chengming]

- Detect when ftrace handler could not be disabled in self-tests [David]

- Calm down warning from a static analyzer [Tom]

* tag 'livepatching-for-5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/livepatching/livepatching:
livepatch: Reorder to use before freeing a pointer
livepatch: Don't block removal of patches that are safe to unload
livepatch: Skip livepatch tests if ftrace cannot be configured

+32 -8
+9 -2
kernel/livepatch/transition.c
··· 641 641 for_each_possible_cpu(cpu) 642 642 klp_update_patch_state(idle_task(cpu)); 643 643 644 - klp_for_each_patch(patch) 645 - patch->forced = true; 644 + /* Set forced flag for patches being removed. */ 645 + if (klp_target_state == KLP_UNPATCHED) 646 + klp_transition_patch->forced = true; 647 + else if (klp_transition_patch->replace) { 648 + klp_for_each_patch(patch) { 649 + if (patch != klp_transition_patch) 650 + patch->forced = true; 651 + } 652 + } 646 653 }
+1 -1
samples/livepatch/livepatch-shadow-fix1.c
··· 109 109 void *d = obj; 110 110 int **shadow_leak = shadow_data; 111 111 112 - kfree(*shadow_leak); 113 112 pr_info("%s: dummy @ %p, prevented leak @ %p\n", 114 113 __func__, d, *shadow_leak); 114 + kfree(*shadow_leak); 115 115 } 116 116 117 117 static void livepatch_fix1_dummy_free(struct dummy *d)
+1 -1
samples/livepatch/livepatch-shadow-fix2.c
··· 61 61 void *d = obj; 62 62 int **shadow_leak = shadow_data; 63 63 64 - kfree(*shadow_leak); 65 64 pr_info("%s: dummy @ %p, prevented leak @ %p\n", 66 65 __func__, d, *shadow_leak); 66 + kfree(*shadow_leak); 67 67 } 68 68 69 69 static void livepatch_fix2_dummy_free(struct dummy *d)
+19 -3
tools/testing/selftests/livepatch/functions.sh
··· 75 75 } 76 76 77 77 function set_ftrace_enabled() { 78 - result=$(sysctl -q kernel.ftrace_enabled="$1" 2>&1 && \ 79 - sysctl kernel.ftrace_enabled 2>&1) 80 - echo "livepatch: $result" > /dev/kmsg 78 + local can_fail=0 79 + if [[ "$1" == "--fail" ]] ; then 80 + can_fail=1 81 + shift 82 + fi 83 + 84 + local err=$(sysctl -q kernel.ftrace_enabled="$1" 2>&1) 85 + local result=$(sysctl --values kernel.ftrace_enabled) 86 + 87 + if [[ "$result" != "$1" ]] ; then 88 + if [[ $can_fail -eq 1 ]] ; then 89 + echo "livepatch: $err" > /dev/kmsg 90 + return 91 + fi 92 + 93 + skip "failed to set kernel.ftrace_enabled = $1" 94 + fi 95 + 96 + echo "livepatch: kernel.ftrace_enabled = $result" > /dev/kmsg 81 97 } 82 98 83 99 function cleanup() {
+2 -1
tools/testing/selftests/livepatch/test-ftrace.sh
··· 25 25 die "livepatch kselftest(s) failed" 26 26 fi 27 27 28 - set_ftrace_enabled 0 28 + # Check that ftrace could not get disabled when a livepatch is enabled 29 + set_ftrace_enabled --fail 0 29 30 if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then 30 31 echo -e "FAIL\n\n" 31 32 die "livepatch kselftest(s) failed"