perf tools fixes for v5.17: 2nd batch

- Fix corrupt inject files when only last branch option is enabled with ARM CoreSight ETM.

- Fix use-after-free for realloc(..., 0) in libsubcmd, found by gcc 12.

- Defer freeing string after possible strlen() on it in the BPF loader, found by gcc 12.

- Avoid early exit in 'perf trace' due SIGCHLD from non-workload processes.

- Fix arm64 perf_event_attr 'perf test's wrt --call-graph initialization.

- Fix libperf 32-bit build for 'perf test' wrt uint64_t printf.

- Fix perf_cpu_map__for_each_cpu macro in libperf, providing access to the CPU iterator.

- Sync linux/perf_event.h UAPI with the kernel sources.

- Update Jiri Olsa's email address in MAINTAINERS.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
perf bpf: Defer freeing string after possible strlen() on it

This was detected by the gcc in Fedora Rawhide's gcc:

  50    11.01 fedora:rawhide                : FAIL gcc version 12.0.1 20220205 (Red Hat 12.0.1-0) (GCC)
        inlined from 'bpf__config_obj' at util/bpf-loader.c:1242:9:
    util/bpf-loader.c:1225:34: error: pointer 'map_opt' may be used after 'free' [-Werror=use-after-free]
     1225 |                 *key_scan_pos += strlen(map_opt);
          |                                  ^~~~~~~~~~~~~~~
    util/bpf-loader.c:1223:9: note: call to 'free' here
     1223 |         free(map_name);
          |         ^~~~~~~~~~~~~~
    cc1: all warnings being treated as errors

So do the calculations on the pointer before freeing it.

Fixes: 04f9bf2bac72480c ("perf bpf-loader: Add missing '*' for key_scan_pos")
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang ShaoBo <bobo.shaobowang@huawei.com>
Link: https://lore.kernel.org/lkml/Yg1VtQxKrPpS3uNA@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 file changed