alistair23-linux/tools
Adrian Hunter 3a4acda1ec perf tools: Fix thread lifetime related segfaut in intel_pt
intel_pt_process_auxtrace_info() creates a pt->unknown_thread thread
that eventually needs to be freed by the last thread__put() on it, when
its refcount hits zero, which may happen in
intel_pt_process_auxtrace_info() error handling path and triggers the
following segfault, which would happen as well at intel_pt_free, when
tools using this intel_pt codebase frees up resources:

  # perf record -I -e intel_pt/tsc=1,noretcomp=1/u /bin/ls
  0  a  anaconda-ks.cfg  bin   perf.data	perf.data.old  perf-f23-bringup.todo
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.217 MB perf.data ]
  #
  # perf script -F event,comm,pid,tid,time,addr,ip,sym,dso,iregs
  Samples for 'instructions:u' event do not have IREGS attribute set. Cannot print 'iregs' field.
  intel_pt_synth_events: failed to synthesize 'instructions' event type
  Segmentation fault (core dumped)
  #

The problem is: there's a union in 'struct thread' combines a list_head
and a rb_node. The standard life cycle of a thread is: init rb_node in
the constructor, insert it into machine->threads rbtree using rb_node,
move it to machine->dead_threads using list_head, clean in the last
thread__put: list_del_init(&thread->node).

In the above command, it clean a thread before adding it into list,
causes the above segfault.

Since pt->unknown_thread will never live in an rbtree, initialize its
list node so that when list_del_init() is done on it we don't segfault.

After this patch:

  # perf script -F event,comm,pid,tid,time,addr,ip,sym,dso,iregs
  Samples for 'instructions:u' event do not have IREGS attribute set. Cannot print 'iregs' field.
  intel_pt_synth_events: failed to synthesize 'instructions' event type
  0x248 [0x88]: failed to process type: 70
  #

Reported-by: Tong Zhang <ztong@vt.edu>
Reported-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: http://lkml.kernel.org/r/1454296865-19749-1-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2016-02-02 12:51:11 -03:00
..
arch tools include: Add basic atomic.h implementation from the kernel sources 2015-05-08 16:11:05 -03:00
build tools build: Add BPF feature check to test-all 2016-01-11 19:22:21 -03:00
cgroup
firewire
hv tools: hv: vss: fix the write()'s argument: error -> vss_msg 2015-12-14 19:15:05 -08:00
iio iio: generic_buffer: be helpful about enabling channels 2015-08-16 10:51:26 +01:00
include tools: Make list.h self-sufficient 2016-01-12 12:42:07 -03:00
laptop/freefall Move freefall program from Documentation/ to tools/ 2015-06-08 16:42:07 -06:00
lguest tools/lguest: Clean up include dir 2015-08-26 06:12:35 +02:00
lib tools subcmd: Add missing NORETURN define for parse-options.h 2016-01-12 12:42:07 -03:00
net tools/net: Use include/uapi with __EXPORTED_HEADERS__ 2015-11-15 17:24:33 -05:00
nfsd
perf perf tools: Fix thread lifetime related segfaut in intel_pt 2016-02-02 12:51:11 -03:00
power Merge branches 'pm-sleep' and 'pm-tools' 2016-01-12 01:12:03 +01:00
scripts tools: Move Makefile.arch from perf/config to tools/scripts 2016-01-11 19:22:20 -03:00
spi spi: spidev_test: Fix typo in error message 2015-12-08 17:58:56 +00:00
testing Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2016-01-14 11:57:22 -08:00
thermal/tmon tools/thermal: tmon: use pkg-config also for CFLAGS 2015-10-10 11:32:31 +08:00
time
usb usb: patches for v4.4 merge window 2015-10-22 17:19:33 -07:00
virtio tools/virtio: fix byteswap logic 2015-12-07 17:28:10 +02:00
vm tools/vm/page-types.c: support KPF_IDLE 2015-11-20 16:17:32 -08:00
Makefile Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2016-01-14 11:39:09 -08:00