Skip to content
  • Yonghong Song's avatar
    bpf: one perf event close won't free bpf program attached by another perf event · 1a4f1ecd
    Yonghong Song authored
    
    [ Upstream commit ec9dd352
    
     ]
    
    This patch fixes a bug exhibited by the following scenario:
      1. fd1 = perf_event_open with attr.config = ID1
      2. attach bpf program prog1 to fd1
      3. fd2 = perf_event_open with attr.config = ID1
         <this will be successful>
      4. user program closes fd2 and prog1 is detached from the tracepoint.
      5. user program with fd1 does not work properly as tracepoint
         no output any more.
    
    The issue happens at step 4. Multiple perf_event_open can be called
    successfully, but only one bpf prog pointer in the tp_event. In the
    current logic, any fd release for the same tp_event will free
    the tp_event->prog.
    
    The fix is to free tp_event->prog only when the closing fd
    corresponds to the one which registered the program.
    
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    1a4f1ecd