Skip to contentSkip to conversation

tracing/uprobe: Fix uprobe_perf_open probes iteration

GIT PULL Merged Steven Rostedt 4 participants 6 messages Nov 24, 2021 Tracing

lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

Linus,

tracing: Fix wrong uprobe variable in iterator

uprobe_perf_open() processes a list of probes, but due to a missing setting of the uprobe to be processed, the loop processes the head probe instead of the added probes.

Please pull the latest trace-v5.16-rc2 tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v5.16-rc2

Tag SHA1: b035fc0d660c88f1ec940aba668d438c96ea1a5c Head SHA1: 1880ed71ce863318c1ce93bf324876fb5f92854f

Jiri Olsa (1):
tracing/uprobe: Fix uprobe_perf_open probes iteration

----

 kernel/trace/trace_uprobe.c | 1 +
 1 file changed, 1 insertion(+)
---------------------------
commit 1880ed71ce863318c1ce93bf324876fb5f92854f
Author: Jiri Olsa <[email protected]>
Date:   Tue Nov 23 15:28:01 2021 +0100

tracing/uprobe: Fix uprobe_perf_open probes iteration

Add missing 'tu' variable initialization in the probes loop, otherwise the head 'tu' is used instead of added probes.

Fixes 99c9a923e97a ("tracing/uprobe: Fix double perf_event linking on multiprobe uprobe")
kernel/trace/trace_uprobe.c +1 -0
index 0a5c0db3137e..f5f0039d31e5 100644
@@ -1313,6 +1313,7 @@ static int uprobe_perf_open(struct trace_event_call *call,
 		return 0;
 
 	list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
+		tu = container_of(pos, struct trace_uprobe, tp);
 		err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
 		if (err) {
 			uprobe_perf_close(call, event);
#1 lore raw
Quoted 2 lines · Steven Rostedt

tracing: Fix wrong uprobe variable in iterator

I've pulled this, but:

Quoted 2 lines
        list_for_each_entry(pos, trace_probe_probe_list(tp), list) {

+ tu = container_of(pos, struct trace_uprobe, tp);

honestly, the "list_for_each_entry()" followed by a "container_of()" like this makes me think you used the wrong entry to walk the list in.

You actually don't want to ever use that

        struct trace_probe *pos;

at all, and I think you should remove it.

Instead, you should do something like

        list_for_each_entry(pu, trace_probe_probe_list(tp), tp.list) {

ie simply walk the list _as_ the uprobe entry, not as some intermediate internal probe list entry only to convert to the uprobe.

Now, I may be entirely off my meds here, and maybe there is something I'm missing, but I _think_ the attached patch should work, and avoid all that indirection through 'pos' that you don't care about and that seems to just have been a mistake.

Feel free to call me funny names for when I missed some detail.

Again - I *have* pulled your fix, and in fact the attached patch is relative to your fix. That fix isn't _wrong_. I just think it's a bit silly, and I think the cause of the bug in the first place was that unnecessary intermediate pointer.

Linus

 kernel/trace/trace_uprobe.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/trace/trace_uprobe.c +2 -3
index f5f0039d31e5..ee5408f2a68a 100644
@@ -1300,7 +1300,7 @@ static int uprobe_perf_close(struct trace_event_call *call,
 static int uprobe_perf_open(struct trace_event_call *call,
 			    struct perf_event *event)
 {
-	struct trace_probe *pos, *tp;
+	struct trace_probe *tp;
 	struct trace_uprobe *tu;
 	int err = 0;
 
@@ -1312,8 +1312,7 @@ static int uprobe_perf_open(struct trace_event_call *call,
 	if (trace_uprobe_filter_add(tu->tp.event->filter, event))
 		return 0;
 
-	list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
-		tu = container_of(pos, struct trace_uprobe, tp);
+	list_for_each_entry(tu, trace_probe_probe_list(tp), tp.list) {
 		err = uprobe_apply(tu->inode, tu->offset, &tu->consumer, true);
 		if (err) {
 			uprobe_perf_close(call, event);
#2 lore raw
Quoted 4 lines · Linus Torvalds

Instead, you should do something like

        list_for_each_entry(pu, trace_probe_probe_list(tp), tp.list) {

That 'pu' is a typo, it should be 'tu'.

The patch itself got it right, I think.

HOWEVER. Despite the patch itself getting it right, I want to point out that that was mostly by luck than anything else.

The patch is ENTIRELY UNTESTED.

Because that's how I roll, as you should all know by now.

Linus

#3 lore raw
Quoted 7 lines · Linus Torvalds
Quoted 4 lines · Linus Torvalds

Instead, you should do something like

        list_for_each_entry(pu, trace_probe_probe_list(tp), tp.list) {
Quoted 8 lines

That 'pu' is a typo, it should be 'tu'.

The patch itself got it right, I think.

HOWEVER. Despite the patch itself getting it right, I want to point out that that was mostly by luck than anything else.

The patch is ENTIRELY UNTESTED.

I put your patch to the test and.. it passed ;-)

there are several other places like this around and also in trace_kprobe.c I can send the follow up fix tomorrow

thanks,
jirka

Quoted 5 lines

Because that's how I roll, as you should all know by now.

Linus

author maintainer
#4 lore raw
In reply to Linus Torvalds
Quoted 5 lines · On Wed, 24 Nov 2021 10:27:27 -0800 Linus Torvalds…

Now, I may be entirely off my meds here, and maybe there is something I'm missing, but I _think_ the attached patch should work, and avoid all that indirection through 'pos' that you don't care about and that seems to just have been a mistake.

Masami and Jiri,

This is your code. Would this be a legitimate clean up?

-- Steve

merge bot Merged
#5 lore raw
In reply to Steven Rostedt
The pull request you sent on Wed, 24 Nov 2021 10:09:56 -0500:

The pull request you sent on Wed, 24 Nov 2021 10:09:56 -0500:

Quoted 1 line

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git trace-v5.16-rc2

has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/29889216befc1cee635da8a64f48caae47ffbcaf

Thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/prtracker.html