All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kprobes: Document how optimized kprobes are removed from module unload
@ 2017-05-16 18:58 Steven Rostedt
  2017-05-17  1:47 ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2017-05-16 18:58 UTC (permalink / raw)
  To: Masami Hiramatsu; +Cc: LKML, Thomas Gleixner, Ingo Molnar

From: Steven Rostedt (VMware) <rostedt@goodmis.org>

Thomas discovered a bug where the kprobe trace tests had a race
condition where the kprobe_optimizer called from a delayed work queue
that does the optimizing and "unoptimizing" of a kprobe, can try to
modify the text after it has been freed by the init code.

The kprobe trace selftest is a special case, and Thomas and myself
investigated to see if there's a chance that this could also be a bug
with module unloading, as the code is not obvious to how it handles
this. After adding lots of printks, I figured it out. Thomas suggested
that this should be commented so that others will not have to go
through this exercise again.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 7367e0e..ac386f6 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2183,6 +2183,12 @@ static int kprobes_module_callback(struct notifier_block *nb,
 				 * The vaddr this probe is installed will soon
 				 * be vfreed buy not synced to disk. Hence,
 				 * disarming the breakpoint isn't needed.
+				 *
+				 * Note, this will also move any optimized probes
+				 * that are pending to be removed from their
+				 * corresponding lists to the freeing_list and
+				 * will not be touched by the delayed
+				 * kprobe_optimizer work handler.
 				 */
 				kill_kprobe(p);
 			}

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

* Re: [PATCH] kprobes: Document how optimized kprobes are removed from module unload
  2017-05-16 18:58 [PATCH] kprobes: Document how optimized kprobes are removed from module unload Steven Rostedt
@ 2017-05-17  1:47 ` Masami Hiramatsu
  2017-05-17  2:46   ` Steven Rostedt
  0 siblings, 1 reply; 4+ messages in thread
From: Masami Hiramatsu @ 2017-05-17  1:47 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Thomas Gleixner, Ingo Molnar

On Tue, 16 May 2017 14:58:35 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: Steven Rostedt (VMware) <rostedt@goodmis.org>
> 
> Thomas discovered a bug where the kprobe trace tests had a race
> condition where the kprobe_optimizer called from a delayed work queue
> that does the optimizing and "unoptimizing" of a kprobe, can try to
> modify the text after it has been freed by the init code.
> 
> The kprobe trace selftest is a special case, and Thomas and myself
> investigated to see if there's a chance that this could also be a bug
> with module unloading, as the code is not obvious to how it handles
> this. After adding lots of printks, I figured it out. Thomas suggested
> that this should be commented so that others will not have to go
> through this exercise again.
> 

OK, and I prefer this comment to move into kill_kprobe() right
before calling kill_optimized_kprobe() because that actually
does it.

Thank you,

> Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 7367e0e..ac386f6 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2183,6 +2183,12 @@ static int kprobes_module_callback(struct notifier_block *nb,
>  				 * The vaddr this probe is installed will soon
>  				 * be vfreed buy not synced to disk. Hence,
>  				 * disarming the breakpoint isn't needed.
> +				 *
> +				 * Note, this will also move any optimized probes
> +				 * that are pending to be removed from their
> +				 * corresponding lists to the freeing_list and
> +				 * will not be touched by the delayed
> +				 * kprobe_optimizer work handler.
>  				 */
>  				kill_kprobe(p);
>  			}


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: [PATCH] kprobes: Document how optimized kprobes are removed from module unload
  2017-05-17  1:47 ` Masami Hiramatsu
@ 2017-05-17  2:46   ` Steven Rostedt
  2017-05-17  4:00     ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Rostedt @ 2017-05-17  2:46 UTC (permalink / raw)
  To: Masami Hiramatsu; +Cc: LKML, Thomas Gleixner, Ingo Molnar

On Wed, 17 May 2017 10:47:07 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> On Tue, 16 May 2017 14:58:35 -0400
> Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> > From: Steven Rostedt (VMware) <rostedt@goodmis.org>
> > 
> > Thomas discovered a bug where the kprobe trace tests had a race
> > condition where the kprobe_optimizer called from a delayed work queue
> > that does the optimizing and "unoptimizing" of a kprobe, can try to
> > modify the text after it has been freed by the init code.
> > 
> > The kprobe trace selftest is a special case, and Thomas and myself
> > investigated to see if there's a chance that this could also be a bug
> > with module unloading, as the code is not obvious to how it handles
> > this. After adding lots of printks, I figured it out. Thomas suggested
> > that this should be commented so that others will not have to go
> > through this exercise again.
> >   
> 
> OK, and I prefer this comment to move into kill_kprobe() right
> before calling kill_optimized_kprobe() because that actually
> does it.

Actually, I can add a comment in both places. I didn't put it into
kill_kprobe() because, yes that's where it is done. I placed it in the
module handler because that's where one will look to see if module
unloading doesn't have any race conditions with the delayed handling.

-- Steve


> 
> Thank you,
> 
> > Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> > Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> > ---
> > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > index 7367e0e..ac386f6 100644
> > --- a/kernel/kprobes.c
> > +++ b/kernel/kprobes.c
> > @@ -2183,6 +2183,12 @@ static int kprobes_module_callback(struct notifier_block *nb,
> >  				 * The vaddr this probe is installed will soon
> >  				 * be vfreed buy not synced to disk. Hence,
> >  				 * disarming the breakpoint isn't needed.
> > +				 *
> > +				 * Note, this will also move any optimized probes
> > +				 * that are pending to be removed from their
> > +				 * corresponding lists to the freeing_list and
> > +				 * will not be touched by the delayed
> > +				 * kprobe_optimizer work handler.
> >  				 */
> >  				kill_kprobe(p);
> >  			}  
> 
> 

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

* Re: [PATCH] kprobes: Document how optimized kprobes are removed from module unload
  2017-05-17  2:46   ` Steven Rostedt
@ 2017-05-17  4:00     ` Masami Hiramatsu
  0 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2017-05-17  4:00 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Thomas Gleixner, Ingo Molnar

On Tue, 16 May 2017 22:46:02 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Wed, 17 May 2017 10:47:07 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
> > On Tue, 16 May 2017 14:58:35 -0400
> > Steven Rostedt <rostedt@goodmis.org> wrote:
> > 
> > > From: Steven Rostedt (VMware) <rostedt@goodmis.org>
> > > 
> > > Thomas discovered a bug where the kprobe trace tests had a race
> > > condition where the kprobe_optimizer called from a delayed work queue
> > > that does the optimizing and "unoptimizing" of a kprobe, can try to
> > > modify the text after it has been freed by the init code.
> > > 
> > > The kprobe trace selftest is a special case, and Thomas and myself
> > > investigated to see if there's a chance that this could also be a bug
> > > with module unloading, as the code is not obvious to how it handles
> > > this. After adding lots of printks, I figured it out. Thomas suggested
> > > that this should be commented so that others will not have to go
> > > through this exercise again.
> > >   
> > 
> > OK, and I prefer this comment to move into kill_kprobe() right
> > before calling kill_optimized_kprobe() because that actually
> > does it.
> 
> Actually, I can add a comment in both places. I didn't put it into
> kill_kprobe() because, yes that's where it is done. I placed it in the
> module handler because that's where one will look to see if module
> unloading doesn't have any race conditions with the delayed handling.

OK, I see.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks,

> 
> -- Steve
> 
> 
> > 
> > Thank you,
> > 
> > > Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> > > Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> > > ---
> > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > > index 7367e0e..ac386f6 100644
> > > --- a/kernel/kprobes.c
> > > +++ b/kernel/kprobes.c
> > > @@ -2183,6 +2183,12 @@ static int kprobes_module_callback(struct notifier_block *nb,
> > >  				 * The vaddr this probe is installed will soon
> > >  				 * be vfreed buy not synced to disk. Hence,
> > >  				 * disarming the breakpoint isn't needed.
> > > +				 *
> > > +				 * Note, this will also move any optimized probes
> > > +				 * that are pending to be removed from their
> > > +				 * corresponding lists to the freeing_list and
> > > +				 * will not be touched by the delayed
> > > +				 * kprobe_optimizer work handler.
> > >  				 */
> > >  				kill_kprobe(p);
> > >  			}  
> > 
> > 
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

end of thread, other threads:[~2017-05-17  4:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-16 18:58 [PATCH] kprobes: Document how optimized kprobes are removed from module unload Steven Rostedt
2017-05-17  1:47 ` Masami Hiramatsu
2017-05-17  2:46   ` Steven Rostedt
2017-05-17  4:00     ` Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.