Skip to contentSkip to conversation

perf: probe: avoid segfault if passed with ''.

PATCH Applied Wang Nan 3 participants 3 messages Apr 28, 2015 – May 6, 2015 perf events

lore
Share & tools
lore

Wang Nan

author
#0 lore raw

PATCH 1/1 perf: probe: avoid segfault if passed with ''.

Since parse_perf_probe_point() deals with a user passed argument, we should not assume it to be a valid string.

Without this patch, if pass '' to perf probe, a segfault raises:

 $ perf probe -a ''
 Segmentation fault

This patch checks argument of parse_perf_probe_point() before string processing.

After this patch:

 $ perf probe -a ''
  usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
     or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
     ...
---
 tools/perf/util/probe-event.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/probe-event.c +2 -0
index d8bb616..d05b77c 100644
@@ -1084,6 +1084,8 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
 	 *
 	 * TODO:Group name support
 	 */
+	if (!arg)
+		return -EINVAL;
 
 	ptr = strpbrk(arg, ";=@+%");
 	if (ptr && *ptr == '=') {	/* Event name */
Signature · 1 line
1.8.3.4
maintainer Applied
#1 lore raw

Em Tue, Apr 28, 2015 at 08:46:09AM +0000, Wang Nan escreveu:

Quoted 11 lines

Since parse_perf_probe_point() deals with a user passed argument, we should not assume it to be a valid string.

Without this patch, if pass '' to perf probe, a segfault raises:

 $ perf probe -a ''
 Segmentation fault

This patch checks argument of parse_perf_probe_point() before string processing.

Quoted 7 lines

After this patch:

 $ perf probe -a ''
  usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
     or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
     ...

Thanks, applied to perf/urgent.

- Arnaldo

#2 lore raw

[tip:perf/urgent] perf probe: Fix segfault if passed with ''.

In reply to Wang Nan
perf probe: Fix segfault if passed with ''.
Commit-ID:  e59d29e88f7b7e3d1231202b0203d0af6f15a440
Gitweb:     http://git.kernel.org/tip/e59d29e88f7b7e3d1231202b0203d0af6f15a440
Author:     Wang Nan <[email protected]>
AuthorDate: Tue, 28 Apr 2015 08:46:09 +0000
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 5 May 2015 12:26:52 -0300

perf probe: Fix segfault if passed with ''.

Since parse_perf_probe_point() deals with a user passed argument, we should not assume it to be a valid string.

Without this patch, if pass '' to perf probe, a segfault raises:

 $ perf probe -a ''
 Segmentation fault

This patch checks argument of parse_perf_probe_point() before string processing.

After this patch:

 $ perf probe -a ''
  usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
     or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
     ...
---
 tools/perf/util/probe-event.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/probe-event.c +2 -0
index d8bb616..d05b77c 100644
@@ -1084,6 +1084,8 @@ static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
 	 *
 	 * TODO:Group name support
 	 */
+	if (!arg)
+		return -EINVAL;
 
 	ptr = strpbrk(arg, ";=@+%");
 	if (ptr && *ptr == '=') {	/* Event name */