]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commit
bpf: one perf event close won't free bpf program attached by another perf event
authorYonghong Song <yhs@fb.com>
Mon, 18 Sep 2017 23:38:36 +0000 (16:38 -0700)
committerSeth Forshee <seth.forshee@canonical.com>
Thu, 19 Oct 2017 14:48:28 +0000 (09:48 -0500)
commit7dc21ce0952ae5bcb36a1ed222c9660e9c414616
tree0405d2c48f8e822e46da6e7624adb09cf82e31ae
parent7dfb100a6a18b67108aea0d6c7c9275dcd8da133
bpf: one perf event close won't free bpf program attached by another perf event

BugLink: http://bugs.launchpad.net/bugs/1723145
[ Upstream commit ec9dd352d591f0c90402ec67a317c1ed4fb2e638 ]

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: Yonghong Song <yhs@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
include/linux/trace_events.h
kernel/events/core.c