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 8MOD_LIVEPATCH=test_klp_livepatch 9MOD_KPROBE=test_klp_kprobe 10 11setup_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 17start_test "livepatch interaction with kprobed function with post_handler" 18 19echo 1 > "$SYSFS_KPROBES_DIR/enabled" 20 21load_mod $MOD_KPROBE has_post_handler=true 22load_failing_mod $MOD_LIVEPATCH 23unload_mod $MOD_KPROBE 24 25check_result "% insmod test_modules/test_klp_kprobe.ko has_post_handler=true 26% insmod test_modules/$MOD_LIVEPATCH.ko 27livepatch: enabling patch '$MOD_LIVEPATCH' 28livepatch: '$MOD_LIVEPATCH': initializing patching transition 29livepatch: failed to register ftrace handler for function 'cmdline_proc_show' (-16) 30livepatch: failed to patch object 'vmlinux' 31livepatch: failed to enable patch '$MOD_LIVEPATCH' 32livepatch: '$MOD_LIVEPATCH': canceling patching transition, going to unpatch 33livepatch: '$MOD_LIVEPATCH': completing unpatching transition 34livepatch: '$MOD_LIVEPATCH': unpatching complete 35insmod: ERROR: could not insert module test_modules/$MOD_LIVEPATCH.ko: Device or resource busy 36% rmmod test_klp_kprobe" 37 38start_test "livepatch interaction with kprobed function without post_handler" 39 40load_mod $MOD_KPROBE has_post_handler=false 41load_lp $MOD_LIVEPATCH 42 43unload_mod $MOD_KPROBE 44disable_lp $MOD_LIVEPATCH 45unload_lp $MOD_LIVEPATCH 46 47check_result "% insmod test_modules/test_klp_kprobe.ko has_post_handler=false 48% insmod test_modules/$MOD_LIVEPATCH.ko 49livepatch: enabling patch '$MOD_LIVEPATCH' 50livepatch: '$MOD_LIVEPATCH': initializing patching transition 51livepatch: '$MOD_LIVEPATCH': starting patching transition 52livepatch: '$MOD_LIVEPATCH': completing patching transition 53livepatch: '$MOD_LIVEPATCH': patching complete 54% rmmod test_klp_kprobe 55% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled 56livepatch: '$MOD_LIVEPATCH': initializing unpatching transition 57livepatch: '$MOD_LIVEPATCH': starting unpatching transition 58livepatch: '$MOD_LIVEPATCH': completing unpatching transition 59livepatch: '$MOD_LIVEPATCH': unpatching complete 60% rmmod $MOD_LIVEPATCH" 61 62exit 0 63