linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kprobes/x86: Check for invalid ftrace location in __recover_probed_insn()
@ 2015-02-03 16:21 Petr Mladek
  2015-02-04  1:15 ` Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Mladek @ 2015-02-03 16:21 UTC (permalink / raw)
  To: Masami Hiramatsu, David S. Miller, Anil S Keshavamurthy,
	Ananth NMavinakayanahalli, Frederic Weisbecker
  Cc: Steven Rostedt, Jiri Kosina, linux-kernel, Petr Mladek

__recover_probed_insn() should always be called from an address where
an instructions starts. The check for ftrace_location() might help to
discover a potential inconsistency. Something goes terribly wrong when
an address inside the ftrace location is checked. Let's BUG() in this case.

Suggested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Petr Mladek <pmladek@suse.cz>
---
 arch/x86/kernel/kprobes/core.c | 6 ++++++
 1 file changed, 6 insertions(+)


This is follow up for the patch ("[PATCH v2] kprobes/x86: Use 5-byte NOP
when the code might be modified by ftrace") based on the Masami's
suggestion, see https://lkml.org/lkml/2015/2/3/207

Let me know if I should merge this with the first patch and send v3.


diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 2f464b56766a..124577dcf768 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -228,6 +228,12 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
 	kp = get_kprobe((void *)addr);
 	faddr = ftrace_location(addr);
 	/*
+	 * Addresses inside the ftrace location are refused by
+	 * arch_check_ftrace_location(). Something went terribly wrong
+	 * if such an address is checked here.
+	 */
+	BUG_ON(faddr && faddr != addr);
+	/*
 	 * Use the current code if it is not modified by Kprobe
 	 * and it cannot be modified by ftrace.
 	 */
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] kprobes/x86: Check for invalid ftrace location in __recover_probed_insn()
  2015-02-03 16:21 [PATCH] kprobes/x86: Check for invalid ftrace location in __recover_probed_insn() Petr Mladek
@ 2015-02-04  1:15 ` Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2015-02-04  1:15 UTC (permalink / raw)
  To: Petr Mladek
  Cc: David S. Miller, Anil S Keshavamurthy, Ananth NMavinakayanahalli,
	Frederic Weisbecker, Steven Rostedt, Jiri Kosina, linux-kernel,
	Ingo Molnar, Ingo Molnar

(2015/02/04 1:21), Petr Mladek wrote:
> __recover_probed_insn() should always be called from an address where
> an instructions starts. The check for ftrace_location() might help to
> discover a potential inconsistency. Something goes terribly wrong when
> an address inside the ftrace location is checked. Let's BUG() in this case.

Looks good to me :)

Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>

Thank you,

> 
> Suggested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
> Signed-off-by: Petr Mladek <pmladek@suse.cz>
> ---
>  arch/x86/kernel/kprobes/core.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> 
> This is follow up for the patch ("[PATCH v2] kprobes/x86: Use 5-byte NOP
> when the code might be modified by ftrace") based on the Masami's
> suggestion, see https://lkml.org/lkml/2015/2/3/207
> 
> Let me know if I should merge this with the first patch and send v3.
> 
> 
> diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
> index 2f464b56766a..124577dcf768 100644
> --- a/arch/x86/kernel/kprobes/core.c
> +++ b/arch/x86/kernel/kprobes/core.c
> @@ -228,6 +228,12 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
>  	kp = get_kprobe((void *)addr);
>  	faddr = ftrace_location(addr);
>  	/*
> +	 * Addresses inside the ftrace location are refused by
> +	 * arch_check_ftrace_location(). Something went terribly wrong
> +	 * if such an address is checked here.
> +	 */
> +	BUG_ON(faddr && faddr != addr);
> +	/*
>  	 * Use the current code if it is not modified by Kprobe
>  	 * and it cannot be modified by ftrace.
>  	 */
> 


-- 
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-02-04  1:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-03 16:21 [PATCH] kprobes/x86: Check for invalid ftrace location in __recover_probed_insn() Petr Mladek
2015-02-04  1:15 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).