Commit 421fd084 authored by Wang Nan's avatar Wang Nan Committed by Arnaldo Carvalho de Melo

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.orgSigned-off-by: default avatarWang Nan <wangnan0@huawei.com>
Acked-by: default avatarMasami 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent e87b4911
...@@ -138,6 +138,9 @@ struct strlist *probe_file__get_rawlist(int fd) ...@@ -138,6 +138,9 @@ struct strlist *probe_file__get_rawlist(int fd)
char *p; char *p;
struct strlist *sl; struct strlist *sl;
if (fd < 0)
return NULL;
sl = strlist__new(NULL, NULL); sl = strlist__new(NULL, NULL);
fp = fdopen(dup(fd), "r"); fp = fdopen(dup(fd), "r");
...@@ -271,6 +274,9 @@ int probe_file__get_events(int fd, struct strfilter *filter, ...@@ -271,6 +274,9 @@ int probe_file__get_events(int fd, struct strfilter *filter,
const char *p; const char *p;
int ret = -ENOENT; int ret = -ENOENT;
if (!plist)
return -EINVAL;
namelist = __probe_file__get_namelist(fd, true); namelist = __probe_file__get_namelist(fd, true);
if (!namelist) if (!namelist)
return -ENOENT; return -ENOENT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment