From patchwork Tue Jul 16 11:13:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11045857 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 BE33E912 for ; Tue, 16 Jul 2019 11:13:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABE5528564 for ; Tue, 16 Jul 2019 11:13:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FF9B2856F; Tue, 16 Jul 2019 11:13:38 +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 33A3B28564 for ; Tue, 16 Jul 2019 11:13:38 +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=uwD4xuAt8gk2Gz29pPVsp59gYxwYNQTAi1I8cuQkIpM=; b=iNQocNEMrpJxj+9EjY5Fv4gtJQ /LCGrnx+nuoW1Io65CO8KwakCVbRyMbeK+bZvzifjw41NkoNYFVi0zpyGwICKqyDj0AoLQGxGADCX aKSBB48iwg/XT2HreKH+q/Vsr6oh8OIstkl3Irz1pnvA8sNuTJsABS47vN4KOoECbM9YUPVIZffIq MFXCQPdj7EwCfLXavlXeGNLrBHsOjbwXSa3Q+2LkezXE+jNv9OsKV68m365HuuywC1ASKvaEpvr/F UuGDKs0stoJK6vDHls0ituuAeIrB6XDXmlJ7IE/SwT9w/EtE2shiZxwSYMM7VLMZYMUQLaS94tFML sgP3Itww==; 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 1hnLOq-0000ah-BH; Tue, 16 Jul 2019 11:13:36 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hnLOg-0000Rn-Kv for linux-arm-kernel@lists.infradead.org; Tue, 16 Jul 2019 11:13:28 +0000 Received: by mail-pg1-x543.google.com with SMTP id f5so448785pgu.5 for ; Tue, 16 Jul 2019 04:13:26 -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=E2i/udg2w3wrGveXxZ0CfGzob3tFFx0rfm+JzVT0Ufc=; b=jHKzaY6922Yu28T9Bff5NZORO93a7cXFLmiZuwi4qLfbemKA5hga13MQN3haCO8ena q/ri2Qg7dE7VL8A1Kl2QztmGDv+YCLGTjyZpEIFPN9KWjOxdu5RE9PZMsFjxXTV5ds8V NN/qh4zAHXZCvvb17yStTthsdlNay9Z2Kstc4El8pGQcaPZ5aSDbtMG/j1GQJp8vuIU5 4hP+vogcQvMmDhOSAmBxXLAPCOCXH2gIuKG8Aq1pRi9aYQC6LcbpNS/drPm6r1XW3T9e VUR3ZRnPGlAfN/jbriW+1ll6DXsv5rVCEXrNEz7ww2hwuKQXLbY3wow52xMceZB0oK7W Y3ZQ== 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=E2i/udg2w3wrGveXxZ0CfGzob3tFFx0rfm+JzVT0Ufc=; b=bgm41FPnvTo4OALqE3TRXh1hYhVFj5lnjMykN4gRYbpM0s43mHbigbLiCSB2Dv7ZsF 5QL/zNZfAdjy3+yQ+9JXxRKi6V+Heqi67WVmZBHpNzXunFNwPCV3S6dM/su0ak9gBr4v 4x2WHnkggSgenznOBVEHRiEZK07Zt5OnM9hiQFXP8x3mU8g/qTfS9MkrTu4+zDwMkvsD yN/dYDaexYpJmMPrjBvNdgU09LpOZUi3kfeNMUqZJmH3ZOQ3X2Af5y7fTfy8WXFyuFb6 gN8faPrbXHegpU2yJVj5+NsgKnkZ4SPPFrlTAU6FBS8uwFn7WuiEhplOhA63yzpIVI4O gOgQ== X-Gm-Message-State: APjAAAVOtETwTb5Mtx5RQ3D3oxSaE5UalfapZ1hRU7Q6njjhGJvvgV7x kWedGayyMSiSj1FFQkjB7/o4WA== X-Google-Smtp-Source: APXvYqxH/LGB+HIDp3yR3h8D9gmqijBTeEMxlQPvdHS35dIb8U6g8YLCFVj2tj/OrIFeqjNGQFTSsA== X-Received: by 2002:a63:d315:: with SMTP id b21mr8418386pgg.326.1563275605529; Tue, 16 Jul 2019 04:13:25 -0700 (PDT) Received: from localhost.localdomain (li1433-81.members.linode.com. [45.33.106.81]) by smtp.gmail.com with ESMTPSA id 21sm19324907pjh.25.2019.07.16.04.13.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 04:13:25 -0700 (PDT) From: Leo Yan To: Russell King , Oleg Nesterov , Catalin Marinas , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Masami Hiramatsu , Justin He Subject: [PATCH 1/2] arm64: Add support for function error injection Date: Tue, 16 Jul 2019 19:13:00 +0800 Message-Id: <20190716111301.1855-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190716111301.1855-1-leo.yan@linaro.org> References: <20190716111301.1855-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190716_041326_867355_D2475D8D X-CRM114-Status: GOOD ( 18.29 ) 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 implement regs_set_return_value() and override_function_with_return() to support function error injection for arm64. In the exception flow, arm64's general register x30 contains the value for the link register; so we can just update pt_regs::pc with it rather than redirecting execution to a dummy function that returns. This patch is heavily inspired by the commit 7cd01b08d35f ("powerpc: Add support for function error injection"). Signed-off-by: Leo Yan --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/error-injection.h | 13 +++++++++++++ arch/arm64/include/asm/ptrace.h | 5 +++++ arch/arm64/lib/Makefile | 2 ++ arch/arm64/lib/error-inject.c | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 arch/arm64/include/asm/error-injection.h create mode 100644 arch/arm64/lib/error-inject.c diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 697ea0510729..a6d9e622977d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -142,6 +142,7 @@ config ARM64 select HAVE_EFFICIENT_UNALIGNED_ACCESS select HAVE_FTRACE_MCOUNT_RECORD select HAVE_FUNCTION_TRACER + select HAVE_FUNCTION_ERROR_INJECTION select HAVE_FUNCTION_GRAPH_TRACER select HAVE_GCC_PLUGINS select HAVE_HW_BREAKPOINT if PERF_EVENTS diff --git a/arch/arm64/include/asm/error-injection.h b/arch/arm64/include/asm/error-injection.h new file mode 100644 index 000000000000..da057e8ed224 --- /dev/null +++ b/arch/arm64/include/asm/error-injection.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef __ASM_ERROR_INJECTION_H_ +#define __ASM_ERROR_INJECTION_H_ + +#include +#include +#include +#include + +void override_function_with_return(struct pt_regs *regs); + +#endif /* __ASM_ERROR_INJECTION_H_ */ diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h index dad858b6adc6..3aafbbe218a2 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -294,6 +294,11 @@ static inline unsigned long regs_return_value(struct pt_regs *regs) return regs->regs[0]; } +static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc) +{ + regs->regs[0] = rc; +} + /** * regs_get_kernel_argument() - get Nth function argument in kernel * @regs: pt_regs of that context diff --git a/arch/arm64/lib/Makefile b/arch/arm64/lib/Makefile index 33c2a4abda04..f182ccb0438e 100644 --- a/arch/arm64/lib/Makefile +++ b/arch/arm64/lib/Makefile @@ -33,3 +33,5 @@ UBSAN_SANITIZE_atomic_ll_sc.o := n lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o obj-$(CONFIG_CRC32) += crc32.o + +obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o diff --git a/arch/arm64/lib/error-inject.c b/arch/arm64/lib/error-inject.c new file mode 100644 index 000000000000..35661c2de4b0 --- /dev/null +++ b/arch/arm64/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->regs[30]' contains the the link register for the probed + * function and assign it to 'regs->pc', so when kprobe returns + * back from exception it will override the end of probed function + * and drirectly return to the predefined function's caller. + */ + regs->pc = regs->regs[30]; +} +NOKPROBE_SYMBOL(override_function_with_return); From patchwork Tue Jul 16 11:13:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 11045859 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 F128E912 for ; Tue, 16 Jul 2019 11:14:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA03828564 for ; Tue, 16 Jul 2019 11:14:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAC882856F; Tue, 16 Jul 2019 11:14:00 +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 4B00328564 for ; Tue, 16 Jul 2019 11:14:00 +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=2b2HGDdOJRgbENjyuA+5rn3JPmo2NqJBBkM3pJjypyY=; b=dIApnFnayOz0zwdJ0INitN2D12 blK8gNWXlUq0erUeXBqopPaDclumNrz3orNzugQt1p+O5hsnljZFLlw5qjyOou+4ueLue2+rrecpP pH2cWkeMRAnoEngQfYoyLzUnw6FvvZf6PpdbiX3egxlbeZb98ddRHUZwGZVhR2FEyvoxrkxtDKTmJ pJQ+cST3BcOqGuZ2ccPNvVDW/h6Jfia3VC/1uAVr+C9yaNa6+pH5RkxGBvFQqg+7HEc23kol0x+xz s7FNgXJbI9rkhXM65oJD0KYkKWtjzeDAzfcdYHPr9O4VS77gS5GUbpEM/Rg45fSdYqOn4f4QcAM9c UlkcpPqg==; 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 1hnLPD-0000sk-Iv; Tue, 16 Jul 2019 11:13:59 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hnLOm-0000YJ-Ph for linux-arm-kernel@lists.infradead.org; Tue, 16 Jul 2019 11:13:34 +0000 Received: by mail-pf1-x442.google.com with SMTP id r1so8939706pfq.12 for ; Tue, 16 Jul 2019 04:13:32 -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=8NFJGPVlVAuYMPwOwTl0aBkcJ7/1gJuCLWe4ZLruxuU=; b=eFbk7M92HouroEKZP0msAOxYiaXaS/2dbFJatwM4kpmpNxCG2xYCHSOShlXhHmfE/y HGkpLzpVjnxwwgeoDQJJKFh0lBYkIHTQa7SmPAqKRACozyFI1kfcxgyGAhe+PYMgiKoV TxyhCnO8KPyvyLcGu/qiDr7sGSerQN8PJUUr+ZQITlUAG3FZs1YFtHMqvb5GXWip8Cd6 x879/KTZqwwgfqf8qTL/8Fhu2rsWdmSFSKgR7tTOmxeuPB4LV1h8KvWPxzLdT/FYmbzt Re6WG4jGnGzfkzfMqkQE+3p6FC6FWaId7hHmYWWVkEQiHCKVqOeGmEHXPEfk69iWGxsa 1r6A== 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=8NFJGPVlVAuYMPwOwTl0aBkcJ7/1gJuCLWe4ZLruxuU=; b=AAekXOY2Kp1yXob5tTKpwWIrE/Jr6vfH6faJdrVqrdWU+CjL9BqpkBI6+2M+h8PB5J srsp7m2aWUDi7a1lqxChzS6NgfLP1OHVsGVd8c92sbmyU9nR5uRzNwglKbf7Q6dZ/q88 ZzH3fp2E8asrJZKARcMgPeOb7VX8lmrHXottDWNBt/Yp+a/Lst70ji23oSggooSaGRMB v9X73NlezySFE4KEhSddkjbYidO9mmQXqOHarmvcSyKRABJ6IjXU5VjlVOmKKQYmhve+ mLHOouODeHYRRmVvQiPOFihjpc1uNF7B1wmopH6VhEYwqkZcJCKL8ERAHXwTMtPHXZ32 4jGA== X-Gm-Message-State: APjAAAUOqI7q+ZRDnwxrZUKQ1uCJsGwtHoT6kZ04ieyCVlvnA6SsSyZT qovdIMX8+LNQEr1o2QD7G1X4N1rM1lQ= X-Google-Smtp-Source: APXvYqxM/EzG6XkGwFUq5lCZpCu7Qc8I2MK4CsmMFswEozlWGhc+DzYVPw/ySuvYYAujJtb6hXwP4Q== X-Received: by 2002:a17:90a:db52:: with SMTP id u18mr35690859pjx.107.1563275611836; Tue, 16 Jul 2019 04:13:31 -0700 (PDT) Received: from localhost.localdomain (li1433-81.members.linode.com. [45.33.106.81]) by smtp.gmail.com with ESMTPSA id 21sm19324907pjh.25.2019.07.16.04.13.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 04:13:31 -0700 (PDT) From: Leo Yan To: Russell King , Oleg Nesterov , Catalin Marinas , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Masami Hiramatsu , Justin He Subject: [PATCH 2/2] arm: Add support for function error injection Date: Tue, 16 Jul 2019 19:13:01 +0800 Message-Id: <20190716111301.1855-3-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190716111301.1855-1-leo.yan@linaro.org> References: <20190716111301.1855-1-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190716_041332_923992_691A26AD X-CRM114-Status: GOOD ( 16.62 ) 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 implement regs_set_return_value() and override_function_with_return() to support function error injection for arm. In the exception flow, we can update pt_regs::ARM_pc with pt_regs::ARM_lr so that can override the probed function return. Signed-off-by: Leo Yan --- arch/arm/Kconfig | 1 + arch/arm/include/asm/error-injection.h | 13 +++++++++++++ arch/arm/include/asm/ptrace.h | 5 +++++ arch/arm/lib/Makefile | 2 ++ arch/arm/lib/error-inject.c | 19 +++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 arch/arm/include/asm/error-injection.h create mode 100644 arch/arm/lib/error-inject.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 8869742a85df..f7932a5e29ea 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -74,6 +74,7 @@ config ARM select HAVE_EFFICIENT_UNALIGNED_ACCESS if (CPU_V6 || CPU_V6K || CPU_V7) && MMU select HAVE_EXIT_THREAD 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/error-injection.h b/arch/arm/include/asm/error-injection.h new file mode 100644 index 000000000000..da057e8ed224 --- /dev/null +++ b/arch/arm/include/asm/error-injection.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef __ASM_ERROR_INJECTION_H_ +#define __ASM_ERROR_INJECTION_H_ + +#include +#include +#include +#include + +void override_function_with_return(struct pt_regs *regs); + +#endif /* __ASM_ERROR_INJECTION_H_ */ 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 0bff0176db2c..d3d7430ecd76 100644 --- a/arch/arm/lib/Makefile +++ b/arch/arm/lib/Makefile @@ -43,3 +43,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..96319d017114 --- /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 and assign it to 'regs->ARM_pc', so when kprobe returns + * back from exception it will override the end of probed function + * and drirectly return to the predefined function's caller. + */ + regs->ARM_pc = regs->ARM_lr; +} +NOKPROBE_SYMBOL(override_function_with_return);