From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Jiri Olsa <jolsa@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Mark Rutland <mark.rutland@arm.com>,
lkml <linux-kernel@vger.kernel.org>,
linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH] fprobe: Release rethook after the ftrace_ops is unregistered
Date: Tue, 27 Jun 2023 23:33:06 +0900 [thread overview]
Message-ID: <20230627233306.b9b04d75f86944466f6534c2@kernel.org> (raw)
In-Reply-To: <20230615115236.3476617-1-jolsa@kernel.org>
Hi Jiri,
On Thu, 15 Jun 2023 13:52:36 +0200
Jiri Olsa <jolsa@kernel.org> wrote:
> 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.
Ah, OK. rethook_free() invoked call_rcu(rethook_free_rcu) to free the
rethook, and it is possible rethook_free_rcu() is called before disabling
all fprobe, then `rethook_try_get(fp->rethook)` will access fp->rethook
which has been freed.
>
> Moving rethook_free call after fp->ops is unregistered with
> unregister_ftrace_function call.
>
> Fixes: 5b0ab78998e3 ("fprobe: Add exit_handler support")
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thank you!
> ---
> kernel/trace/fprobe.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> 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);
> -
> 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;
> --
> 2.40.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2023-06-27 14:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-15 11:52 [PATCH] fprobe: Release rethook after the ftrace_ops is unregistered Jiri Olsa
2023-06-15 12:59 ` Steven Rostedt
2023-06-23 11:11 ` Jiri Olsa
2023-06-27 14:33 ` Masami Hiramatsu [this message]
2023-06-27 16:23 ` Masami Hiramatsu
2023-06-28 14:44 ` [PATCH] fprobe: Ensure running fprobe_exit_handler() finished before calling rethook_free() Masami Hiramatsu (Google)
2023-07-05 23:59 ` Masami Hiramatsu
2023-07-06 1:26 ` Steven Rostedt
2023-07-06 5:10 ` Masami Hiramatsu
2023-07-06 13:56 ` Steven Rostedt
2023-07-07 0:17 ` Masami Hiramatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230627233306.b9b04d75f86944466f6534c2@kernel.org \
--to=mhiramat@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox