2021-11-24 15:10:02

by Steven Rostedt

[permalink] [raw]
Subject: [GIT PULL] tracing/uprobe: Fix uprobe_perf_open probes iteration

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.

Link: https://lkml.kernel.org/r/[email protected]

Cc: [email protected]
Fixes: 99c9a923e97a ("tracing/uprobe: Fix double perf_event linking on multiprobe uprobe")
Acked-by: Masami Hiramatsu <[email protected]>
Signed-off-by: Jiri Olsa <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>

diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index 0a5c0db3137e..f5f0039d31e5 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -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);


2021-11-24 18:27:55

by Linus Torvalds

[permalink] [raw]
Subject: Re: [GIT PULL] tracing/uprobe: Fix uprobe_perf_open probes iteration

On Wed, Nov 24, 2021 at 7:10 AM Steven Rostedt <[email protected]> wrote:
>
> tracing: Fix wrong uprobe variable in iterator

I've pulled this, but:

> 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


Attachments:
patch.diff (0.98 kB)

2021-11-24 18:30:45

by Linus Torvalds

[permalink] [raw]
Subject: Re: [GIT PULL] tracing/uprobe: Fix uprobe_perf_open probes iteration

On Wed, Nov 24, 2021 at 10:27 AM Linus Torvalds
<[email protected]> wrote:
>
> 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

2021-11-24 18:31:47

by pr-tracker-bot

[permalink] [raw]
Subject: Re: [GIT PULL] tracing/uprobe: Fix uprobe_perf_open probes iteration

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

> 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!

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

2021-11-24 18:33:11

by Steven Rostedt

[permalink] [raw]
Subject: Re: [GIT PULL] tracing/uprobe: Fix uprobe_perf_open probes iteration

On Wed, 24 Nov 2021 10:27:27 -0800
Linus Torvalds <[email protected]> wrote:

> 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

2021-11-24 20:06:16

by Jiri Olsa

[permalink] [raw]
Subject: Re: [GIT PULL] tracing/uprobe: Fix uprobe_perf_open probes iteration

On Wed, Nov 24, 2021 at 10:30:24AM -0800, Linus Torvalds wrote:
> On Wed, Nov 24, 2021 at 10:27 AM Linus Torvalds
> <[email protected]> wrote:
> >
> > 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.

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

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