Commit 625db36e authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf srcline: Change free_srcline to zfree_srcline

Make use after free more unlikely.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ali Saidi <alisaidi@amazon.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Brian Robbins <brianrob@linux.microsoft.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
Cc: Fangrui Song <maskray@google.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ivan Babrou <ivan@cloudflare.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Wenyu Liu <liuwenyu7@huawei.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Ye Xingchen <ye.xingchen@zte.com.cn>
Cc: Yuan Can <yuancan@huawei.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230608232823.4027869-26-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 8ab12a20
...@@ -1387,8 +1387,8 @@ static int cycles_printf(struct hist_entry *he, struct hist_entry *pair, ...@@ -1387,8 +1387,8 @@ static int cycles_printf(struct hist_entry *he, struct hist_entry *pair,
bi->start, bi->end, block_he->diff.cycles); bi->start, bi->end, block_he->diff.cycles);
} }
free_srcline(start_line); zfree_srcline(&start_line);
free_srcline(end_line); zfree_srcline(&end_line);
return scnprintf(hpp->buf, hpp->size, "%*s", width, buf); return scnprintf(hpp->buf, hpp->size, "%*s", width, buf);
} }
......
...@@ -1218,7 +1218,7 @@ static void annotation_line__init(struct annotation_line *al, ...@@ -1218,7 +1218,7 @@ static void annotation_line__init(struct annotation_line *al,
static void annotation_line__exit(struct annotation_line *al) static void annotation_line__exit(struct annotation_line *al)
{ {
free_srcline(al->path); zfree_srcline(&al->path);
zfree(&al->line); zfree(&al->line);
} }
......
...@@ -305,8 +305,8 @@ static int block_range_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp, ...@@ -305,8 +305,8 @@ static int block_range_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
bi->start, bi->end); bi->start, bi->end);
} }
free_srcline(start_line); zfree_srcline(&start_line);
free_srcline(end_line); zfree_srcline(&end_line);
return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width, buf); return scnprintf(hpp->buf, hpp->size, "%*s", block_fmt->width, buf);
} }
......
...@@ -1323,8 +1323,8 @@ void hist_entry__delete(struct hist_entry *he) ...@@ -1323,8 +1323,8 @@ void hist_entry__delete(struct hist_entry *he)
if (he->branch_info) { if (he->branch_info) {
map__zput(he->branch_info->from.ms.map); map__zput(he->branch_info->from.ms.map);
map__zput(he->branch_info->to.ms.map); map__zput(he->branch_info->to.ms.map);
free_srcline(he->branch_info->srcline_from); zfree_srcline(&he->branch_info->srcline_from);
free_srcline(he->branch_info->srcline_to); zfree_srcline(&he->branch_info->srcline_to);
zfree(&he->branch_info); zfree(&he->branch_info);
} }
...@@ -1342,7 +1342,7 @@ void hist_entry__delete(struct hist_entry *he) ...@@ -1342,7 +1342,7 @@ void hist_entry__delete(struct hist_entry *he)
zfree(&he->res_samples); zfree(&he->res_samples);
zfree(&he->stat_acc); zfree(&he->stat_acc);
free_srcline(he->srcline); zfree_srcline(&he->srcline);
if (he->srcfile && he->srcfile[0]) if (he->srcfile && he->srcfile[0])
zfree(&he->srcfile); zfree(&he->srcfile);
free_callchain(he->callchain); free_callchain(he->callchain);
......
...@@ -498,7 +498,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, ...@@ -498,7 +498,7 @@ int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
char *srcline = map__srcline(map, addr, NULL); char *srcline = map__srcline(map, addr, NULL);
if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0) if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)
ret = fprintf(fp, "%s%s", prefix, srcline); ret = fprintf(fp, "%s%s", prefix, srcline);
free_srcline(srcline); zfree_srcline(&srcline);
} }
return ret; return ret;
} }
......
...@@ -804,10 +804,15 @@ char *get_srcline_split(struct dso *dso, u64 addr, unsigned *line) ...@@ -804,10 +804,15 @@ char *get_srcline_split(struct dso *dso, u64 addr, unsigned *line)
return NULL; return NULL;
} }
void free_srcline(char *srcline) void zfree_srcline(char **srcline)
{ {
if (srcline && strcmp(srcline, SRCLINE_UNKNOWN) != 0) if (*srcline == NULL)
free(srcline); return;
if (strcmp(*srcline, SRCLINE_UNKNOWN))
free(*srcline);
*srcline = NULL;
} }
char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym, char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
...@@ -880,7 +885,7 @@ void srcline__tree_delete(struct rb_root_cached *tree) ...@@ -880,7 +885,7 @@ void srcline__tree_delete(struct rb_root_cached *tree)
pos = rb_entry(next, struct srcline_node, rb_node); pos = rb_entry(next, struct srcline_node, rb_node);
next = rb_next(&pos->rb_node); next = rb_next(&pos->rb_node);
rb_erase_cached(&pos->rb_node, tree); rb_erase_cached(&pos->rb_node, tree);
free_srcline(pos->srcline); zfree_srcline(&pos->srcline);
zfree(&pos); zfree(&pos);
} }
} }
...@@ -903,7 +908,7 @@ void inline_node__delete(struct inline_node *node) ...@@ -903,7 +908,7 @@ void inline_node__delete(struct inline_node *node)
list_for_each_entry_safe(ilist, tmp, &node->val, list) { list_for_each_entry_safe(ilist, tmp, &node->val, list) {
list_del_init(&ilist->list); list_del_init(&ilist->list);
free_srcline(ilist->srcline); zfree_srcline(&ilist->srcline);
/* only the inlined symbols are owned by the list */ /* only the inlined symbols are owned by the list */
if (ilist->symbol && ilist->symbol->inlined) if (ilist->symbol && ilist->symbol->inlined)
symbol__delete(ilist->symbol); symbol__delete(ilist->symbol);
......
...@@ -15,7 +15,7 @@ char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym, ...@@ -15,7 +15,7 @@ char *get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym, char *__get_srcline(struct dso *dso, u64 addr, struct symbol *sym,
bool show_sym, bool show_addr, bool unwind_inlines, bool show_sym, bool show_addr, bool unwind_inlines,
u64 ip); u64 ip);
void free_srcline(char *srcline); void zfree_srcline(char **srcline);
char *get_srcline_split(struct dso *dso, u64 addr, unsigned *line); char *get_srcline_split(struct dso *dso, u64 addr, unsigned *line);
/* insert the srcline into the DSO, which will take ownership */ /* insert the srcline into the DSO, which will take ownership */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment