aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang Nan <wangnan0@huawei.com>2015-11-06 04:50:15 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-11-11 16:41:32 -0500
commit421fd0845eaeecce6b3806f7f0c0d67d1f9ad108 (patch)
treeaaacfa9c48bec1daa5b0fb8c8809d0d74333a2c0
parente87b49116dedba3464fd8d0ec9393b4841167334 (diff)
perf probe: Verify parameters in two functions
On kernel with only one out of CONFIG_KPROBE_EVENTS and CONFIG_UPROBE_EVENTS enabled, 'perf probe -d' causes a segfault because perf_del_probe_events() calls probe_file__get_events() with a negative fd. This patch fixes it by adding parameter validation at the entry of probe_file__get_events() and probe_file__get_rawlist(). Since they are both non-static public functions (in .h file), parameter verifying is required. v1 -> v2: Verify fd at the head of probe_file__get_rawlist() instead of checking at call site (suggested by Masami and Arnaldo at [1,2]). [1] http://lkml.kernel.org/r/50399556C9727B4D88A595C8584AAB37526048E3@GSjpTKYDCembx32.service.hitachi.net [2] http://lkml.kernel.org/r/20151105155830.GV13236@kernel.org Signed-off-by: Wang Nan <wangnan0@huawei.com> Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1446803415-83382-1-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/probe-file.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 89dbeb92c68e..e3b3b92e4458 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -138,6 +138,9 @@ struct strlist *probe_file__get_rawlist(int fd)
138 char *p; 138 char *p;
139 struct strlist *sl; 139 struct strlist *sl;
140 140
141 if (fd < 0)
142 return NULL;
143
141 sl = strlist__new(NULL, NULL); 144 sl = strlist__new(NULL, NULL);
142 145
143 fp = fdopen(dup(fd), "r"); 146 fp = fdopen(dup(fd), "r");
@@ -271,6 +274,9 @@ int probe_file__get_events(int fd, struct strfilter *filter,
271 const char *p; 274 const char *p;
272 int ret = -ENOENT; 275 int ret = -ENOENT;
273 276
277 if (!plist)
278 return -EINVAL;
279
274 namelist = __probe_file__get_namelist(fd, true); 280 namelist = __probe_file__get_namelist(fd, true);
275 if (!namelist) 281 if (!namelist)
276 return -ENOENT; 282 return -ENOENT;