From patchwork Sat Apr 27 10:06:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 10920141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 36B6D14DB for ; Sat, 27 Apr 2019 10:08:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2708928DEE for ; Sat, 27 Apr 2019 10:08:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A45928DF1; Sat, 27 Apr 2019 10:08:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9349C28DEE for ; Sat, 27 Apr 2019 10:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726536AbfD0KHy (ORCPT ); Sat, 27 Apr 2019 06:07:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:51468 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726503AbfD0KHy (ORCPT ); Sat, 27 Apr 2019 06:07:54 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D3645ADF2; Sat, 27 Apr 2019 10:07:51 +0000 (UTC) From: Nicolai Stange To: Steven Rostedt Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Shuah Khan , Konrad Rzeszutek Wilk , Tim Chen , Sebastian Andrzej Siewior , Mimi Zohar , Juergen Gross , Nick Desaulniers , Nayna Jain , Masahiro Yamada , Andy Lutomirski , Joerg Roedel , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, linux-kselftest@vger.kernel.org, Nicolai Stange Subject: [PATCH 4/4] selftests/livepatch: add "ftrace a live patched function" test Date: Sat, 27 Apr 2019 12:06:39 +0200 Message-Id: <20190427100639.15074-5-nstange@suse.de> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20190427100639.15074-1-nstange@suse.de> References: <20190427100639.15074-1-nstange@suse.de> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There had been an issue with interactions between tracing and live patching due to how x86' CONFIG_DYNAMIC_FTRACE used to handle the breakpoints at the updated instructions from its ftrace_int3_handler(). More specifically, starting to trace a live patched function caused a short period in time where the live patching redirection became ineffective. In particular, the guarantees from the consistency model couldn't be held up in this situation. Implement a testcase for verifying that a function's live patch replacement is kept effective when enabling tracing on it. Reuse the existing 'test_klp_livepatch' live patch module which patches cmdline_proc_show(), the handler for /proc/cmdline. Let the testcase in a loop - apply this live patch, - launch a background shell job enabling tracing on that function - while continuously verifying that the contents of /proc/cmdline still match what would be expected when the live patch is applied. Signed-off-by: Nicolai Stange --- tools/testing/selftests/livepatch/Makefile | 3 +- .../livepatch/test-livepatch-vs-ftrace.sh | 44 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/livepatch/test-livepatch-vs-ftrace.sh diff --git a/tools/testing/selftests/livepatch/Makefile b/tools/testing/selftests/livepatch/Makefile index af4aee79bebb..bfa5353f6d17 100644 --- a/tools/testing/selftests/livepatch/Makefile +++ b/tools/testing/selftests/livepatch/Makefile @@ -3,6 +3,7 @@ TEST_GEN_PROGS := \ test-livepatch.sh \ test-callbacks.sh \ - test-shadow-vars.sh + test-shadow-vars.sh \ + test-livepatch-vs-ftrace.sh include ../lib.mk diff --git a/tools/testing/selftests/livepatch/test-livepatch-vs-ftrace.sh b/tools/testing/selftests/livepatch/test-livepatch-vs-ftrace.sh new file mode 100755 index 000000000000..5c982ec56373 --- /dev/null +++ b/tools/testing/selftests/livepatch/test-livepatch-vs-ftrace.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2019 SUSE Linux GmbH + +. $(dirname $0)/functions.sh + +set -e + +MOD_LIVEPATCH=test_klp_livepatch + +# TEST: ftrace a live patched function +# - load a livepatch that modifies the output from /proc/cmdline +# - install a function tracer at the live patched function +# - verify that the function is still patched by reading /proc/cmdline +# - unload the livepatch and make sure the patch was removed + +echo -n "TEST: ftrace a live patched function ... " +dmesg -C + +for i in $(seq 1 3); do + load_lp $MOD_LIVEPATCH + + ( echo cmdline_proc_show > /sys/kernel/debug/tracing/set_ftrace_filter; + echo function > /sys/kernel/debug/tracing/current_tracer ) & + + for j in $(seq 1 200); do + if [[ "$(cat /proc/cmdline)" != \ + "$MOD_LIVEPATCH: this has been live patched" ]] ; then + echo -e "FAIL\n\n" + die "livepatch kselftest(s) failed" + fi + done + + wait %1 + + echo nop > /sys/kernel/debug/tracing/current_tracer + echo > /sys/kernel/debug/tracing/set_ftrace_filter + + disable_lp $MOD_LIVEPATCH + unload_lp $MOD_LIVEPATCH +done + +echo "ok" +exit 0