]> git.baikalelectronics.ru Git - kernel.git/commit
perf bpf: Defer freeing string after possible strlen() on it
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 16 Feb 2022 19:01:00 +0000 (16:01 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 Feb 2022 10:15:09 +0000 (07:15 -0300)
commitf605821aefee7cebea614d412679b915a63c80c6
tree034b258a1ea0713f1a173fb8310c86f10af14648
parent02bf028271532f4144c6700cc315701d8e55d1b8
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: 68eaf1530bf9810b ("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>
tools/perf/util/bpf-loader.c