From patchwork Tue Aug 6 10:00:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 170649 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp5470473ile; Tue, 6 Aug 2019 03:01:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqz4ETCmglzQgfFf06OmQYk4/fh4Wf4JI+Yyu67Xa6FZcRtKrYFLxVh+a3XV2lDWNLvy7BnL X-Received: by 2002:aa7:90d4:: with SMTP id k20mr2734003pfk.78.1565085665308; Tue, 06 Aug 2019 03:01:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565085665; cv=none; d=google.com; s=arc-20160816; b=jEVp3x66s7MGG8MvntgAtMvhZZcKXKO9Q3qR6Vkjb+mrq13GeO0ztScuWTzvEjvIXa yOfy75DoEAwXumZUqMj3O26pCRlAaD/MSPMNUY4++MgYnW/2i/mIVqtpvWZybQSWLD2N kEvA+yn1Nw7V+lS9Ws/uQrBVx3Md3De1zeKYGJTW0GhkVzo2W8Naz22xs2KtiMIr46Kg MfBaNK0kqPprDDWaPPQGPZn2X1AnNsqRr27p7MpYEZzdvarjMnvSI/B8Yx+nRfoP2uwy 2ri7QzScidW+WqJKErMDCiQMagyb5DFCoLeiIE0TGjB7ykRa0Z7UldY7f4UogJaLx0BR X9MQ== 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=BrBBFjqsIPWSTPOwNEcUeajfoMogUhxNa7dexawAwRQ=; b=0eEmSHpTQZQispgCfT8Ht6JCEjUgWeQV/WTwDBiMoIJhE8+JpOCFE5Q1xNpZz/NEHR 1w9EdxHRkd9YRAYJSPfCZo72Sb5qnSZW9gZH01NSKsHtznl/f311TW1LJl02g9oGWDwk RFy/LGO2v0w1VUk7SFcKsWG9+up1Q+0gk1+o05WLos83beIgatuclvMUrVlRgDct/oub ocbIhzS3mPgCL1rndtCBPOD152y5wz1kReVzhDIbzlU0AqN9uC9Vo3rdlTzQ0H5lV3LC Ozvr3ItE8F83iLA9XYLg681wah4Rhwoxc2OGdt1rMho+6x8yWrGbahCq0+erWWsBsAWJ pXVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Un6oFivG; 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 o33si22204264pgb.381.2019.08.06.03.01.04; Tue, 06 Aug 2019 03:01:05 -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=Un6oFivG; 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 S1732582AbfHFKBD (ORCPT + 29 others); Tue, 6 Aug 2019 06:01:03 -0400 Received: from mail-yb1-f193.google.com ([209.85.219.193]:39656 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732560AbfHFKBD (ORCPT ); Tue, 6 Aug 2019 06:01:03 -0400 Received: by mail-yb1-f193.google.com with SMTP id s142so445130ybc.6 for ; Tue, 06 Aug 2019 03:01:02 -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=BrBBFjqsIPWSTPOwNEcUeajfoMogUhxNa7dexawAwRQ=; b=Un6oFivG+UxJxUJOYr8+LA93ywEnvAQtUBkTGho7Ltp6aiGVqv555mAWbj39vVVe4T tTAZGZRpv3XowvmjuMFxMrBReXJdTs8FxGKnoziDeXG0a4qL4zmORnd9YynujYMNhNfH 4ecvqroC3gmCOKv5mJHmY4V38pqK6HNSb1geNVBH3Ivvtta3hsjCkmzLX9KUaWgVC6lX kJB08KuTYFEWh/U6h9qYHQxR8vAbQxOtxHmBwM3NjyhcgI62tYhGmkw/q+wYGZwhLkHO 4UzK1unsE6K15NH9p83nxGH/Qi30CQ2wvypdep65rye0RfNW5eLhw6/oUpCmj6Y9CEBx AQ2Q== 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=BrBBFjqsIPWSTPOwNEcUeajfoMogUhxNa7dexawAwRQ=; b=XAoDcf/Uckqss/Fkew3weJt3YZZFfqtoZwkwFMlCbQCmpj1NpU9uM3p6IERKEp+PA+ vD8Jqr57Ym1qKIcqX4hNDoYHsQ3KRKXDlLN7t5ymYenIdRhMguYD3kVtZIfMWLWEfp3/ pS029rYVQ9plljcK63zVTe0Dibjrxf74WumyGSAfGsOI+TGHvJmP0M01IC6aYBBXZ6Fz bBUYHp95OAr0tw6qPr+7lk8ANHMyCArbQttDqgkBhPCFVNo7FLvVU1uv1qWpBjWrYfmX heCVXUqtUThvIJTAMFyI6MBm/Oz3WbPTt7lhBcequ2jCd62Q0gwa7jFak55oTjUVa59x faag== X-Gm-Message-State: APjAAAUljwPhjSP4NoZyZEr8LqxIHGybNTdIpJ6z6HmlfL07oeYZ6IcJ yGnlEk40J+ibb7z/6lyAOf5xjQ== X-Received: by 2002:a25:8410:: with SMTP id u16mr1788923ybk.466.1565085662057; Tue, 06 Aug 2019 03:01:02 -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.00.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 06 Aug 2019 03:01:01 -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 Cc: Leo Yan Subject: [PATCH v2 1/3] error-injection: Consolidate override function definition Date: Tue, 6 Aug 2019 18:00:13 +0800 Message-Id: <20190806100015.11256-2-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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function override_function_with_return() is defined separately for each architecture and every architecture's definition is almost same with each other. E.g. x86 and powerpc both define function in its own asm/error-injection.h header and override_function_with_return() has the same definition, the only difference is that x86 defines an extra function just_return_func() but it is specific for x86 and is only used by x86's override_function_with_return(), so don't need to export this function. This patch consolidates override_function_with_return() definition into asm-generic/error-injection.h header, thus all architectures can use the common definition. As result, the architecture specific headers are removed; the include/linux/error-injection.h header also changes to include asm-generic/error-injection.h header rather than architecture header, furthermore, it includes linux/compiler.h for successful compilation. Signed-off-by: Leo Yan --- arch/powerpc/include/asm/error-injection.h | 13 ------------- arch/x86/include/asm/error-injection.h | 13 ------------- include/asm-generic/error-injection.h | 6 ++++++ include/linux/error-injection.h | 6 +++--- 4 files changed, 9 insertions(+), 29 deletions(-) delete mode 100644 arch/powerpc/include/asm/error-injection.h delete mode 100644 arch/x86/include/asm/error-injection.h -- 2.17.1 diff --git a/arch/powerpc/include/asm/error-injection.h b/arch/powerpc/include/asm/error-injection.h deleted file mode 100644 index 62fd24739852..000000000000 --- a/arch/powerpc/include/asm/error-injection.h +++ /dev/null @@ -1,13 +0,0 @@ -/* 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/x86/include/asm/error-injection.h b/arch/x86/include/asm/error-injection.h deleted file mode 100644 index 47b7a1296245..000000000000 --- a/arch/x86/include/asm/error-injection.h +++ /dev/null @@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_ERROR_INJECTION_H -#define _ASM_ERROR_INJECTION_H - -#include -#include -#include -#include - -asmlinkage void just_return_func(void); -void override_function_with_return(struct pt_regs *regs); - -#endif /* _ASM_ERROR_INJECTION_H */ diff --git a/include/asm-generic/error-injection.h b/include/asm-generic/error-injection.h index 95a159a4137f..80ca61058dd2 100644 --- a/include/asm-generic/error-injection.h +++ b/include/asm-generic/error-injection.h @@ -16,6 +16,8 @@ struct error_injection_entry { int etype; }; +struct pt_regs; + #ifdef CONFIG_FUNCTION_ERROR_INJECTION /* * Whitelist ganerating macro. Specify functions which can be @@ -28,8 +30,12 @@ static struct error_injection_entry __used \ .addr = (unsigned long)fname, \ .etype = EI_ETYPE_##_etype, \ }; + +void override_function_with_return(struct pt_regs *regs); #else #define ALLOW_ERROR_INJECTION(fname, _etype) + +static inline void override_function_with_return(struct pt_regs *regs) { } #endif #endif diff --git a/include/linux/error-injection.h b/include/linux/error-injection.h index 280c61ecbf20..635a95caf29f 100644 --- a/include/linux/error-injection.h +++ b/include/linux/error-injection.h @@ -2,16 +2,16 @@ #ifndef _LINUX_ERROR_INJECTION_H #define _LINUX_ERROR_INJECTION_H -#ifdef CONFIG_FUNCTION_ERROR_INJECTION +#include +#include -#include +#ifdef CONFIG_FUNCTION_ERROR_INJECTION extern bool within_error_injection_list(unsigned long addr); extern int get_injectable_error_type(unsigned long addr); #else /* !CONFIG_FUNCTION_ERROR_INJECTION */ -#include static inline bool within_error_injection_list(unsigned long addr) { return false; From patchwork Tue Aug 6 10:00:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 170650 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp5470671ile; Tue, 6 Aug 2019 03:01:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwCYZ4HRdj+HZkko1EVfichcoFuqdYdtNFnlsPza192A4rMKbfjC7FAtTn6rXqkygQMXwT9 X-Received: by 2002:a63:ff0c:: with SMTP id k12mr2215137pgi.186.1565085674593; Tue, 06 Aug 2019 03:01:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565085674; cv=none; d=google.com; s=arc-20160816; b=G1KdsM77/fKeCrNHYbcI40qnLlDxF8LuNIFvICWI4hxKsbMQ5u7h6AltLkvUirfzMR YJJ7g8T+MrCl7JiNd/GTgoGN4VcUqFyjhRA4upsxYWE42XgWr+gCzZGXMO5HeUWMwvzq Fow7EFD/j2fethve7Jh4gc86aqeGMRjq8GybpSt1yJTch8W/XbDWn8Ikc84uaRUkrlpj UVb252HmLi6j/6lNEfIGncarr/8JFODKzmSEGwl7ZLVweWTJWe1YCEfjbh/x20zvDGn4 eL3BFwnv5yg+aNNAxllPvMaNUJl7FLnEy+JNYdjRMQlzNyUGUGbrrjWnClyZ4C+5Xb5l 8Amw== 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=X1kq35amQF0eADWBqq2tRXGYPbvo4jnAQagrNi2mP5k=; b=lQ9VIi1wt9YF/fysqq2zP4EejQnZxWDpxKj/cyO6BWis8IFtEMcBqDfx8JH9DCIdaG QP6d7vLTXtYcr2iciW5VTP2f1w2i/+WFzBsivjACVk+YJV5FPCsaV/OXuRkxA5vGs9/A MIfMxjhlEeuH2lAVfA7aR3oZWj3wBD9a4XfFLd36yZUbrbU+i97+YUxFJrYmkd59Nwaj fi2pwUarZiwbRNSliG/fF9coZumkAECfpXBxmlMBNdFKqaT58+KwRyJnBYNFvR9UvPeK qraNgSXC76RslgwQe9tdBpmZ27aDb4D5EGi8PAbjyX8WQCkmxa23oSwxOFfi5+XjizRJ r57w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ryN6Ug8N; 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 24si49328782pgu.501.2019.08.06.03.01.14; Tue, 06 Aug 2019 03:01:14 -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=ryN6Ug8N; 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 S1732607AbfHFKBN (ORCPT + 29 others); Tue, 6 Aug 2019 06:01:13 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:41851 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732584AbfHFKBM (ORCPT ); Tue, 6 Aug 2019 06:01:12 -0400 Received: by mail-yw1-f67.google.com with SMTP id i138so30625394ywg.8 for ; Tue, 06 Aug 2019 03:01:12 -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=X1kq35amQF0eADWBqq2tRXGYPbvo4jnAQagrNi2mP5k=; b=ryN6Ug8NTpg6DdZSRbeCs9SgNy9VYtFjReXZvH386JZijbFKUzuZ1IjFN+pJi8xLPk LukM2OHMl1jpO+jAcXDzJzG1kaH2PnG+tcT5DoqbCGgCYAsjKehsHtqdpjk7TYaP+3CV HZ1GbOcghRxf92Hbf1SK5LK2/I8WDRR2FVLhSdgtj7ZW3y/uM0N3UDKoHjXcgpIcRbHD 1AYRQOWT3JC1YJ6kRjEADY9+WyGfW67uyh8F5pYDNBg65QJ+un2Ii1vzMKBODmSrobuN Vw2Yd3mHVNb3h8K0DrfYubyUTL2jde6CpXbbokcZVLtq5/WG2hhHq4YewOfhnaY442nK tnBg== 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=X1kq35amQF0eADWBqq2tRXGYPbvo4jnAQagrNi2mP5k=; b=agKkEdDojKW4i15dPAEmG1jL5CNK6yE+w8GV0dC5e0fqSzSplLKnxhs/XahUEzjZ1Z QCcin2yni75y3ElSWnTLpe7pEtGAUoq/9KHCCSj0fH0y+lp+DJPG8AohB3oqbh2C/bBX dozrKo2+5KlBkw58oErhcIw9mBNWqVFgiDaBvMtJ+eKBzxRsy/mSq4I0sDGIOTqpkgBa 2cI2Hr2lxpVq4z+Fy/l6cb0ssZ5VufovYj0qN7UR8qk9mkvo6wOSCTkLbUPuuhzBTKtt 83yMkeyUID6gI/jaVfVWdO5hHYRufOGnSJOH+v9j4Myumd0Pvi8CLq8/94+OgmbiRxFR Ahsw== X-Gm-Message-State: APjAAAVRuP04jORP60O4y4aa9f17xbXj9MJYt621cTHGiSzyritE8DHD exROvsB2riUqbZOQni7QxUF5rg== X-Received: by 2002:a81:2545:: with SMTP id l66mr1596296ywl.489.1565085671977; Tue, 06 Aug 2019 03:01:11 -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.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 06 Aug 2019 03:01:11 -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 Cc: Leo Yan Subject: [PATCH v2 2/3] arm64: Add support for function error injection Date: Tue, 6 Aug 2019 18:00:14 +0800 Message-Id: <20190806100015.11256-3-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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Inspired by the commit 7cd01b08d35f ("powerpc: Add support for function error injection"), this patch supports function error injection for Arm64. This patch mainly support two functions: one is regs_set_return_value() which is used to overwrite the return value; the another function is override_function_with_return() which is to override the probed function returning and jump to its caller. Signed-off-by: Leo Yan --- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/ptrace.h | 5 +++++ arch/arm64/lib/Makefile | 2 ++ arch/arm64/lib/error-inject.c | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 arch/arm64/lib/error-inject.c -- 2.17.1 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 3adcec05b1f6..b15803afb2a0 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -148,6 +148,7 @@ config ARM64 select HAVE_FAST_GUP 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/ptrace.h b/arch/arm64/include/asm/ptrace.h index b1dd039023ef..891b9995cb4b 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -301,6 +301,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..ed15021da3ed --- /dev/null +++ b/arch/arm64/lib/error-inject.c @@ -0,0 +1,18 @@ +// 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. + * + * 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, procedure_link_pointer(regs)); +} +NOKPROBE_SYMBOL(override_function_with_return); 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: 170651 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp5470899ile; Tue, 6 Aug 2019 03:01:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGkuz/Ywwz312zoER3TBioKpeuy7uQAOZhB8s1fxRQem7z7TWMrZazDfguLZN2SQ1i3oow X-Received: by 2002:a62:1b0c:: with SMTP id b12mr2771369pfb.17.1565085684935; Tue, 06 Aug 2019 03:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565085684; cv=none; d=google.com; s=arc-20160816; b=yrWWqCYJ+Npt6zzRjTwwXe3hyabEZyUguDNAcwbbOcbT5bouQgQvI6vCjryYNFNFiF 72w3L2sGlSTmjWpal595QVDZ0iJo/WcBP6xWRFetI4KEKFD6qZFLaPqul9feAVCnoc+N v5/0ohyoYp/MS2ewqiw12IUIVcHTsM2nfUPD0B/JIQ+sNmBd5ZpuTRM1XP/WT5pNVjOk H1MKbN+4gVLEMAXB785ddC24dn7SCQZIxDbcVEDSHRMUvpDNEtGUTtA4x0H+GddwIkVF LCYWM52e0I1FXFVju8AexpiSi1NmGrViYAzNc8RFn/G/D7+BzwNI8ylbiUKlqGMdYUKQ ZxOA== 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=SpJEkhv16jwVLO2sSfJ7SapVMbBMCm5PIZfy4pO40/c=; b=w81Enbu05BGPq0BXT7epIK1tIVLF56tvPm/9Nj28zPzTgi7pl8GvRWWmbbjF7OTGTn FNddFHMJNk7A92jNoAms1mwFj7ZBQVwYcEYxThT1H/BViPXW9tz3gyvKbkalt3e+8/17 OSv4c9+sfmy5OF0neYzRpDAIJPGQ8/Me6q4bET1Ro9P3YSg3AQwM9HlVR+V19qF1AdLe t7ienMj3qunndoiB+aDvKsGIndjFdt95i6W2y44iDkHMdOCIjm32QEuPvrJEoDTrCuVG txd5E14gX42/H/egCvdiLp3NWEuAXiG5v3i33l6l4cOKWyvg2AZVO5/jpO8yvfuqaV4h 71Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NcmXSNcy; 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 q13si46269407pgr.514.2019.08.06.03.01.24; Tue, 06 Aug 2019 03:01:24 -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=NcmXSNcy; 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 S1732629AbfHFKBX (ORCPT + 29 others); Tue, 6 Aug 2019 06:01:23 -0400 Received: from mail-yb1-f194.google.com ([209.85.219.194]:43397 "EHLO mail-yb1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732608AbfHFKBW (ORCPT ); Tue, 6 Aug 2019 06:01:22 -0400 Received: by mail-yb1-f194.google.com with SMTP id y123so27391273yby.10 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=EHkOtm8JyBx95kiGFCCspoGpmWt32jnXuNms9QSfsSwGLag1sLeSZbK8SVkQu2UYHl /xL0c/762Mp16IY4WBA/tdwkS0yiBFC8ns4miYfL5rAyC4jbUgyzKzqLQQKMA71UHJU4 aRfijHj+HVop5jobwaTG4M4PVGi+m77OO2EQh89UXhA62ZJ6eIMgvaLNj4En+PnLj/td Sr+2cmitafdoj8+AHmYn4eRL2gYetktDqKjM5vyPGF1MlTZzMw9kRrnqcuQL5cAJldr0 3xZRiRoi3SGaWaQr3f5vrmbupz1KvJ8OvnyDj+ZwZcUj4iAFx9nTpuyIcc9lcmplgD9H Zw3Q== X-Gm-Message-State: APjAAAWNwyavO58g+oR1l7nnCdbHJ+60ZvGXyEEgUTam/lcFQM1ghlyU iJRV6qW4cFRn55/2qbBJzB6dhA== 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 Cc: Leo Yan 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.17.1 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);