From patchwork Tue Aug 6 10:00:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11078585 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 0D9521395 for ; Tue, 6 Aug 2019 10:02:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE668287D1 for ; Tue, 6 Aug 2019 10:02:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0E9D28961; Tue, 6 Aug 2019 10:02:30 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 78CFD28900 for ; Tue, 6 Aug 2019 10:02:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=rS0IwQ4+OALEDu2iB2h7rN+rehfdd9Vk5EWYOTlwb4M=; b=l1c3JFGl+c/TWVo6WUG0WyrRk0 aBEQjfnM32IOaCNP2sVG5l8MRjKmroPwbby2KfS4tl+Kw13F39ljw9gBfRjhvkWPBrdlIMDcixYlQ 51OiU5D2ug0ZcXVkixntk3sQaUJCqZ3n7s7OBbX0JzL5WCfFLlPQQuEaajGMfUbrOiKJHdnSxF6pj EXA5sb8eO91XLC7sejkVk2yJl1vPq8Fvi0s34zJlhbTtHh/puGFyMLyX00OTLH1UKsfcgUck4PB/9 9nnX8xz7ogIhzNWOZqwvFyQ226nGmqzQaE1zm7Y6QZ1iz68qVR90gWK8t9CW8Rpe0k/cLX/LcCs8O 6rtehd1Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1huwIW-0003gJ-DK; Tue, 06 Aug 2019 10:02:28 +0000 Received: from mail-yb1-xb42.google.com ([2607:f8b0:4864:20::b42]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1huwHT-0002jS-4s for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2019 10:01:24 +0000 Received: by mail-yb1-xb42.google.com with SMTP id e11so4019106ybq.9 for ; Tue, 06 Aug 2019 03:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SpJEkhv16jwVLO2sSfJ7SapVMbBMCm5PIZfy4pO40/c=; b=NcmXSNcyQXDjk3UYlgYN76nvMxC7M92+xGOU6qJ+B27Ib4OnaFsQUE4R4i6AgQ5Z27 CrVPGUgZwTFsH/qOmNAZIQ9t8+tJQYLJRYwOgyGPNBTtVtV2+jhG318/V8R4JQ79LBji IXJFOhESxve1HFswgRG5nTJ/blfxFcD16f8zz9LuhnDFQEGvMLmUBnqt1xPDTPxTR3F2 UHxlkCaew7fGYGA1NWH+bEsjzPS8fNmBKA8ge4sydhn43kds0Br7aJqOw8nsgys43bqq +XxhHjPci5pdYEoWKUtlQUEsK7RtCbrhP00EmAXuXadm7JEFV+so2h2c2OMhdTF7sOr/ uDpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SpJEkhv16jwVLO2sSfJ7SapVMbBMCm5PIZfy4pO40/c=; b=KIyf7TyhBwzKdy7rsszZ3JkYV71B1LFepJzMGsLScWGYNalqChMVj7DROfYu4qjhwf 3w9uaqUS6JNmBDpYjKpUx/LCNEEAawwHdLr4dVw1x1A8r+aFoRFFQ5JIY8V/naWjCg5T LqfCNOkCVOIxtUrZgVHixJzshKP3UxZLOhr9+3jn+6Wrrqga62MiBYUaA/ITQJoe9EP8 jXfdRLpVpshRexqGHIJ6ojLcAkShtsfJl5Wd+nCh29bhlk6m7xkfhMDbWJZ2wUmyphbm XdoP4j6qjWf+4Fi7KX+tlPFLyOORhX8F2OiTQKRshCahtmpsXBrFpU7ve6N6XWjIHpvX vsEw== X-Gm-Message-State: APjAAAWnHJlB5O324fEoRKdv4vHFGKJgJlrdXl4E2NN30zWGXqUng+5P pluO8v0k+PQvQsMwLxNITr9YGw== X-Google-Smtp-Source: APXvYqwTAorLnL1JJGzrv713O0sksEZzjbqxPPlxmNn5n95Bw8aIX/crRrWGGgZ7Emh+mOBZG+hc4w== X-Received: by 2002:a25:1a82:: with SMTP id a124mr1799776yba.160.1565085681984; Tue, 06 Aug 2019 03:01:21 -0700 (PDT) Received: from localhost.localdomain (li1322-146.members.linode.com. [45.79.223.146]) by smtp.gmail.com with ESMTPSA id h12sm18316685ywm.91.2019.08.06.03.01.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 06 Aug 2019 03:01:21 -0700 (PDT) From: Leo Yan To: Russell King , Oleg Nesterov , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Arnd Bergmann , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , "Naveen N. Rao" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, clang-built-linux@googlegroups.com, Masami Hiramatsu Subject: [PATCH v2 3/3] arm: Add support for function error injection Date: Tue, 6 Aug 2019 18:00:15 +0800 Message-Id: <20190806100015.11256-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190806100015.11256-1-leo.yan@linaro.org> References: <20190806100015.11256-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190806_030123_376438_6D02D8B4 X-CRM114-Status: GOOD ( 17.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Leo Yan MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch implements arm specific functions regs_set_return_value() and override_function_with_return() to support function error injection. In the exception flow, it updates pt_regs::ARM_pc with pt_regs::ARM_lr so can override the probed function return. Signed-off-by: Leo Yan --- arch/arm/Kconfig | 1 + arch/arm/include/asm/ptrace.h | 5 +++++ arch/arm/lib/Makefile | 2 ++ arch/arm/lib/error-inject.c | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+) create mode 100644 arch/arm/lib/error-inject.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 33b00579beff..2d3d44a037f6 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -77,6 +77,7 @@ config ARM select HAVE_EXIT_THREAD select HAVE_FAST_GUP if ARM_LPAE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL + select HAVE_FUNCTION_ERROR_INJECTION if !THUMB2_KERNEL select HAVE_FUNCTION_GRAPH_TRACER if !THUMB2_KERNEL && !CC_IS_CLANG select HAVE_FUNCTION_TRACER if !XIP_KERNEL select HAVE_GCC_PLUGINS diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h index 91d6b7856be4..3b41f37b361a 100644 --- a/arch/arm/include/asm/ptrace.h +++ b/arch/arm/include/asm/ptrace.h @@ -89,6 +89,11 @@ static inline long regs_return_value(struct pt_regs *regs) return regs->ARM_r0; } +static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc) +{ + regs->ARM_r0 = rc; +} + #define instruction_pointer(regs) (regs)->ARM_pc #ifdef CONFIG_THUMB2_KERNEL diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile index b25c54585048..8f56484a7156 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -42,3 +42,5 @@ ifeq ($(CONFIG_KERNEL_MODE_NEON),y) CFLAGS_xor-neon.o += $(NEON_FLAGS) obj-$(CONFIG_XOR_BLOCKS) += xor-neon.o endif + +obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o diff --git a/arch/arm/lib/error-inject.c b/arch/arm/lib/error-inject.c new file mode 100644 index 000000000000..2d696dc94893 --- /dev/null +++ b/arch/arm/lib/error-inject.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include + +void override_function_with_return(struct pt_regs *regs) +{ + /* + * 'regs' represents the state on entry of a predefined function in + * the kernel/module and which is captured on a kprobe. + * + * 'regs->ARM_lr' contains the the link register for the probed + * function, when kprobe returns back from exception it will override + * the end of probed function and directly return to the predefined + * function's caller. + */ + instruction_pointer_set(regs, regs->ARM_lr); +} +NOKPROBE_SYMBOL(override_function_with_return);