perf machine: Guard against NULL in machine__exit() [Linux 4.14.129]

perf machine: Guard against NULL in machine__exit() [Linux 4.14.129]

This Linux kernel change "perf machine: Guard against NULL in machine__exit()" is included in the Linux 4.14.129 release. This change is authored by Arnaldo Carvalho de Melo <acme [at]> on Mon Nov 13 16:06:29 2017 -0300. The commit for this change in Linux stable tree is 24f1363 (patch) which is from upstream commit 4a2233b. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 4a2233b.

perf machine: Guard against NULL in machine__exit()

commit 4a2233b194c77ae1ea8304cb7c00b551de4313f0 upstream.

A recent fix for 'perf trace' introduced a bug where
machine__exit(trace->host) could be called while trace->host was still
NULL, so make this more robust by guarding against NULL, just like
free() does.

The problem happens, for instance, when !root users try to run 'perf

  [[email protected] linux]$ trace
  Error:    No permissions to read /sys/kernel/debug/tracing/events/raw_syscalls/sys_(enter|exit)
  Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/tracing'

  perf: Segmentation fault
  Obtained 7 stack frames.
  /lib64/ [0x7f43a1dd971f]
  /lib64/ [0x7f43a1dc3509]
  Segmentation fault (core dumped)
  [[email protected] linux]$

Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Andrei Vagin <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Vasily Averin <[email protected]>
Cc: Wang Nan <[email protected]>
Fixes: 33974a414ce2 ("perf trace: Call machine__exit() at exit")
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: Tommi Rantala <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>

There are 3 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 tools/perf/util/machine.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 968fd04..d246080 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -156,6 +156,9 @@ void machine__delete_threads(struct machine *machine)

 void machine__exit(struct machine *machine)
+   if (machine == NULL)
+       return;

Leave a Reply

Your email address will not be published. Required fields are marked *