Skip to content

Commit d111c9f

Browse files
committed
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
2 parents a701f37 + e7dbd4d commit d111c9f

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

kernel/livepatch/transition.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,13 @@ void klp_force_transition(void)
641641
for_each_possible_cpu(cpu)
642642
klp_update_patch_state(idle_task(cpu));
643643

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+
}
646653
}

samples/livepatch/livepatch-shadow-fix1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ static void livepatch_fix1_dummy_leak_dtor(void *obj, void *shadow_data)
109109
void *d = obj;
110110
int **shadow_leak = shadow_data;
111111

112-
kfree(*shadow_leak);
113112
pr_info("%s: dummy @ %p, prevented leak @ %p\n",
114113
__func__, d, *shadow_leak);
114+
kfree(*shadow_leak);
115115
}
116116

117117
static void livepatch_fix1_dummy_free(struct dummy *d)

samples/livepatch/livepatch-shadow-fix2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ static void livepatch_fix2_dummy_leak_dtor(void *obj, void *shadow_data)
6161
void *d = obj;
6262
int **shadow_leak = shadow_data;
6363

64-
kfree(*shadow_leak);
6564
pr_info("%s: dummy @ %p, prevented leak @ %p\n",
6665
__func__, d, *shadow_leak);
66+
kfree(*shadow_leak);
6767
}
6868

6969
static void livepatch_fix2_dummy_free(struct dummy *d)

tools/testing/selftests/livepatch/functions.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,25 @@ function set_dynamic_debug() {
7575
}
7676

7777
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
8197
}
8298

8399
function cleanup() {

tools/testing/selftests/livepatch/test-ftrace.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]]
2525
die "livepatch kselftest(s) failed"
2626
fi
2727

28-
set_ftrace_enabled 0
28+
# Check that ftrace could not get disabled when a livepatch is enabled
29+
set_ftrace_enabled --fail 0
2930
if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then
3031
echo -e "FAIL\n\n"
3132
die "livepatch kselftest(s) failed"

0 commit comments

Comments
 (0)