From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Jiri Olsa <jolsa@kernel.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 v2] fprobe: Ensure running fprobe_exit_handler() finished before calling rethook_free()
Date: Tue, 11 Jul 2023 09:06:53 +0900 [thread overview]
Message-ID: <20230711090653.35e4cf97b2a9fcdd6e1b6884@kernel.org> (raw)
In-Reply-To: <20230710180422.572d7c21@gandalf.local.home>
On Mon, 10 Jul 2023 18:04:22 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Fri, 7 Jul 2023 23:03:19 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
>
> > From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> >
> > Ensure running fprobe_exit_handler() has finished before
> > calling rethook_free() in the unregister_fprobe() so that caller can free
> > the fprobe right after unregister_fprobe().
> >
> > unregister_fprobe() ensured that all running fprobe_entry/exit_handler()
> > have finished by calling unregister_ftrace_function() which synchronizes
> > RCU. But commit 5f81018753df ("fprobe: Release rethook after the ftrace_ops
> > is unregistered") changed to call rethook_free() after
> > unregister_ftrace_function(). So call rethook_stop() to make rethook
> > disabled before unregister_ftrace_function() and ensure it again.
> >
> > Here is the possible code flow that can call the exit handler after
> > unregister_fprobe().
> >
> > ------
> > CPU1 CPU2
> > call unregister_fprobe(fp)
> > ...
> > __fprobe_handler()
> > rethook_hook() on probed function
> > unregister_ftrace_function()
> > return from probed function
> > rethook hooks
> > find rh->handler == fprobe_exit_handler
> > call fprobe_exit_handler()
> > rethook_free():
> > set rh->handler = NULL;
> > return from unreigster_fprobe;
> > call fp->exit_handler() <- (*)
> > ------
> >
> > (*) At this point, the exit handler is called after returning from
> > unregister_fprobe().
> >
> > This fixes it as following;
> > ------
> > CPU1 CPU2
> > call unregister_fprobe()
> > ...
> > rethook_stop():
> > set rh->handler = NULL;
> > __fprobe_handler()
> > rethook_hook() on probed function
> > unregister_ftrace_function()
> > return from probed function
> > rethook hooks
> > find rh->handler == NULL
> > return from rethook
> > rethook_free()
> > return from unreigster_fprobe;
> > ------
> >
> >
> > Fixes: 5f81018753df ("fprobe: Release rethook after the ftrace_ops is unregistered")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
>
> Looks good.
>
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Thank you :)
>
>
> > ---
> > Changes in v2:
> > - Update changelog to add a problematic code flow.
>
> Nit, for making forensic analysis easier in the future, I now always add a
> link to the previous version. That is:
>
> Changes since v1: https://lore.kernel.org/linux-trace-kernel/168796344232.46347.7947681068822514750.stgit@devnote2/
> - Update changelog to add a problematic code flow.
OK, I'll add it for an isolated patch too.
Thanks!
>
> -- Steve
>
>
> > ---
> > include/linux/rethook.h | 1 +
> > kernel/trace/fprobe.c | 3 +++
> > kernel/trace/rethook.c | 13 +++++++++++++
> > 3 files changed, 17 insertions(+)
> >
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
prev parent reply other threads:[~2023-07-11 0:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-07 14:03 [PATCH v2] fprobe: Ensure running fprobe_exit_handler() finished before calling rethook_free() Masami Hiramatsu (Google)
2023-07-10 22:04 ` Steven Rostedt
2023-07-11 0:06 ` Masami Hiramatsu [this message]
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=20230711090653.35e4cf97b2a9fcdd6e1b6884@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