Re: Oops caused by race between livepatch and ftrace

From: Josh Poimboeuf
Date: Tue May 21 2019 - 10:19:15 EST


On Mon, May 20, 2019 at 05:39:10PM -0400, Steven Rostedt wrote:
> On Mon, 20 May 2019 16:19:31 -0500
> Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:
>
> > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> > index a12aff849c04..8259d4ba8b00 100644
> > --- a/kernel/trace/ftrace.c
> > +++ b/kernel/trace/ftrace.c
> > @@ -34,6 +34,7 @@
> > #include <linux/hash.h>
> > #include <linux/rcupdate.h>
> > #include <linux/kprobes.h>
> > +#include <linux/memory.h>
> >
> > #include <trace/events/sched.h>
> >
> > @@ -2610,10 +2611,12 @@ static void ftrace_run_update_code(int command)
> > {
> > int ret;
> >
> > + mutex_lock(&text_mutex);
> > +
>
> Hmm, this may blow up with lockdep, as I believe we already have a
> locking dependency of:
>
> text_mutex -> ftrace_lock
>
> And this will reverses it. (kprobes appears to take the locks in this
> order).
>
> Perhaps have live kernel patching grab ftrace_lock?

Where does kprobes call into ftrace with the text_mutex? I couldn't
find it.

--
Josh