Skip to contentSkip to conversation

perf/cgroup: correct indirection in perf_less_group_idx

PATCH Superseded Ian Rogers 2 participants 3 messages Mar 21, 2020 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf/cgroup: correct indirection in perf_less_group_idx

The void* in perf_less_group_idx is to a cell in the array which points at a perf_event*, as such it is a perf_event**.

Fixes 6eef8a7116de ("perf/core: Use min_heap in visit_groups_merge()")

Author: John Sperbeck <[email protected]>

---
 kernel/events/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/events/core.c +2 -1
index d22e4ba59dfa..a758c2311c53 100644
@@ -3503,7 +3503,8 @@ static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
 
 static bool perf_less_group_idx(const void *l, const void *r)
 {
-	const struct perf_event *le = l, *re = r;
+	const struct perf_event *le = *(const struct perf_event **)l;
+	const struct perf_event *re = *(const struct perf_event **)r;
 
 	return le->group_index < re->group_index;
 }
Signature · 1 line
2.25.1.696.g5e7596f4ac-goog
maintainer
#1 lore raw
Quoted 5 lines · Ian Rogers

The void* in perf_less_group_idx is to a cell in the array which points at a perf_event*, as such it is a perf_event**.

Fixes 6eef8a7116de ("perf/core: Use min_heap in visit_groups_merge()")

Author: John Sperbeck <[email protected]>

That doesn't make sense, did he write the patch? Then there needs to be a From: him and a SoB: him, If he reported the issue, it should be
Reported-by: him.

Quoted 10 lines
---
 kernel/events/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/events/core.c +0 -0
index d22e4ba59dfa..a758c2311c53 100644

kernel/events/core.c static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx, · line 3507

Quoted 6 lines
kernel/events/core.c +2 -1
@@ -3503,7 +3503,8 @@ static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
 
 static bool perf_less_group_idx(const void *l, const void *r)
 {
-	const struct perf_event *le = l, *re = r;
+	const struct perf_event *le = *(const struct perf_event **)l;
+	const struct perf_event *re = *(const struct perf_event **)r;

How did this not insta explode?

author reviewer
#2 lore raw
Quoted 11 lines · Peter Zijlstra
Quoted 5 lines · Ian Rogers

The void* in perf_less_group_idx is to a cell in the array which points at a perf_event*, as such it is a perf_event**.

Fixes 6eef8a7116de ("perf/core: Use min_heap in visit_groups_merge()")

Author: John Sperbeck <[email protected]>

That doesn't make sense, did he write the patch? Then there needs to be a From: him and a SoB: him, If he reported the issue, it should be
Reported-by: him.

Done.
https://lkml.org/lkml/2020/3/21/295

Quoted 11 lines
Quoted 11 lines
---
 kernel/events/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/events/core.c +0 -0
index d22e4ba59dfa..a758c2311c53 100644
@@ -3503,7 +3503,8 @@ static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
 
Quoted 7 lines

kernel/events/core.c static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx, · line 3507

Quoted 5 lines
kernel/events/core.c +2 -1
 static bool perf_less_group_idx(const void *l, const void *r)
 {
-     const struct perf_event *le = l, *re = r;
+     const struct perf_event *le = *(const struct perf_event **)l;
+     const struct perf_event *re = *(const struct perf_event **)r;

How did this not insta explode?

Agreed, a cgroup depth of at least 3 is needed for a heap allocation and we saw this with kasan. CONFIG_KASAN_STACK should have been able to catch this in the normal case.

Thanks,
Ian