Re: [RFC] fprobe call of rethook_try_get faults
From: Jiri Olsa <hidden>
Date: 2023-06-14 06:42:57
Also in:
bpf, lkml
On Tue, Jun 13, 2023 at 05:48:44PM -0400, Steven Rostedt wrote:
On Wed, 7 Jun 2023 09:42:30 -0700 Jiri Olsa [off-list ref] wrote:quoted
I can't really reliable reproduce this, but while checking the code, I wonder we should call rethook_free only after we call unregister_ftrace_function like in the patch belowYeah, I think you're right!quoted
jirka ---diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index 18d36842faf5..0121e8c0d54e 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c@@ -364,19 +364,13 @@ int unregister_fprobe(struct fprobe *fp) fp->ops.saved_func != fprobe_kprobe_handler)) return -EINVAL; - /* - * rethook_free() starts disabling the rethook, but the rethook handlers - * may be running on other processors at this point. To make sure that all - * current running handlers are finished, call unregister_ftrace_function() - * after this. - */ - if (fp->rethook) - rethook_free(fp->rethook);The above only waits for RCU to finish and then starts to free rethook. This also means that something could be on the trampoline already and was preempted. It could be that this code path gets preempted. Anyway, I don't see how freeing rethook is safe before disabling all users. Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
thanks, I'll send formal patch jirka
-- Stevequoted
- ret = unregister_ftrace_function(&fp->ops); if (ret < 0) return ret; + if (fp->rethook) + rethook_free(fp->rethook); + ftrace_free_filter(&fp->ops); return ret;