• Dario Petrillo's avatar
    perf annotate: Avoid TUI crash when navigating in the annotation of recursive functions · d5962fb7
    Dario Petrillo authored
    In 'perf report', entering a recursive function from inside of itself
    (either directly of indirectly through some other function) results in
    calling symbol__annotate2 multiple() times, and freeing the whole
    disassembly when exiting from the innermost instance.
    
    The first issue causes the function's disassembly to be duplicated, and
    the latter a heap use-after-free (and crash) when trying to access the
    disassembly again.
    
    I reproduced the bug on perf 5.11.22 (Ubuntu 20.04.3 LTS) and 5.16.rc8
    with the following testcase (compile with gcc recursive.c -o recursive).
    To reproduce:
    
    - perf record ./recursive
    - perf report
    - enter fibonacci and annotate it
    - move the cursor on one of the "callq fibonacci" instructions and press enter
      - at this point there will be two copies of the function in the disassembly
    - go back by pressing q, and perf will crash
    
      #include <stdio.h>
    
      int fibonacci(int n)
      {
          if(n <= 2) retur...
    d5962fb7
annotate.c 27 KB