Skip to content

Commit 5f81018

Browse files
olsajirimhiramat
authored andcommitted
fprobe: Release rethook after the ftrace_ops is unregistered
While running bpf selftests it's possible to get following fault: general protection fault, probably for non-canonical address \ 0x6b6b6b6b6b6b6b6b: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC NOPTI ... Call Trace: <TASK> fprobe_handler+0xc1/0x270 ? __pfx_bpf_testmod_init+0x10/0x10 ? __pfx_bpf_testmod_init+0x10/0x10 ? bpf_fentry_test1+0x5/0x10 ? bpf_fentry_test1+0x5/0x10 ? bpf_testmod_init+0x22/0x80 ? do_one_initcall+0x63/0x2e0 ? rcu_is_watching+0xd/0x40 ? kmalloc_trace+0xaf/0xc0 ? do_init_module+0x60/0x250 ? __do_sys_finit_module+0xac/0x120 ? do_syscall_64+0x37/0x90 ? entry_SYSCALL_64_after_hwframe+0x72/0xdc </TASK> In unregister_fprobe function we can't release fp->rethook while it's possible there are some of its users still running on another cpu. Moving rethook_free call after fp->ops is unregistered with unregister_ftrace_function call. Link: https://lore.kernel.org/all/[email protected]/ Fixes: 5b0ab78 ("fprobe: Add exit_handler support") Cc: [email protected] Reviewed-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]>
1 parent 6995e2d commit 5f81018

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

kernel/trace/fprobe.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,19 +364,13 @@ int unregister_fprobe(struct fprobe *fp)
364364
fp->ops.saved_func != fprobe_kprobe_handler))
365365
return -EINVAL;
366366

367-
/*
368-
* rethook_free() starts disabling the rethook, but the rethook handlers
369-
* may be running on other processors at this point. To make sure that all
370-
* current running handlers are finished, call unregister_ftrace_function()
371-
* after this.
372-
*/
373-
if (fp->rethook)
374-
rethook_free(fp->rethook);
375-
376367
ret = unregister_ftrace_function(&fp->ops);
377368
if (ret < 0)
378369
return ret;
379370

371+
if (fp->rethook)
372+
rethook_free(fp->rethook);
373+
380374
ftrace_free_filter(&fp->ops);
381375

382376
return ret;

0 commit comments

Comments
 (0)