stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/kprobes: Prohibit probing on rcu_nmi_exit() and ist_exit()
@ 2020-03-07  3:02 Masami Hiramatsu
  2020-03-07  3:28 ` Paul E. McKenney
  0 siblings, 1 reply; 3+ messages in thread
From: Masami Hiramatsu @ 2020-03-07  3:02 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Paul E . McKenney, Peter Zijlstra, Joel Fernandes, Steven Rostedt,
	linux-kernel, linux-arch, gregkh, gustavo, tglx, josh,
	mathieu.desnoyers, jiangshanlai, stable

Prohibit probing on rcu_nmi_exit() and ist_exit() which
are called from do_int3()'s kprobe path after kprobe_int3_handler().

The commit c13324a505c7 ("x86/kprobes: Prohibit probing on
functions before kprobe_int3_handler()") tried to fix similar
issue, but it only marks the functions before kprobe_int3_handler()
in do_int3().

If we put a kprobe on rcu_nmi_exit() or ist_exit(), the kprobes
will detect reentrance. However, it only skips the kprobe handler,
exits from do_int3() and hits ist_exit() and rcu_nmi_exit() again.
Thus, it causes another int3 exception and finally we will get
the kernel panic with "Unrecoverable kprobe detected." error message.

This is reproducible by the following commands.

/ # echo 0 > /proc/sys/debug/kprobes-optimization
/ # echo p vfs_read > /sys/kernel/debug/tracing/kprobe_events
/ # echo p rcu_nmi_exit >> /sys/kernel/debug/tracing/kprobe_events
/ # echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable

Fixes: c13324a505c7 ("x86/kprobes: Prohibit probing on functions before kprobe_int3_handler()")
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: stable@vger.kernel.org
---
 arch/x86/kernel/traps.c |    1 +
 kernel/rcu/tree.c       |    1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 6ef00eb6fbb9..c63fb7697794 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -115,6 +115,7 @@ void ist_exit(struct pt_regs *regs)
 	if (!user_mode(regs))
 		rcu_nmi_exit();
 }
+NOKPROBE_SYMBOL(ist_exit);
 
 /**
  * ist_begin_non_atomic() - begin a non-atomic section in an IST exception
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index d91c9156fab2..c49ea0e919f9 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -670,6 +670,7 @@ void rcu_nmi_exit(void)
 {
 	rcu_nmi_exit_common(false);
 }
+NOKPROBE_SYMBOL(rcu_nmi_exit);
 
 /**
  * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle


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

* Re: [PATCH] x86/kprobes: Prohibit probing on rcu_nmi_exit() and ist_exit()
  2020-03-07  3:02 [PATCH] x86/kprobes: Prohibit probing on rcu_nmi_exit() and ist_exit() Masami Hiramatsu
@ 2020-03-07  3:28 ` Paul E. McKenney
  2020-03-07  7:47   ` Joel Fernandes
  0 siblings, 1 reply; 3+ messages in thread
From: Paul E. McKenney @ 2020-03-07  3:28 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Ingo Molnar, Peter Zijlstra, Joel Fernandes, Steven Rostedt,
	linux-kernel, linux-arch, gregkh, gustavo, tglx, josh,
	mathieu.desnoyers, jiangshanlai, stable

On Sat, Mar 07, 2020 at 12:02:12PM +0900, Masami Hiramatsu wrote:
> Prohibit probing on rcu_nmi_exit() and ist_exit() which
> are called from do_int3()'s kprobe path after kprobe_int3_handler().
> 
> The commit c13324a505c7 ("x86/kprobes: Prohibit probing on
> functions before kprobe_int3_handler()") tried to fix similar
> issue, but it only marks the functions before kprobe_int3_handler()
> in do_int3().
> 
> If we put a kprobe on rcu_nmi_exit() or ist_exit(), the kprobes
> will detect reentrance. However, it only skips the kprobe handler,
> exits from do_int3() and hits ist_exit() and rcu_nmi_exit() again.
> Thus, it causes another int3 exception and finally we will get
> the kernel panic with "Unrecoverable kprobe detected." error message.
> 
> This is reproducible by the following commands.
> 
> / # echo 0 > /proc/sys/debug/kprobes-optimization
> / # echo p vfs_read > /sys/kernel/debug/tracing/kprobe_events
> / # echo p rcu_nmi_exit >> /sys/kernel/debug/tracing/kprobe_events
> / # echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable
> 
> Fixes: c13324a505c7 ("x86/kprobes: Prohibit probing on functions before kprobe_int3_handler()")
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> Cc: stable@vger.kernel.org

From an RCU perspective:

Reviewed-by: Paul E. McKenney <paulmck@kernel.org>

> ---
>  arch/x86/kernel/traps.c |    1 +
>  kernel/rcu/tree.c       |    1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
> index 6ef00eb6fbb9..c63fb7697794 100644
> --- a/arch/x86/kernel/traps.c
> +++ b/arch/x86/kernel/traps.c
> @@ -115,6 +115,7 @@ void ist_exit(struct pt_regs *regs)
>  	if (!user_mode(regs))
>  		rcu_nmi_exit();
>  }
> +NOKPROBE_SYMBOL(ist_exit);
>  
>  /**
>   * ist_begin_non_atomic() - begin a non-atomic section in an IST exception
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index d91c9156fab2..c49ea0e919f9 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -670,6 +670,7 @@ void rcu_nmi_exit(void)
>  {
>  	rcu_nmi_exit_common(false);
>  }
> +NOKPROBE_SYMBOL(rcu_nmi_exit);
>  
>  /**
>   * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle
> 

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

* Re: [PATCH] x86/kprobes: Prohibit probing on rcu_nmi_exit() and ist_exit()
  2020-03-07  3:28 ` Paul E. McKenney
@ 2020-03-07  7:47   ` Joel Fernandes
  0 siblings, 0 replies; 3+ messages in thread
From: Joel Fernandes @ 2020-03-07  7:47 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Masami Hiramatsu, Ingo Molnar, Peter Zijlstra, Steven Rostedt,
	linux-kernel, linux-arch, gregkh, gustavo, tglx, josh,
	mathieu.desnoyers, jiangshanlai, stable

On Fri, Mar 06, 2020 at 07:28:31PM -0800, Paul E. McKenney wrote:
> On Sat, Mar 07, 2020 at 12:02:12PM +0900, Masami Hiramatsu wrote:
> > Prohibit probing on rcu_nmi_exit() and ist_exit() which
> > are called from do_int3()'s kprobe path after kprobe_int3_handler().
> > 
> > The commit c13324a505c7 ("x86/kprobes: Prohibit probing on
> > functions before kprobe_int3_handler()") tried to fix similar
> > issue, but it only marks the functions before kprobe_int3_handler()
> > in do_int3().
> > 
> > If we put a kprobe on rcu_nmi_exit() or ist_exit(), the kprobes
> > will detect reentrance. However, it only skips the kprobe handler,
> > exits from do_int3() and hits ist_exit() and rcu_nmi_exit() again.
> > Thus, it causes another int3 exception and finally we will get
> > the kernel panic with "Unrecoverable kprobe detected." error message.
> > 
> > This is reproducible by the following commands.
> > 
> > / # echo 0 > /proc/sys/debug/kprobes-optimization
> > / # echo p vfs_read > /sys/kernel/debug/tracing/kprobe_events
> > / # echo p rcu_nmi_exit >> /sys/kernel/debug/tracing/kprobe_events
> > / # echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable
> > 
> > Fixes: c13324a505c7 ("x86/kprobes: Prohibit probing on functions before kprobe_int3_handler()")
> > Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> > Cc: stable@vger.kernel.org
> 
> From an RCU perspective:
> 
> Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
> 

Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>

thanks,

 - Joel

> > ---
> >  arch/x86/kernel/traps.c |    1 +
> >  kernel/rcu/tree.c       |    1 +
> >  2 files changed, 2 insertions(+)
> > 
> > diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
> > index 6ef00eb6fbb9..c63fb7697794 100644
> > --- a/arch/x86/kernel/traps.c
> > +++ b/arch/x86/kernel/traps.c
> > @@ -115,6 +115,7 @@ void ist_exit(struct pt_regs *regs)
> >  	if (!user_mode(regs))
> >  		rcu_nmi_exit();
> >  }
> > +NOKPROBE_SYMBOL(ist_exit);
> >  
> >  /**
> >   * ist_begin_non_atomic() - begin a non-atomic section in an IST exception
> > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> > index d91c9156fab2..c49ea0e919f9 100644
> > --- a/kernel/rcu/tree.c
> > +++ b/kernel/rcu/tree.c
> > @@ -670,6 +670,7 @@ void rcu_nmi_exit(void)
> >  {
> >  	rcu_nmi_exit_common(false);
> >  }
> > +NOKPROBE_SYMBOL(rcu_nmi_exit);
> >  
> >  /**
> >   * rcu_irq_exit - inform RCU that current CPU is exiting irq towards idle
> > 

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

end of thread, other threads:[~2020-03-07  7:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-07  3:02 [PATCH] x86/kprobes: Prohibit probing on rcu_nmi_exit() and ist_exit() Masami Hiramatsu
2020-03-07  3:28 ` Paul E. McKenney
2020-03-07  7:47   ` Joel Fernandes

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).