Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1432054

[PATCH 2/4] ftrace/x86: Do not crash when reading wrong ftrace func

From Petr Mladek <pmladek@suse.com>
Newsgroups linux.kernel
Subject [PATCH 2/4] ftrace/x86: Do not crash when reading wrong ftrace func
Date 2016-06-27 16:00 +0200
Message-ID <rOFeW-XV-29@gated-at.bofh.it> (permalink)
References <rOFeV-XV-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Ftrace modifies the code on many locations. It is paranoid
and avoid a kernel crash using probe_kernel_read() and
probe_kernel_write(). The only exception is update_ftrace_func()
where where we read the old code using memcpy().

It is true that this function is used only to modify well
defined functions that are part of the ftrace API. But
it might still make sense to be paranoid and be consistent
with the writing side.

Signed-off-by: Petr Mladek <pmladek@suse.com>
---
 arch/x86/kernel/ftrace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 42ea69d35dfd..8305c6792ad2 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -233,7 +233,8 @@ static int update_ftrace_func(unsigned long ip, void *new)
 	unsigned char old[MCOUNT_INSN_SIZE];
 	int ret;
 
-	memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
+	if (probe_kernel_read(old, (void *)ip, MCOUNT_INSN_SIZE))
+		return -EFAULT;
 
 	/*
 	 * Make sure that we replace 5-byte instruction that
-- 
1.8.5.6

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/4] ftrace: One more check on x86 and some small fixes Petr Mladek <pmladek@suse.com> - 2016-06-27 16:00 +0200
  [PATCH 3/4] ftrace: Always destroy trampoline when shutting down the trace Petr Mladek <pmladek@suse.com> - 2016-06-27 16:00 +0200
  [PATCH 2/4] ftrace/x86: Do not crash when reading wrong ftrace func Petr Mladek <pmladek@suse.com> - 2016-06-27 16:00 +0200
    Re: [PATCH 2/4] ftrace/x86: Do not crash when reading wrong ftrace  func Steven Rostedt <rostedt@goodmis.org> - 2016-06-27 16:50 +0200
      Re: [PATCH 2/4] ftrace/x86: Do not crash when reading wrong ftrace  func Petr Mladek <pmladek@suse.com> - 2016-06-28 12:10 +0200
  [PATCH 1/4] ftrace/x86: Make sure to modify 5-bite instructions Petr Mladek <pmladek@suse.com> - 2016-06-27 16:00 +0200
  [PATCH 4/4] ftrace: Fixup trace_selftest_ops() Petr Mladek <pmladek@suse.com> - 2016-06-27 16:00 +0200
  Re: [PATCH 0/4] ftrace: One more check on x86 and some small fixes Namhyung Kim <namhyung@gmail.com> - 2016-06-28 07:30 +0200
  Re: [PATCH 0/4] ftrace: One more check on x86 and some small fixes Steven Rostedt <rostedt@goodmis.org> - 2016-06-28 21:20 +0200
    Re: [PATCH 0/4] ftrace: One more check on x86 and some small fixes Petr Mladek <pmladek@suse.com> - 2016-06-29 10:30 +0200

csiph-web