linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tracing/fprobe: Fix to check whether fprobe is registered correctly
@ 2022-10-23 14:19 Masami Hiramatsu (Google)
  2022-10-24  7:01 ` Jiri Olsa
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Masami Hiramatsu (Google) @ 2022-10-23 14:19 UTC (permalink / raw)
  To: LKML; +Cc: Linux Trace Kernel, Masami Hiramatsu, Steven Rostedt, Jiri Olsa

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Since commit ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag
for fprobe") introduced fprobe_kprobe_handler() for fprobe::f_op::func,
unregister_fprobe() fails to unregister the registered if user specifies
FPROBE_FL_KPROBE_SHARED flag.
To check it correctly, it should confirm the fprobe::f_op::func is either
fprobe_handler() or fprobe_kprobe_handler().

Fixes: ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag for fprobe")
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
 kernel/trace/fprobe.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
index aac63ca9c3d1..9000d8ea6274 100644
--- a/kernel/trace/fprobe.c
+++ b/kernel/trace/fprobe.c
@@ -301,7 +301,8 @@ int unregister_fprobe(struct fprobe *fp)
 {
 	int ret;
 
-	if (!fp || fp->ops.func != fprobe_handler)
+	if (!fp || (fp->ops.func != fprobe_handler &&
+		    fp->ops.func != fprobe_kprobe_handler))
 		return -EINVAL;
 
 	/*


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tracing/fprobe: Fix to check whether fprobe is registered correctly
  2022-10-23 14:19 [PATCH] tracing/fprobe: Fix to check whether fprobe is registered correctly Masami Hiramatsu (Google)
@ 2022-10-24  7:01 ` Jiri Olsa
  2022-10-24 14:22 ` Steven Rostedt
  2022-10-26  9:11 ` Masami Hiramatsu
  2 siblings, 0 replies; 5+ messages in thread
From: Jiri Olsa @ 2022-10-24  7:01 UTC (permalink / raw)
  To: Masami Hiramatsu (Google); +Cc: LKML, Linux Trace Kernel, Steven Rostedt

On Sun, Oct 23, 2022 at 11:19:33PM +0900, Masami Hiramatsu (Google) wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Since commit ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag
> for fprobe") introduced fprobe_kprobe_handler() for fprobe::f_op::func,
> unregister_fprobe() fails to unregister the registered if user specifies
> FPROBE_FL_KPROBE_SHARED flag.
> To check it correctly, it should confirm the fprobe::f_op::func is either
> fprobe_handler() or fprobe_kprobe_handler().
> 
> Fixes: ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag for fprobe")
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Acked-by: Jiri Olsa <jolsa@kernel.org>

jirka

> ---
>  kernel/trace/fprobe.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index aac63ca9c3d1..9000d8ea6274 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -301,7 +301,8 @@ int unregister_fprobe(struct fprobe *fp)
>  {
>  	int ret;
>  
> -	if (!fp || fp->ops.func != fprobe_handler)
> +	if (!fp || (fp->ops.func != fprobe_handler &&
> +		    fp->ops.func != fprobe_kprobe_handler))
>  		return -EINVAL;
>  
>  	/*
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tracing/fprobe: Fix to check whether fprobe is registered correctly
  2022-10-23 14:19 [PATCH] tracing/fprobe: Fix to check whether fprobe is registered correctly Masami Hiramatsu (Google)
  2022-10-24  7:01 ` Jiri Olsa
@ 2022-10-24 14:22 ` Steven Rostedt
  2022-10-25 14:36   ` Masami Hiramatsu
  2022-10-26  9:11 ` Masami Hiramatsu
  2 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2022-10-24 14:22 UTC (permalink / raw)
  To: Masami Hiramatsu (Google); +Cc: LKML, Linux Trace Kernel, Jiri Olsa

On Sun, 23 Oct 2022 23:19:33 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Since commit ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag
> for fprobe") introduced fprobe_kprobe_handler() for fprobe::f_op::func,
> unregister_fprobe() fails to unregister the registered if user specifies
> FPROBE_FL_KPROBE_SHARED flag.
> To check it correctly, it should confirm the fprobe::f_op::func is either
> fprobe_handler() or fprobe_kprobe_handler().
> 
> Fixes: ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag for fprobe")
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
>  kernel/trace/fprobe.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index aac63ca9c3d1..9000d8ea6274 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -301,7 +301,8 @@ int unregister_fprobe(struct fprobe *fp)
>  {
>  	int ret;
>  
> -	if (!fp || fp->ops.func != fprobe_handler)
> +	if (!fp || (fp->ops.func != fprobe_handler &&
> +		    fp->ops.func != fprobe_kprobe_handler))
>  		return -EINVAL;
>  
>  	/*

Should we make this more paranoid?

	if (!fp ||
	    (fprobe_shared_with_kprobes(fp) && fp->ops.func != fprobe_kprobe_handler) ||
	    (!fprobe_shared_with_kprobes(fp) && fp->ops.func != fprobe_handler))

Or is that over-kill?

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tracing/fprobe: Fix to check whether fprobe is registered correctly
  2022-10-24 14:22 ` Steven Rostedt
@ 2022-10-25 14:36   ` Masami Hiramatsu
  0 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2022-10-25 14:36 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: LKML, Linux Trace Kernel, Jiri Olsa

On Mon, 24 Oct 2022 10:22:30 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Sun, 23 Oct 2022 23:19:33 +0900
> "Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:
> 
> > From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > 
> > Since commit ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag
> > for fprobe") introduced fprobe_kprobe_handler() for fprobe::f_op::func,
> > unregister_fprobe() fails to unregister the registered if user specifies
> > FPROBE_FL_KPROBE_SHARED flag.
> > To check it correctly, it should confirm the fprobe::f_op::func is either
> > fprobe_handler() or fprobe_kprobe_handler().
> > 
> > Fixes: ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag for fprobe")
> > Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> > ---
> >  kernel/trace/fprobe.c |    3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> > index aac63ca9c3d1..9000d8ea6274 100644
> > --- a/kernel/trace/fprobe.c
> > +++ b/kernel/trace/fprobe.c
> > @@ -301,7 +301,8 @@ int unregister_fprobe(struct fprobe *fp)
> >  {
> >  	int ret;
> >  
> > -	if (!fp || fp->ops.func != fprobe_handler)
> > +	if (!fp || (fp->ops.func != fprobe_handler &&
> > +		    fp->ops.func != fprobe_kprobe_handler))
> >  		return -EINVAL;
> >  
> >  	/*
> 
> Should we make this more paranoid?
> 
> 	if (!fp ||
> 	    (fprobe_shared_with_kprobes(fp) && fp->ops.func != fprobe_kprobe_handler) ||
> 	    (!fprobe_shared_with_kprobes(fp) && fp->ops.func != fprobe_handler))
> 
> Or is that over-kill?

Yeah, I think it is over-kill since this is just for a safety check, like
checking NULL in free(). Or, are there any way to check the ftrace_ops is
registered?

Thank you,

> 
> -- Steve


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tracing/fprobe: Fix to check whether fprobe is registered correctly
  2022-10-23 14:19 [PATCH] tracing/fprobe: Fix to check whether fprobe is registered correctly Masami Hiramatsu (Google)
  2022-10-24  7:01 ` Jiri Olsa
  2022-10-24 14:22 ` Steven Rostedt
@ 2022-10-26  9:11 ` Masami Hiramatsu
  2 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2022-10-26  9:11 UTC (permalink / raw)
  To: Masami Hiramatsu (Google)
  Cc: LKML, Linux Trace Kernel, Steven Rostedt, Jiri Olsa

On Sun, 23 Oct 2022 23:19:33 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Since commit ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag
> for fprobe") introduced fprobe_kprobe_handler() for fprobe::f_op::func,
> unregister_fprobe() fails to unregister the registered if user specifies
> FPROBE_FL_KPROBE_SHARED flag.
> To check it correctly, it should confirm the fprobe::f_op::func is either
> fprobe_handler() or fprobe_kprobe_handler().
> 
> Fixes: ab51e15d535e ("fprobe: Introduce FPROBE_FL_KPROBE_SHARED flag for fprobe")
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> ---
>  kernel/trace/fprobe.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c
> index aac63ca9c3d1..9000d8ea6274 100644
> --- a/kernel/trace/fprobe.c
> +++ b/kernel/trace/fprobe.c
> @@ -301,7 +301,8 @@ int unregister_fprobe(struct fprobe *fp)
>  {
>  	int ret;
>  
> -	if (!fp || fp->ops.func != fprobe_handler)
> +	if (!fp || (fp->ops.func != fprobe_handler &&
> +		    fp->ops.func != fprobe_kprobe_handler))

Oops, ops.func can be changed by ftrace itself. Hmm, maybe I should check fp->ops.saved_func instead.

Thank you,

>  		return -EINVAL;
>  
>  	/*
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-26  9:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-23 14:19 [PATCH] tracing/fprobe: Fix to check whether fprobe is registered correctly Masami Hiramatsu (Google)
2022-10-24  7:01 ` Jiri Olsa
2022-10-24 14:22 ` Steven Rostedt
2022-10-25 14:36   ` Masami Hiramatsu
2022-10-26  9:11 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).