lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200114015217.9246-1-cj.chengjian@huawei.com>
Date:   Tue, 14 Jan 2020 01:52:17 +0000
From:   Cheng Jian <cj.chengjian@...wei.com>
To:     <xiexiuqi@...wei.com>, <huawei.libin@...wei.com>,
        <rostedt@...dmis.org>, <tglx@...utronix.de>, <x86@...nel.org>,
        <linux-kernel@...r.kernel.org>
CC:     <cj.chengjian@...wei.com>, <bobo.shaobowang@...wei.com>
Subject: [PATCH] x86/ftrace: use ftrace_write to simplify code

ftrace_write() can be used in ftrace_modify_code_direct(),
that make the code more brief.

Signed-off-by: Cheng Jian <cj.chengjian@...wei.com>
---
 arch/x86/kernel/ftrace.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 024c3053dbba..6b36ed2fd04d 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -114,6 +114,16 @@ static const unsigned char *ftrace_nop_replace(void)
 	return ideal_nops[NOP_ATOMIC5];
 }
 
+static int ftrace_write(unsigned long ip, const char *val, int size)
+{
+	ip = text_ip_addr(ip);
+
+	if (probe_kernel_write((void *)ip, val, size))
+		return -EPERM;
+
+	return 0;
+}
+
 static int
 ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
 		   unsigned const char *new_code)
@@ -138,10 +148,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
 	if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
 		return -EINVAL;
 
-	ip = text_ip_addr(ip);
-
 	/* replace the text with the new text */
-	if (probe_kernel_write((void *)ip, new_code, MCOUNT_INSN_SIZE))
+	if (ftrace_write(ip, new_code, MCOUNT_INSN_SIZE))
 		return -EPERM;
 
 	sync_core();
@@ -326,16 +334,6 @@ int ftrace_int3_handler(struct pt_regs *regs)
 }
 NOKPROBE_SYMBOL(ftrace_int3_handler);
 
-static int ftrace_write(unsigned long ip, const char *val, int size)
-{
-	ip = text_ip_addr(ip);
-
-	if (probe_kernel_write((void *)ip, val, size))
-		return -EPERM;
-
-	return 0;
-}
-
 static int add_break(unsigned long ip, const char *old)
 {
 	unsigned char replaced[MCOUNT_INSN_SIZE];
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ