LKML Archive on lore.kernel.org
 help / Atom feed
* [PATCH] kprobes: fix trace_probe flags in enable_trace_kprobe
@ 2018-07-25 10:28 Artem Savkov
  2018-07-25 13:21 ` Steven Rostedt
  2018-07-25 13:56 ` Josh Poimboeuf
  0 siblings, 2 replies; 5+ messages in thread
From: Artem Savkov @ 2018-07-25 10:28 UTC (permalink / raw)
  To: Steven Rostedt, Ingo Molnar; +Cc: linux-kernel, Josh Poimboeuf, Artem Savkov

If enable_trace_kprobe fails to enable the probe in enable_k(ret)probe
it returns an error, but does not unset the tp flags it set previosly.
This results in a probe being considered enabled and failures like being
unable to remove the probe through kprobe_events file since probes_open()
expects every probe to be disabled.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
---
 kernel/trace/trace_kprobe.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 21f718472942..fb887ced5056 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -400,11 +400,10 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
 static int
 enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
 {
+	struct event_file_link *link;
 	int ret = 0;
 
 	if (file) {
-		struct event_file_link *link;
-
 		link = kmalloc(sizeof(*link), GFP_KERNEL);
 		if (!link) {
 			ret = -ENOMEM;
@@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
 		else
 			ret = enable_kprobe(&tk->rp.kp);
 	}
+
+	if (ret) {
+		if (file) {
+			list_del(&link->list);
+			kfree(link);
+			tk->tp.flags &= ~TP_FLAG_TRACE;
+		} else {
+			tk->tp.flags &= ~TP_FLAG_PROFILE;
+		}
+	}
  out:
 	return ret;
 }
-- 
2.13.6


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

* Re: [PATCH] kprobes: fix trace_probe flags in enable_trace_kprobe
  2018-07-25 10:28 [PATCH] kprobes: fix trace_probe flags in enable_trace_kprobe Artem Savkov
@ 2018-07-25 13:21 ` Steven Rostedt
  2018-07-25 15:35   ` Masami Hiramatsu
  2018-07-25 13:56 ` Josh Poimboeuf
  1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2018-07-25 13:21 UTC (permalink / raw)
  To: Artem Savkov; +Cc: Ingo Molnar, linux-kernel, Josh Poimboeuf, Masami Hiramatsu


[ Adding Masami to Cc ]

On Wed, 25 Jul 2018 12:28:26 +0200
Artem Savkov <asavkov@redhat.com> wrote:

> If enable_trace_kprobe fails to enable the probe in enable_k(ret)probe
> it returns an error, but does not unset the tp flags it set previosly.
> This results in a probe being considered enabled and failures like being
> unable to remove the probe through kprobe_events file since probes_open()
> expects every probe to be disabled.
> 

Looks good to me. Masami, want to ack it?

-- Steve

> Signed-off-by: Artem Savkov <asavkov@redhat.com>
> ---
>  kernel/trace/trace_kprobe.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 21f718472942..fb887ced5056 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -400,11 +400,10 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
>  static int
>  enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
>  {
> +	struct event_file_link *link;
>  	int ret = 0;
>  
>  	if (file) {
> -		struct event_file_link *link;
> -
>  		link = kmalloc(sizeof(*link), GFP_KERNEL);
>  		if (!link) {
>  			ret = -ENOMEM;
> @@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
>  		else
>  			ret = enable_kprobe(&tk->rp.kp);
>  	}
> +
> +	if (ret) {
> +		if (file) {
> +			list_del(&link->list);
> +			kfree(link);
> +			tk->tp.flags &= ~TP_FLAG_TRACE;
> +		} else {
> +			tk->tp.flags &= ~TP_FLAG_PROFILE;
> +		}
> +	}
>   out:
>  	return ret;
>  }


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

* Re: [PATCH] kprobes: fix trace_probe flags in enable_trace_kprobe
  2018-07-25 10:28 [PATCH] kprobes: fix trace_probe flags in enable_trace_kprobe Artem Savkov
  2018-07-25 13:21 ` Steven Rostedt
@ 2018-07-25 13:56 ` Josh Poimboeuf
  2018-07-25 14:05   ` Steven Rostedt
  1 sibling, 1 reply; 5+ messages in thread
From: Josh Poimboeuf @ 2018-07-25 13:56 UTC (permalink / raw)
  To: Artem Savkov; +Cc: Steven Rostedt, Ingo Molnar, linux-kernel

On Wed, Jul 25, 2018 at 12:28:26PM +0200, Artem Savkov wrote:
> If enable_trace_kprobe fails to enable the probe in enable_k(ret)probe
> it returns an error, but does not unset the tp flags it set previosly.

"previously"

> @@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
>  		else
>  			ret = enable_kprobe(&tk->rp.kp);
>  	}
> +
> +	if (ret) {
> +		if (file) {
> +			list_del(&link->list);

Should this be list_del_rcu(), since it was added to the list with
list_add_tail_rcu()?

-- 
Josh

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

* Re: [PATCH] kprobes: fix trace_probe flags in enable_trace_kprobe
  2018-07-25 13:56 ` Josh Poimboeuf
@ 2018-07-25 14:05   ` Steven Rostedt
  0 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2018-07-25 14:05 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: Artem Savkov, Ingo Molnar, linux-kernel

On Wed, 25 Jul 2018 08:56:32 -0500
Josh Poimboeuf <jpoimboe@redhat.com> wrote:

> On Wed, Jul 25, 2018 at 12:28:26PM +0200, Artem Savkov wrote:
> > If enable_trace_kprobe fails to enable the probe in enable_k(ret)probe
> > it returns an error, but does not unset the tp flags it set previosly.  
> 
> "previously"

I tentatively added this to my queue. I updated the subject as:

 tracing/kprobes: Fix trace_probe flags on enable_trace_kprobe() failure

But yeah, that needs to be fixed.

> 
> > @@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
> >  		else
> >  			ret = enable_kprobe(&tk->rp.kp);
> >  	}
> > +
> > +	if (ret) {
> > +		if (file) {
> > +			list_del(&link->list);  
> 
> Should this be list_del_rcu(), since it was added to the list with
> list_add_tail_rcu()?
> 

Good catch. Yes, that should be list_del_rcu().

Artem,

Can you send a v2 with the changes.

Thanks,

-- Steve

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

* Re: [PATCH] kprobes: fix trace_probe flags in enable_trace_kprobe
  2018-07-25 13:21 ` Steven Rostedt
@ 2018-07-25 15:35   ` Masami Hiramatsu
  0 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2018-07-25 15:35 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Artem Savkov, Ingo Molnar, linux-kernel, Josh Poimboeuf,
	Masami Hiramatsu

On Wed, 25 Jul 2018 09:21:51 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> 
> [ Adding Masami to Cc ]
> 
> On Wed, 25 Jul 2018 12:28:26 +0200
> Artem Savkov <asavkov@redhat.com> wrote:
> 
> > If enable_trace_kprobe fails to enable the probe in enable_k(ret)probe
> > it returns an error, but does not unset the tp flags it set previosly.
> > This results in a probe being considered enabled and failures like being
> > unable to remove the probe through kprobe_events file since probes_open()
> > expects every probe to be disabled.
> > 
> 
> Looks good to me. Masami, want to ack it?

Yes, looks good to me too.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks Artem!

> 
> -- Steve
> 
> > Signed-off-by: Artem Savkov <asavkov@redhat.com>
> > ---
> >  kernel/trace/trace_kprobe.c | 13 +++++++++++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> > index 21f718472942..fb887ced5056 100644
> > --- a/kernel/trace/trace_kprobe.c
> > +++ b/kernel/trace/trace_kprobe.c
> > @@ -400,11 +400,10 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,
> >  static int
> >  enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
> >  {
> > +	struct event_file_link *link;
> >  	int ret = 0;
> >  
> >  	if (file) {
> > -		struct event_file_link *link;
> > -
> >  		link = kmalloc(sizeof(*link), GFP_KERNEL);
> >  		if (!link) {
> >  			ret = -ENOMEM;
> > @@ -424,6 +423,16 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)
> >  		else
> >  			ret = enable_kprobe(&tk->rp.kp);
> >  	}
> > +
> > +	if (ret) {
> > +		if (file) {
> > +			list_del(&link->list);
> > +			kfree(link);
> > +			tk->tp.flags &= ~TP_FLAG_TRACE;
> > +		} else {
> > +			tk->tp.flags &= ~TP_FLAG_PROFILE;
> > +		}
> > +	}
> >   out:
> >  	return ret;
> >  }
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-25 10:28 [PATCH] kprobes: fix trace_probe flags in enable_trace_kprobe Artem Savkov
2018-07-25 13:21 ` Steven Rostedt
2018-07-25 15:35   ` Masami Hiramatsu
2018-07-25 13:56 ` Josh Poimboeuf
2018-07-25 14:05   ` Steven Rostedt

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox