18c666d2aSJoe Lawrence#!/bin/bash 28c666d2aSJoe Lawrence# SPDX-License-Identifier: GPL-2.0 38c666d2aSJoe Lawrence# Copyright (C) 2019 Joe Lawrence <joe.lawrence@redhat.com> 48c666d2aSJoe Lawrence 58c666d2aSJoe Lawrence. $(dirname $0)/functions.sh 68c666d2aSJoe Lawrence 78c666d2aSJoe LawrenceMOD_LIVEPATCH=test_klp_livepatch 88c666d2aSJoe Lawrence 98c666d2aSJoe Lawrencesetup_config 108c666d2aSJoe Lawrence 118c666d2aSJoe Lawrence 128c666d2aSJoe Lawrence# - turn ftrace_enabled OFF and verify livepatches can't load 138c666d2aSJoe Lawrence# - turn ftrace_enabled ON and verify livepatch can load 148c666d2aSJoe Lawrence# - verify that ftrace_enabled can't be turned OFF while a livepatch is loaded 158c666d2aSJoe Lawrence 162eeb0d45SJoe Lawrencestart_test "livepatch interaction with ftrace_enabled sysctl" 178c666d2aSJoe Lawrence 188c666d2aSJoe Lawrenceset_ftrace_enabled 0 198c666d2aSJoe Lawrenceload_failing_mod $MOD_LIVEPATCH 208c666d2aSJoe Lawrence 218c666d2aSJoe Lawrenceset_ftrace_enabled 1 228c666d2aSJoe Lawrenceload_lp $MOD_LIVEPATCH 238c666d2aSJoe Lawrenceif [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then 248c666d2aSJoe Lawrence echo -e "FAIL\n\n" 258c666d2aSJoe Lawrence die "livepatch kselftest(s) failed" 268c666d2aSJoe Lawrencefi 278c666d2aSJoe Lawrence 284327b9eaSDavid Vernet# Check that ftrace could not get disabled when a livepatch is enabled 294327b9eaSDavid Vernetset_ftrace_enabled --fail 0 308c666d2aSJoe Lawrenceif [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live patched" ]] ; then 318c666d2aSJoe Lawrence echo -e "FAIL\n\n" 328c666d2aSJoe Lawrence die "livepatch kselftest(s) failed" 338c666d2aSJoe Lawrencefi 348c666d2aSJoe Lawrencedisable_lp $MOD_LIVEPATCH 358c666d2aSJoe Lawrenceunload_lp $MOD_LIVEPATCH 368c666d2aSJoe Lawrence 378c666d2aSJoe Lawrencecheck_result "livepatch: kernel.ftrace_enabled = 0 38*c4bbe83dSMarcos Paulo de Souza% insmod test_modules/$MOD_LIVEPATCH.ko 398c666d2aSJoe Lawrencelivepatch: enabling patch '$MOD_LIVEPATCH' 408c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': initializing patching transition 418c666d2aSJoe Lawrencelivepatch: failed to register ftrace handler for function 'cmdline_proc_show' (-16) 428c666d2aSJoe Lawrencelivepatch: failed to patch object 'vmlinux' 438c666d2aSJoe Lawrencelivepatch: failed to enable patch '$MOD_LIVEPATCH' 448c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': canceling patching transition, going to unpatch 458c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': completing unpatching transition 468c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': unpatching complete 47*c4bbe83dSMarcos Paulo de Souzainsmod: ERROR: could not insert module test_modules/$MOD_LIVEPATCH.ko: Device or resource busy 488c666d2aSJoe Lawrencelivepatch: kernel.ftrace_enabled = 1 49*c4bbe83dSMarcos Paulo de Souza% insmod test_modules/$MOD_LIVEPATCH.ko 508c666d2aSJoe Lawrencelivepatch: enabling patch '$MOD_LIVEPATCH' 518c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': initializing patching transition 528c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': starting patching transition 538c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': completing patching transition 548c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': patching complete 555e4d4688SPetr Mladeklivepatch: sysctl: setting key \"kernel.ftrace_enabled\": Device or resource busy 568c666d2aSJoe Lawrence% echo 0 > /sys/kernel/livepatch/$MOD_LIVEPATCH/enabled 578c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': initializing unpatching transition 588c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': starting unpatching transition 598c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': completing unpatching transition 608c666d2aSJoe Lawrencelivepatch: '$MOD_LIVEPATCH': unpatching complete 618c666d2aSJoe Lawrence% rmmod $MOD_LIVEPATCH" 628c666d2aSJoe Lawrence 638c666d2aSJoe Lawrence 648c666d2aSJoe Lawrenceexit 0 65