Commit 813ccd15452ed34e97aa526ffc70d6d8e6c466c5

Authored by Namhyung Kim
Committed by Arnaldo Carvalho de Melo
1 parent b93b096782

perf tools: Fix segfault for symbol annotation on TUI

Currently the symbol structure is allocated with symbol_conf.priv_size
to carry sideband information like annotation, map browser on TUI and
sort-by-name tree node.  So retrieving these information from symbol
needs to care about the details of such placement.

However the annotation code just assumes that the symbol is placed after
the struct annotation.  But actually there's other info between them.
So accessing those struct will lead to an undefined behavior (usually a
crash) after they write their info to the same location.

To reproduce the problem, please follow the steps below:

  1. run perf report (TUI of course) with -v option
  2. open map browser (by pressing right arrow key for any entry)
  3. search any function (by pressing '/' key and input whatever..)
  4. return to the hist browser (by pressing 'q' or left arrow key)
  5. open annotation window for the same entry (by pressing 'a' key)

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1421234288-22758-1-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

Showing 1 changed file with 1 additions and 7 deletions Side-by-side Diff

tools/perf/util/annotate.h
... ... @@ -116,11 +116,6 @@
116 116 struct annotated_source *src;
117 117 };
118 118  
119   -struct sannotation {
120   - struct annotation annotation;
121   - struct symbol symbol;
122   -};
123   -
124 119 static inline struct sym_hist *annotation__histogram(struct annotation *notes, int idx)
125 120 {
126 121 return (((void *)&notes->src->histograms) +
... ... @@ -129,8 +124,7 @@
129 124  
130 125 static inline struct annotation *symbol__annotation(struct symbol *sym)
131 126 {
132   - struct sannotation *a = container_of(sym, struct sannotation, symbol);
133   - return &a->annotation;
  127 + return (void *)sym - symbol_conf.priv_size;
134 128 }
135 129  
136 130 int addr_map_symbol__inc_samples(struct addr_map_symbol *ams, int evidx);