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: 169052 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp703273ilk; Tue, 16 Jul 2019 04:13:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzszpynFahd7f2WEvSWj2DLF9qoWbtC7rPAKfzORTO9ZIjS5cmudhJBT+AYizs06MqR1zHa X-Received: by 2002:a63:f04:: with SMTP id e4mr31878317pgl.38.1563275608509; Tue, 16 Jul 2019 04:13:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563275608; cv=none; d=google.com; s=arc-20160816; b=kNISndRo2K0XYP+PXBlSTtZBDbfOHyWFaAO+cBzbpsKZJRCtQJFLiy8Rg7Dkr/VwAT fzW3ZWq/0mu3r0onUNJktbI+4eapWsw35LkkrZb7TGj3uHnMxdJ5hcXag/oR0lcGjnnW g1UvE5QjVk1A8fCnDGPg1qrNgHrXs0UDvP3qu33fOe93PCIBZ2rNs017eKl8c7oQ5IDp P6w8OZhr71k9IoyvnO0Egk+mWzQVTBKzRkHXdBylksPEcfEqAFl/jFSSESPmI6jq2JpD JgKnDxj4fo4XCTBol4eS5lZ0kMURz/20/WDcHIjtC9Zyp+MdPWmSV8q0iMlxhJWdgwJp 09bA== 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:dkim-signature; bh=E2i/udg2w3wrGveXxZ0CfGzob3tFFx0rfm+JzVT0Ufc=; b=X+mg/jpHkILUSVagK876m9zP7arKZZ3CyEGvtfyyVI0Bm1WZCXwTHgUZpBro+x7YAM 8DigWc1pA8Q+3ZJylWmrrajU9peKeokqs7h1ahNieWGlVldXbTIOiUQzhgUMJa8uW30l uKd38fnwNxmBlweIbFQJv+cErlmEkm5qA4Vjtk99bHASkhle1Ju8jaML08KyEKNLKKAK n3NFVvxIDlopnNuYeNqbHSqj7wPD3b3jw/v0wILZXTRqjyKk3Zo8z5YDoDKV77yELiIf 3HjcJJjGmvWh6ApVFm6c5r8Wwue0rT2/ROwQIspoInACDQy3bFRHjbU5GYKrfWQeTbb/ 5TQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jHKzaY69; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si19726340pln.228.2019.07.16.04.13.28; Tue, 16 Jul 2019 04:13:28 -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; dkim=pass header.i=@linaro.org header.s=google header.b=jHKzaY69; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387673AbfGPLN1 (ORCPT + 29 others); Tue, 16 Jul 2019 07:13:27 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40252 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387445AbfGPLN0 (ORCPT ); Tue, 16 Jul 2019 07:13:26 -0400 Received: by mail-pg1-f193.google.com with SMTP id w10so9281005pgj.7 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=F2Pwyl3KjikZjVJxnv/28tLNztEG23l76W1z9MBjFjQV786XySSGthW7mX5gNfcbCY TiRybaJR6q1TX/pwvihj024XDoM98ed8q+dqSWukr4rC5h1JVoWfpq8YMY4fi4v8aKHe bqWgKFmRo9ijKEV6AogPs4ckG3SSOCU+Kap/0J3oy3NefuScFjRAr75fenRG2GdSPrY9 gH4nI1DCJLJWjETmFkEmsppFTpGgl8YL7ZPW3vcK75+hUaaKDr0xNNI44xlltPV6FTMV wiGdU0OdpkIsrHcRJ6kz0MnUPSpccztX2OLVVKacOYilGekWfrP40DGxbqau8rgvxSC7 2YXQ== X-Gm-Message-State: APjAAAV8SdEL1e228I3pi8mFvgnyhveT3fyCLK6G80uJZRpMWa8w+c4j qj80e5BVErRyRr4ajHTCF+sXjg== 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 Cc: Leo Yan 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.17.1 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: 169053 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp703404ilk; Tue, 16 Jul 2019 04:13:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPQe0ujB8/psG5IKdIMOiQ05Bn24PTk+TG/vD854I5inpWR0VOYqgfhM4+tLKdgInpoV01 X-Received: by 2002:a63:9c5:: with SMTP id 188mr1846048pgj.2.1563275615182; Tue, 16 Jul 2019 04:13:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563275615; cv=none; d=google.com; s=arc-20160816; b=eCFzMnwbjrFnDwN1RChCrzyGSZzxj+9Rum/mZPyQ2C5Shqg9qDkLuMnwNn0xQlRxkK VSfkx3VDh/YvbE39uiFxAlxhe/953EWCWpQHZoWrlPz89qXfEYYk2eQAEEsGHrHO46U1 EBCAkOTLVIrJqRuYW/nme3tTbNTO8F+HnBccHIJjQMFhmklzKlFHZPOF8K5JPhBTpyMm 8g0bDepQZR9i677stYibHKavKhXhnebBmR/QNWboyaUl2YNJxVn+lfgGFBXJJKzHlvTG VGFuIyFMiDBe8WZOsOOvthDEs6fhI/3fOhXIZzc1ObaDmDYUhplhWQsapsT8zdBHb8Sg 3HxQ== 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:dkim-signature; bh=8NFJGPVlVAuYMPwOwTl0aBkcJ7/1gJuCLWe4ZLruxuU=; b=rFhpV7ksqlYMk54FpxgKNcFTCpOGO/1/mrbkfA0Bb8/kNFzZ2ity5JdOSDdldmwdg+ oNc4/HGYNur2o0ysoYh/GNpEEaJzxhUrKfFV6hMociiAzg9Tp/iwadzRqvdFDg/W0Xeh sdEEON+xnOZrpSw4T+c6zfKDAuz3+vQng12exOfSgX9jLT8VJKeiUF5nHGqA0stjkbtQ 6nXSxbLhIY7XYV664Q5+/XKt59QA3htp9msSi6MgdvgGeSrHbDqoxhBEE2WWcm1J7ms4 kkZgPVFIxedNR94fYEPq8EJeN17UIrJFuoEAAeAIQ4mXCuRRjFuVAEBGPhwE2fimEOTI wcFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eFbk7M92; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si18893912pgf.529.2019.07.16.04.13.34; Tue, 16 Jul 2019 04:13:35 -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; dkim=pass header.i=@linaro.org header.s=google header.b=eFbk7M92; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387699AbfGPLNd (ORCPT + 29 others); Tue, 16 Jul 2019 07:13:33 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:46317 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387584AbfGPLNc (ORCPT ); Tue, 16 Jul 2019 07:13:32 -0400 Received: by mail-pf1-f193.google.com with SMTP id c73so8943364pfb.13 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=XL29PB+aGUIbqfCf0Jnx0TAP2WSAR1mem/sYrWKgfqLK867aIc/QTRuLuH7UBYX1BQ u8iOqBsI4fzEgyTxHc3RDeEn0nJM+GyTm1PGk/uaRtfg0CKtO26VwiXboMYoZ+RPYBd1 NhE0K/TzIKwXnOjQC/PIO6V7xpue9Ybce5wnwgeyMsJYAWajNkvusNodyvlUjJqsZGT+ HsvGYRg2G/772MKlKSZKn7DOQGQ71kShGO2qR59T5LTWokpcOd43D6dGoCB3QmhgSHfj UQY6mrpIFriYACh4az+b5l2VfGqNLbwLWbN5Jgv0sDeS+NjXAM7/DFEB4ZxKNVOu8DSw PI+g== X-Gm-Message-State: APjAAAV/nMAGEC/4Imp0503HcEWkn64P0HDxfjVnfk+7VPRC+BiPHnhk 6DX4pueg3wgarnXnM/pnvKjYrA== 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 Cc: Leo Yan 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.17.1 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);