Skip to content

Commit

Permalink
perf symbols: Fix use-after-free in get_plt_got_name()
Browse files Browse the repository at this point in the history
[ Upstream commit c8bb2d7 ]

Fix use-after-free in get_plt_got_name().

Discovered using EXTRA_CFLAGS="-fsanitize=undefined -fsanitize=address".

Fixes: ce4c8e7 ("perf symbols: Get symbols for .plt.got for x86-64")
Reported-by: kernel test robot <yujie.liu@intel.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/oe-lkp/202303061424.6ad43294-yujie.liu@intel.com
Link: https://lore.kernel.org/r/20230316194156.8320-2-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
ahunter6 authored and gregkh committed May 17, 2023
1 parent 4d907b2 commit d744e07
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tools/perf/util/symbol-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ static bool get_plt_got_name(GElf_Shdr *shdr, size_t i,
const char *sym_name;
char *demangled;
GElf_Sym sym;
bool result;
u32 disp;

if (!di->sorted)
Expand All @@ -606,9 +607,11 @@ static bool get_plt_got_name(GElf_Shdr *shdr, size_t i,

snprintf(buf, buf_sz, "%s@plt", sym_name);

result = *sym_name;

free(demangled);

return *sym_name;
return result;
}

static int dso__synthesize_plt_got_symbols(struct dso *dso, Elf *elf,
Expand Down

0 comments on commit d744e07

Please sign in to comment.