Skip to content

Commit

Permalink
perf probe: Verify parameters in two functions
Browse files Browse the repository at this point in the history
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/[email protected]

Signed-off-by: Wang Nan <[email protected]>
Acked-by: Masami Hiramatsu <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Zefan Li <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
WangNan0 authored and acmel committed Nov 11, 2015
1 parent e87b491 commit 421fd08
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/perf/util/probe-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ struct strlist *probe_file__get_rawlist(int fd)
char *p;
struct strlist *sl;

if (fd < 0)
return NULL;

sl = strlist__new(NULL, NULL);

fp = fdopen(dup(fd), "r");
Expand Down Expand Up @@ -271,6 +274,9 @@ int probe_file__get_events(int fd, struct strfilter *filter,
const char *p;
int ret = -ENOENT;

if (!plist)
return -EINVAL;

namelist = __probe_file__get_namelist(fd, true);
if (!namelist)
return -ENOENT;
Expand Down

0 comments on commit 421fd08

Please sign in to comment.