Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1604820yba; Sat, 27 Apr 2019 03:09:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqx+Boqh530gmG2jAJrZUGUAuhvnMGq5EWKziwcr7uZFm5C5tI+ka1SXxDpBcmoqpRgs0XMt X-Received: by 2002:a63:f26:: with SMTP id e38mr49642428pgl.290.1556359792672; Sat, 27 Apr 2019 03:09:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556359792; cv=none; d=google.com; s=arc-20160816; b=JmD6ZrkcGfF78hMCTiDud1K/xgLaP4X3q5B5JChZ6Bi/PL1TUy65w8a3HLJA6ubVme 5EWkaNFKGYYvsF8Wih2xKkQTsh1huLeAjOGBX11oZMZ9KjFiRGb49UTl/udw5dGdsOHx j6ijI3PqTrZl98xbQ1cabLxGVO8ydUHYs97cLdiJSPA9fUDicQhS8SfH3Bjk+Q8EhcqH SKtB94FNA5jzni18PoLslw0XU+KrU+ryF5ifeZC9V+CmT2L2k65oHEIbVtnZvyiNiIM1 N+PDCTPSwM3kIEVrFwf6MajQcLUkOxlqSilrg9cBqcQrLU/T9RA3j5VwH4jMEM8Y6w98 PNSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=MtMQcxU8O3t5jJ2HfcSw6vxXMfZABStDJqVloJtQ1nE=; b=A+d8XuGPBxIRi4cEaLjecdHhaXRqzNDhtJyq5xagX95DiKnk9EEWoZub84Bdg7WPcC liRFZQIjXOK25A/szBgj9f/7tmw4yqhiron32gKiQA8gSlNaK5+xpmZxlYABZjlRMYm4 24IK8OzUwxErS5YaiEJsIYQ7gsByqyKFdk3juiWRUv9loEtexqvvHkYJ9VOX1fqonktc W977UGUi5rpzIHXT+x637ue/Aqqu7GlqugV6nenp2tLG3kLKPRJcIEYrriZ/z4Bc5K22 KrZr4PuIp1SwTcEOMzjcKjatuTmwJCS4PT7dIPy3Qlcm/9bNmc4Y+BpH3JyrVl7+b1lt ma5A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p8si27566001plk.392.2019.04.27.03.09.24; Sat, 27 Apr 2019 03:09:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726547AbfD0KH4 (ORCPT + 99 others); Sat, 27 Apr 2019 06:07:56 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.13.7