Skip to contentSkip to conversation

perf/probe: Fix to clear tev->nargs in clear_probe_trace_event()

PATCH Applied Masami Hiramatsu 3 participants 3 messages Sep 15, 2019 – Sep 22, 2019 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/probe: Fix to clear tev->nargs in clear_probe_trace_event()

Since add_probe_trace_event() can reuse tf->tevs[i] after calling clear_probe_trace_event(), this can make perf-probe crash if the 1st attempt of probe event finding fails to find an event argument, and the 2nd attempt fails to find probe point.

E.g.

  $ perf probe -D "task_pid_nr tsk"
  Failed to find 'tsk' in this function.
  Failed to get entry address of warn_bad_vsyscall
  Segmentation fault (core dumped)
Fixes 092b1f0b5f9f ("perf probe: Clear probe_trace_event when add_probe_trace_event() fails")
Cc Wang Nan <[email protected]>
---
 tools/perf/util/probe-event.c |    1 +
 1 file changed, 1 insertion(+)
tools/perf/util/probe-event.c +1 -0
index b8e0967c5c21..91cab5f669d2 100644
@@ -2331,6 +2331,7 @@ void clear_probe_trace_event(struct probe_trace_event *tev)
 		}
 	}
 	zfree(&tev->args);
+	tev->nargs = 0;
 }
 
 struct kprobe_blacklist_node {
#1 lore raw

Em Mon, Sep 16, 2019 at 01:44:40AM +0900, Masami Hiramatsu escreveu:

Quoted 10 lines

Since add_probe_trace_event() can reuse tf->tevs[i] after calling clear_probe_trace_event(), this can make perf-probe crash if the 1st attempt of probe event finding fails to find an event argument, and the 2nd attempt fails to find probe point.

E.g.

  $ perf probe -D "task_pid_nr tsk"
  Failed to find 'tsk' in this function.
  Failed to get entry address of warn_bad_vsyscall
  Segmentation fault (core dumped)

Thanks, tested and applied!

- Arnaldo

Quoted 20 lines
Fixes 092b1f0b5f9f ("perf probe: Clear probe_trace_event when add_probe_trace_event() fails")
Cc Wang Nan <[email protected]>
---
 tools/perf/util/probe-event.c |    1 +
 1 file changed, 1 insertion(+)
tools/perf/util/probe-event.c +1 -0
index b8e0967c5c21..91cab5f669d2 100644
@@ -2331,6 +2331,7 @@ void clear_probe_trace_event(struct probe_trace_event *tev)
 		}
 	}
 	zfree(&tev->args);
+	tev->nargs = 0;
 }
 
 struct kprobe_blacklist_node {
Signature · 1 line
- Arnaldo
#2 lore raw

[tip: perf/urgent] perf probe: Fix to clear tev->nargs in clear_probe_trace_event()

In reply to Masami Hiramatsu
The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     9e6124d9d635957b56717f85219a88701617253f
Gitweb:        https://git.kernel.org/tip/9e6124d9d635957b56717f85219a88701617253f
Author:        Masami Hiramatsu <[email protected]>
AuthorDate:    Mon, 16 Sep 2019 01:44:40 +09:00
Committer:     Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Fri, 20 Sep 2019 15:30:09 -03:00

perf probe: Fix to clear tev->nargs in clear_probe_trace_event()

Since add_probe_trace_event() can reuse tf->tevs[i] after calling clear_probe_trace_event(), this can make perf-probe crash if the 1st attempt of probe event finding fails to find an event argument, and the 2nd attempt fails to find probe point.

E.g.

  $ perf probe -D "task_pid_nr tsk"
  Failed to find 'tsk' in this function.
  Failed to get entry address of warn_bad_vsyscall
  Segmentation fault (core dumped)

Committer testing:

After the patch:

  $ perf probe -D "task_pid_nr tsk"
  Failed to find 'tsk' in this function.
  Failed to get entry address of warn_bad_vsyscall
  Failed to get entry address of signal_fault
  Failed to get entry address of show_signal
  Failed to get entry address of umip_printk
  Failed to get entry address of __bad_area_nosemaphore
  <SNIP>
  Failed to get entry address of sock_set_timeout
  Failed to get entry address of tcp_recvmsg
  Probe point 'task_pid_nr' not found.
    Error: Failed to add events.
  $
Fixes 092b1f0b5f9f ("perf probe: Clear probe_trace_event when add_probe_trace_event() fails")
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/perf/util/probe-event.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/probe-event.c +1 -0
index b8e0967..91cab5f 100644
@@ -2331,6 +2331,7 @@ void clear_probe_trace_event(struct probe_trace_event *tev)
 		}
 	}
 	zfree(&tev->args);
+	tev->nargs = 0;
 }
 
 struct kprobe_blacklist_node {