stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] tracing: Check pid filtering when creating events" failed to apply to 5.10-stable tree
@ 2021-11-28 11:44 gregkh
  2021-11-28 18:48 ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: gregkh @ 2021-11-28 11:44 UTC (permalink / raw)
  To: rostedt; +Cc: stable


The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 6cb206508b621a9a0a2c35b60540e399225c8243 Mon Sep 17 00:00:00 2001
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Date: Fri, 26 Nov 2021 13:35:26 -0500
Subject: [PATCH] tracing: Check pid filtering when creating events

When pid filtering is activated in an instance, all of the events trace
files for that instance has the PID_FILTER flag set. This determines
whether or not pid filtering needs to be done on the event, otherwise the
event is executed as normal.

If pid filtering is enabled when an event is created (via a dynamic event
or modules), its flag is not updated to reflect the current state, and the
events are not filtered properly.

Cc: stable@vger.kernel.org
Fixes: 3fdaf80f4a836 ("tracing: Implement event pid filtering")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 4021b9a79f93..f8965fd50d3b 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -2678,12 +2678,24 @@ static struct trace_event_file *
 trace_create_new_event(struct trace_event_call *call,
 		       struct trace_array *tr)
 {
+	struct trace_pid_list *no_pid_list;
+	struct trace_pid_list *pid_list;
 	struct trace_event_file *file;
+	unsigned int first;
 
 	file = kmem_cache_alloc(file_cachep, GFP_TRACE);
 	if (!file)
 		return NULL;
 
+	pid_list = rcu_dereference_protected(tr->filtered_pids,
+					     lockdep_is_held(&event_mutex));
+	no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
+					     lockdep_is_held(&event_mutex));
+
+	if (!trace_pid_list_first(pid_list, &first) ||
+	    !trace_pid_list_first(pid_list, &first))
+		file->flags |= EVENT_FILE_FL_PID_FILTER;
+
 	file->event_call = call;
 	file->tr = tr;
 	atomic_set(&file->sm_ref, 0);


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

* Re: FAILED: patch "[PATCH] tracing: Check pid filtering when creating events" failed to apply to 5.10-stable tree
  2021-11-28 11:44 FAILED: patch "[PATCH] tracing: Check pid filtering when creating events" failed to apply to 5.10-stable tree gregkh
@ 2021-11-28 18:48 ` Steven Rostedt
  2021-11-28 19:10   ` Steven Rostedt
  2021-11-29 12:16   ` Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: Steven Rostedt @ 2021-11-28 18:48 UTC (permalink / raw)
  To: gregkh; +Cc: stable

On Sun, 28 Nov 2021 12:44:01 +0100
<gregkh@linuxfoundation.org> wrote:

> The patch below does not apply to the 5.10-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.

This is a funny case, where I actually found the bug in the 5.15 kernel
that I was using to do my cut and paste screen shots for the upcoming
Embedded Fest conference I'll be giving a talk at on Friday.

I wrote this fix for 5.15 first (to continue working on my
presentation), and since stable requires upstream to have the fix, I
forward ported it to 5.16-rc. As 5.16 introduced changes in this code,
the forward port had to do things differently, and my forward port
added a bug which the fix has just been added:

  https://git.kernel.org/torvalds/c/f8132d62a2deedca1b7558028cfe72f93ad5ba2d

That fix does not need to be backported, as the origin 5.15 patch did
not have that bug.

This is the original 5.15 patch I used to create the 5.16 version with,
and it should also fix 5.10. Kernels before 5.7 will need a different
patch, as it did not have the "no_pid" feature yet. I'll send out the
fix for those kernels later.

-- Steve

Upstream commit: 6cb206508b621a9a0a2c35b60540e399225c8243

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH] tracing: Check pid filtering when creating events

When pid filtering is activated in an instance, all of the events trace
files for that instance has the PID_FILTER flag set. This determines
whether or not pid filtering needs to be done on the event, otherwise the
event is executed as normal.

If pid filtering is enabled when an event is created (via a dynamic event
or modules), its flag is not updated to reflect the current state, and the
events are not filtered properly.

Cc: stable@vger.kernel.org
Fixes: 3fdaf80f4a836 ("tracing: Implement event pid filtering")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/trace_events.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 830b3b9940f4..e760e078c733 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -2677,12 +2677,23 @@ static struct trace_event_file *
 trace_create_new_event(struct trace_event_call *call,
 		       struct trace_array *tr)
 {
+	struct trace_pid_list *no_pid_list;
+	struct trace_pid_list *pid_list;
 	struct trace_event_file *file;
+	unsigned int first;
 
 	file = kmem_cache_alloc(file_cachep, GFP_TRACE);
 	if (!file)
 		return NULL;
 
+	pid_list = rcu_dereference_protected(tr->filtered_pids,
+					     lockdep_is_held(&event_mutex));
+	no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
+					     lockdep_is_held(&event_mutex));
+
+	if (pid_list || no_pid_list)
+		file->flags |= EVENT_FILE_FL_PID_FILTER;
+
 	file->event_call = call;
 	file->tr = tr;
 	atomic_set(&file->sm_ref, 0);
-- 
2.33.0


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

* Re: FAILED: patch "[PATCH] tracing: Check pid filtering when creating events" failed to apply to 5.10-stable tree
  2021-11-28 18:48 ` Steven Rostedt
@ 2021-11-28 19:10   ` Steven Rostedt
  2021-11-29 12:16     ` Greg KH
  2021-11-29 12:16   ` Greg KH
  1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2021-11-28 19:10 UTC (permalink / raw)
  To: gregkh; +Cc: stable

On Sun, 28 Nov 2021 13:48:05 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> +++ b/kernel/trace/trace_events.c
> @@ -2677,12 +2677,23 @@ static struct trace_event_file *
>  trace_create_new_event(struct trace_event_call *call,
>  		       struct trace_array *tr)
>  {
> +	struct trace_pid_list *no_pid_list;
> +	struct trace_pid_list *pid_list;
>  	struct trace_event_file *file;
> +	unsigned int first;
>  

And even though this was the first fix, I somehow got a bit of the 5.16
patch in here, as the "first" variable is only used for that.

Take two:

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Subject: [PATCH] tracing: Check pid filtering when creating events

When pid filtering is activated in an instance, all of the events trace
files for that instance has the PID_FILTER flag set. This determines
whether or not pid filtering needs to be done on the event, otherwise the
event is executed as normal.

If pid filtering is enabled when an event is created (via a dynamic event
or modules), its flag is not updated to reflect the current state, and the
events are not filtered properly.

Cc: stable@vger.kernel.org
Fixes: 3fdaf80f4a836 ("tracing: Implement event pid filtering")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/trace_events.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Index: linux-test.git/kernel/trace/trace_events.c
===================================================================
--- linux-test.git.orig/kernel/trace/trace_events.c
+++ linux-test.git/kernel/trace/trace_events.c
@@ -2462,12 +2462,22 @@ static struct trace_event_file *
 trace_create_new_event(struct trace_event_call *call,
 		       struct trace_array *tr)
 {
+	struct trace_pid_list *no_pid_list;
+	struct trace_pid_list *pid_list;
 	struct trace_event_file *file;
 
 	file = kmem_cache_alloc(file_cachep, GFP_TRACE);
 	if (!file)
 		return NULL;
 
+	pid_list = rcu_dereference_protected(tr->filtered_pids,
+					     lockdep_is_held(&event_mutex));
+	no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
+					     lockdep_is_held(&event_mutex));
+
+	if (pid_list || no_pid_list)
+		file->flags |= EVENT_FILE_FL_PID_FILTER;
+
 	file->event_call = call;
 	file->tr = tr;
 	atomic_set(&file->sm_ref, 0);

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

* Re: FAILED: patch "[PATCH] tracing: Check pid filtering when creating events" failed to apply to 5.10-stable tree
  2021-11-28 18:48 ` Steven Rostedt
  2021-11-28 19:10   ` Steven Rostedt
@ 2021-11-29 12:16   ` Greg KH
  1 sibling, 0 replies; 5+ messages in thread
From: Greg KH @ 2021-11-29 12:16 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: stable

On Sun, Nov 28, 2021 at 01:48:05PM -0500, Steven Rostedt wrote:
> On Sun, 28 Nov 2021 12:44:01 +0100
> <gregkh@linuxfoundation.org> wrote:
> 
> > The patch below does not apply to the 5.10-stable tree.
> > If someone wants it applied there, or to any other stable or longterm
> > tree, then please email the backport, including the original git commit
> > id to <stable@vger.kernel.org>.
> 
> This is a funny case, where I actually found the bug in the 5.15 kernel
> that I was using to do my cut and paste screen shots for the upcoming
> Embedded Fest conference I'll be giving a talk at on Friday.
> 
> I wrote this fix for 5.15 first (to continue working on my
> presentation), and since stable requires upstream to have the fix, I
> forward ported it to 5.16-rc. As 5.16 introduced changes in this code,
> the forward port had to do things differently, and my forward port
> added a bug which the fix has just been added:
> 
>   https://git.kernel.org/torvalds/c/f8132d62a2deedca1b7558028cfe72f93ad5ba2d
> 
> That fix does not need to be backported, as the origin 5.15 patch did
> not have that bug.
> 
> This is the original 5.15 patch I used to create the 5.16 version with,
> and it should also fix 5.10. Kernels before 5.7 will need a different
> patch, as it did not have the "no_pid" feature yet. I'll send out the
> fix for those kernels later.
> 
> -- Steve
> 
> Upstream commit: 6cb206508b621a9a0a2c35b60540e399225c8243
> 
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> Subject: [PATCH] tracing: Check pid filtering when creating events
> 
> When pid filtering is activated in an instance, all of the events trace
> files for that instance has the PID_FILTER flag set. This determines
> whether or not pid filtering needs to be done on the event, otherwise the
> event is executed as normal.
> 
> If pid filtering is enabled when an event is created (via a dynamic event
> or modules), its flag is not updated to reflect the current state, and the
> events are not filtered properly.
> 
> Cc: stable@vger.kernel.org
> Fixes: 3fdaf80f4a836 ("tracing: Implement event pid filtering")
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>  kernel/trace/trace_events.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 830b3b9940f4..e760e078c733 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -2677,12 +2677,23 @@ static struct trace_event_file *
>  trace_create_new_event(struct trace_event_call *call,
>  		       struct trace_array *tr)
>  {
> +	struct trace_pid_list *no_pid_list;
> +	struct trace_pid_list *pid_list;
>  	struct trace_event_file *file;
> +	unsigned int first;
>  
>  	file = kmem_cache_alloc(file_cachep, GFP_TRACE);
>  	if (!file)
>  		return NULL;
>  
> +	pid_list = rcu_dereference_protected(tr->filtered_pids,
> +					     lockdep_is_held(&event_mutex));
> +	no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
> +					     lockdep_is_held(&event_mutex));
> +
> +	if (pid_list || no_pid_list)
> +		file->flags |= EVENT_FILE_FL_PID_FILTER;
> +
>  	file->event_call = call;
>  	file->tr = tr;
>  	atomic_set(&file->sm_ref, 0);
> -- 
> 2.33.0

Why did you add the first variable here?

I get the build failure:

kernel/trace/trace_events.c: In function ‘trace_create_new_event’:
kernel/trace/trace_events.c:2684:22: error: unused variable ‘first’ [-Werror=unused-variable]
 2684 |         unsigned int first;
      |                      ^~~~~
cc1: all warnings being treated as errors

because of that.

I'll go remove that line, but please, test-build your patches at the
very least :)

thanks,

greg k-h

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

* Re: FAILED: patch "[PATCH] tracing: Check pid filtering when creating events" failed to apply to 5.10-stable tree
  2021-11-28 19:10   ` Steven Rostedt
@ 2021-11-29 12:16     ` Greg KH
  0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2021-11-29 12:16 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: stable

On Sun, Nov 28, 2021 at 02:10:15PM -0500, Steven Rostedt wrote:
> On Sun, 28 Nov 2021 13:48:05 -0500
> Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> > +++ b/kernel/trace/trace_events.c
> > @@ -2677,12 +2677,23 @@ static struct trace_event_file *
> >  trace_create_new_event(struct trace_event_call *call,
> >  		       struct trace_array *tr)
> >  {
> > +	struct trace_pid_list *no_pid_list;
> > +	struct trace_pid_list *pid_list;
> >  	struct trace_event_file *file;
> > +	unsigned int first;
> >  
> 
> And even though this was the first fix, I somehow got a bit of the 5.16
> patch in here, as the "first" variable is only used for that.
> 
> Take two:
> 
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> Subject: [PATCH] tracing: Check pid filtering when creating events
> 
> When pid filtering is activated in an instance, all of the events trace
> files for that instance has the PID_FILTER flag set. This determines
> whether or not pid filtering needs to be done on the event, otherwise the
> event is executed as normal.
> 
> If pid filtering is enabled when an event is created (via a dynamic event
> or modules), its flag is not updated to reflect the current state, and the
> events are not filtered properly.
> 
> Cc: stable@vger.kernel.org
> Fixes: 3fdaf80f4a836 ("tracing: Implement event pid filtering")
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>  kernel/trace/trace_events.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> Index: linux-test.git/kernel/trace/trace_events.c
> ===================================================================
> --- linux-test.git.orig/kernel/trace/trace_events.c
> +++ linux-test.git/kernel/trace/trace_events.c
> @@ -2462,12 +2462,22 @@ static struct trace_event_file *
>  trace_create_new_event(struct trace_event_call *call,
>  		       struct trace_array *tr)
>  {
> +	struct trace_pid_list *no_pid_list;
> +	struct trace_pid_list *pid_list;
>  	struct trace_event_file *file;
>  
>  	file = kmem_cache_alloc(file_cachep, GFP_TRACE);
>  	if (!file)
>  		return NULL;
>  
> +	pid_list = rcu_dereference_protected(tr->filtered_pids,
> +					     lockdep_is_held(&event_mutex));
> +	no_pid_list = rcu_dereference_protected(tr->filtered_no_pids,
> +					     lockdep_is_held(&event_mutex));
> +
> +	if (pid_list || no_pid_list)
> +		file->flags |= EVENT_FILE_FL_PID_FILTER;
> +
>  	file->event_call = call;
>  	file->tr = tr;
>  	atomic_set(&file->sm_ref, 0);

Oops, now I see this one, thanks...

greg "read the whole thread before reponding" k-h

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

end of thread, other threads:[~2021-11-29 13:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-28 11:44 FAILED: patch "[PATCH] tracing: Check pid filtering when creating events" failed to apply to 5.10-stable tree gregkh
2021-11-28 18:48 ` Steven Rostedt
2021-11-28 19:10   ` Steven Rostedt
2021-11-29 12:16     ` Greg KH
2021-11-29 12:16   ` Greg KH

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).