|
| 1 | +#!/bin/bash |
| 2 | +# SPDX-License-Identifier: GPL-2.0 |
| 3 | +# Copyright (C) 2024 SUSE |
| 4 | +# Author: Michael Vetter <mvetter@suse.com> |
| 5 | + |
| 6 | +. $(dirname $0)/functions.sh |
| 7 | + |
| 8 | +MOD_LIVEPATCH=test_klp_livepatch |
| 9 | +MOD_KPROBE=test_klp_kprobe |
| 10 | + |
| 11 | +setup_config |
| 12 | + |
| 13 | +# Kprobe a function and verify that we can't livepatch that same function |
| 14 | +# when it uses a post_handler since only one IPMODIFY maybe be registered |
| 15 | +# to any given function at a time. |
| 16 | + |
| 17 | +start_test "livepatch interaction with kprobed function with post_handler" |
| 18 | + |
| 19 | +echo 1 > "$SYSFS_KPROBES_DIR/enabled" |
| 20 | + |
| 21 | +load_mod $MOD_KPROBE has_post_handler=true |
| 22 | +load_failing_mod $MOD_LIVEPATCH |
| 23 | +unload_mod $MOD_KPROBE |
| 24 | + |
| 25 | +check_result "% insmod test_modules/test_klp_kprobe.ko has_post_handler=true |
| 26 | +% insmod test_modules/$MOD_LIVEPATCH.ko |
| 27 | +livepatch: enabling patch '$MOD_LIVEPATCH' |
| 28 | +livepatch: '$MOD_LIVEPATCH': initializing patching transition |
| 29 | +livepatch: failed to register ftrace handler for function 'cmdline_proc_show' (-16) |
| 30 | +livepatch: failed to patch object 'vmlinux' |
| 31 | +livepatch: failed to enable patch '$MOD_LIVEPATCH' |
| 32 | +livepatch: '$MOD_LIVEPATCH': canceling patching transition, going to unpatch |
| 33 | +livepatch: '$MOD_LIVEPATCH': completing unpatching transition |
| 34 | +livepatch: '$MOD_LIVEPATCH': unpatching complete |
| 35 | +insmod: ERROR: could not insert module test_modules/$MOD_LIVEPATCH.ko: Device or resource busy |
| 36 | +% rmmod test_klp_kprobe" |
| 37 | + |
| 38 | +start_test "livepatch interaction with kprobed function without post_handler" |
| 39 | + |
| 40 | +load_mod $MOD_KPROBE has_post_handler=false |
| 41 | +load_lp $MOD_LIVEPATCH |
| 42 | + |
| 43 | +unload_mod $MOD_KPROBE |
| 44 | +disable_lp $MOD_LIVEPATCH |
| 45 | +unload_lp $MOD_LIVEPATCH |
| 46 | + |
| 47 | +check_result "% insmod test_modules/test_klp_kprobe.ko has_post_handler=false |
| 48 | +% insmod test_modules/$MOD_LIVEPATCH.ko |
| 49 | +livepatch: enabling patch '$MOD_LIVEPATCH' |
| 50 | +livepatch: '$MOD_LIVEPATCH': initializing patching transition |
| 51 | +livepatch: '$MOD_LIVEPATCH': starting patching transition |
| 52 | +livepatch: '$MOD_LIVEPATCH': completing patching transition |
| 53 | +livepatch: '$MOD_LIVEPATCH': patching complete |
| 54 | +% rmmod test_klp_kprobe |
| 55 | +% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled |
| 56 | +livepatch: '$MOD_LIVEPATCH': initializing unpatching transition |
| 57 | +livepatch: '$MOD_LIVEPATCH': starting unpatching transition |
| 58 | +livepatch: '$MOD_LIVEPATCH': completing unpatching transition |
| 59 | +livepatch: '$MOD_LIVEPATCH': unpatching complete |
| 60 | +% rmmod $MOD_LIVEPATCH" |
| 61 | + |
| 62 | +exit 0 |
0 commit comments