Skip to content

Commit ee5061f

Browse files
captain5050acmel
authored andcommitted
perf symbol-elf: Ensure dso__put() in machine__process_ksymbol_register()
The dso__put() after the map creation causes a use after put in dso__set_loaded(). To ensure there is a +1 reference count on both sides of the if-else, do a dso__get() on the found map's dso. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Changbin Du <changbin.du@huawei.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Link: https://lore.kernel.org/r/20240506180104.485674-3-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7fdc33f commit ee5061f

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

tools/perf/util/machine.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ static int machine__process_ksymbol_register(struct machine *machine,
683683
struct perf_sample *sample __maybe_unused)
684684
{
685685
struct symbol *sym;
686-
struct dso *dso;
686+
struct dso *dso = NULL;
687687
struct map *map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr);
688688
int err = 0;
689689

@@ -696,7 +696,6 @@ static int machine__process_ksymbol_register(struct machine *machine,
696696
}
697697
dso__set_kernel(dso, DSO_SPACE__KERNEL);
698698
map = map__new2(0, dso);
699-
dso__put(dso);
700699
if (!map) {
701700
err = -ENOMEM;
702701
goto out;
@@ -722,7 +721,7 @@ static int machine__process_ksymbol_register(struct machine *machine,
722721
dso__set_long_name(dso, "", false);
723722
}
724723
} else {
725-
dso = map__dso(map);
724+
dso = dso__get(map__dso(map));
726725
}
727726

728727
sym = symbol__new(map__map_ip(map, map__start(map)),
@@ -735,6 +734,7 @@ static int machine__process_ksymbol_register(struct machine *machine,
735734
dso__insert_symbol(dso, sym);
736735
out:
737736
map__put(map);
737+
dso__put(dso);
738738
return err;
739739
}
740740

0 commit comments

Comments
 (0)