]> Git Repo - linux.git/commitdiff
perf bpf: Remove undefined behavior from bpf_perf_object__next()
authorIan Rogers <[email protected]>
Tue, 26 Jul 2022 22:09:21 +0000 (15:09 -0700)
committerArnaldo Carvalho de Melo <[email protected]>
Wed, 27 Jul 2022 14:19:39 +0000 (11:19 -0300)
bpf_perf_object__next() folded the last element in the list test with the
empty list test. However, this meant that offsets were computed against
null and that a struct list_head was compared against a 'struct
bpf_perf_object'.

Working around this with clang's undefined behavior sanitizer required
-fno-sanitize=null and -fno-sanitize=object-size.

Remove the undefined behavior by using the regular Linux list APIs and
handling the starting case separately from the end testing case.

Looking at uses like bpf_perf_object__for_each(), as the constant NULL
or non-NULL argument can be constant propagated, the code is no less
efficient.

Signed-off-by: Ian Rogers <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andrii Nakryiko <[email protected]>
Cc: Christy Lee <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Miaoqian Lin <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Nathan Chancellor <[email protected]>
Cc: Nick Desaulniers <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Tom Rix <[email protected]>
Cc: [email protected]
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
tools/perf/util/bpf-loader.c

index f8ad581ea2479097ad0b52ca3db664ef42a8017b..cdd6463a5b684ebeba34e699c1429cb31b127ecc 100644 (file)
@@ -63,20 +63,16 @@ static struct hashmap *bpf_map_hash;
 static struct bpf_perf_object *
 bpf_perf_object__next(struct bpf_perf_object *prev)
 {
-       struct bpf_perf_object *next;
-
-       if (!prev)
-               next = list_first_entry(&bpf_objects_list,
-                                       struct bpf_perf_object,
-                                       list);
-       else
-               next = list_next_entry(prev, list);
+       if (!prev) {
+               if (list_empty(&bpf_objects_list))
+                       return NULL;
 
-       /* Empty list is noticed here so don't need checking on entry. */
-       if (&next->list == &bpf_objects_list)
+               return list_first_entry(&bpf_objects_list, struct bpf_perf_object, list);
+       }
+       if (list_is_last(&prev->list, &bpf_objects_list))
                return NULL;
 
-       return next;
+       return list_next_entry(prev, list);
 }
 
 #define bpf_perf_object__for_each(perf_obj, tmp)       \
This page took 0.06434 seconds and 4 git commands to generate.