• Tommi Rantala's avatar
    perf tools: Fix crash with non-jited bpf progs · ab8bf5f2
    Tommi Rantala authored
    The addr in PERF_RECORD_KSYMBOL events for non-jited bpf progs points to
    the bpf interpreter, ie. within kernel text section. When processing the
    unregister event, this causes unexpected removal of vmlinux_map,
    crashing perf later in cleanup:
    
      # perf record -- timeout --signal=INT 2s /usr/share/bcc/tools/execsnoop
      PCOMM            PID    PPID   RET ARGS
      [ perf record: Woken up 1 times to write data ]
      [ perf record: Captured and wrote 0.208 MB perf.data (5155 samples) ]
      perf: tools/include/linux/refcount.h:131: refcount_sub_and_test: Assertion `!(new > val)' failed.
      Aborted (core dumped)
    
      # perf script -D|grep KSYM
      0 0xa40 [0x48]: PERF_RECORD_KSYMBOL addr ffffffffa9b6b530 len 0 type 1 flags 0x0 name bpf_prog_f958f6eb72ef5af6
      0 0xab0 [0x48]: PERF_RECORD_KSYMBOL addr ffffffffa9b6b530 len 0 type 1 flags 0x0 name bpf_prog_8c42dee26e8cd4c2
      0 0xb20 [0x48]: PERF_RECORD_KSYMBOL addr ffffffffa9b6b530 len 0 type 1 flags 0x0 name bpf_prog_f958f6eb72ef5af6
      108563691893 0x33d98 [0x58]: PERF_RECORD_KSYMBOL addr ffffffffa9b6b3b0 len 0 type 1 flags 0x0 name bpf_prog_bc5697a410556fc2_syscall__execve
      108568518458 0x34098 [0x58]: PERF_RECORD_KSYMBOL addr ffffffffa9b6b3f0 len 0 type 1 flags 0x0 name bpf_prog_45e2203c2928704d_do_ret_sys_execve
      109301967895 0x34830 [0x58]: PERF_RECORD_KSYMBOL addr ffffffffa9b6b3b0 len 0 type 1 flags 0x1 name bpf_prog_bc5697a410556fc2_syscall__execve
      109302007356 0x348b0 [0x58]: PERF_RECORD_KSYMBOL addr ffffffffa9b6b3f0 len 0 type 1 flags 0x1 name bpf_prog_45e2203c2928704d_do_ret_sys_execve
      perf: tools/include/linux/refcount.h:131: refcount_sub_and_test: Assertion `!(new > val)' failed.
    
    Here the addresses match the bpf interpreter:
    
      # grep -e ffffffffa9b6b530 -e ffffffffa9b6b3b0 -e ffffffffa9b6b3f0 /proc/kallsyms
      ffffffffa9b6b3b0 t __bpf_prog_run224
      ffffffffa9b6b3f0 t __bpf_prog_run192
      ffffffffa9b6b530 t __bpf_prog_run32
    
    Fix by not allowing vmlinux_map to be removed by PERF_RECORD_KSYMBOL
    unregister event.
    Signed-off-by: default avatarTommi Rantala <tommi.t.rantala@nokia.com>
    Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
    Tested-by: default avatarJiri Olsa <jolsa@redhat.com>
    Link: https://lore.kernel.org/r/20201016114718.54332-1-tommi.t.rantala@nokia.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    ab8bf5f2
machine.c 75.1 KB