Skip to content

Commit

Permalink
tracing: Fix kernel crash while using empty filter with perf
Browse files Browse the repository at this point in the history
Kernel is crashing when user tries to record 'ftrace:function' event
with empty filter:

  # perf record -e ftrace:function --filter="" ls

  # dmesg
  BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
  Oops: 0000 [#1] SMP PTI
  ...
  RIP: 0010:ftrace_profile_set_filter+0x14b/0x2d0
  RSP: 0018:ffffa4a7c0da7d20 EFLAGS: 00010246
  RAX: ffffa4a7c0da7d64 RBX: 0000000000000000 RCX: 0000000000000006
  RDX: 0000000000000000 RSI: 0000000000000092 RDI: ffff8c48ffc968f0
  ...
  Call Trace:
   _perf_ioctl+0x54a/0x6b0
   ? rcu_all_qs+0x5/0x30
  ...

After patch:
  # perf record -e ftrace:function --filter="" ls
  failed to set filter "" on event ftrace:function with 22 (Invalid argument)

Also, if user tries to echo "" > filter, it used to throw an error.
This behavior got changed by commit 8076559 ("tracing: Rewrite
filter logic to be simpler and faster"). This patch restores the
behavior as a side effect:

Before patch:
  # echo "" > filter
  #

After patch:
  # echo "" > filter
  bash: echo: write error: Invalid argument
  #

Link: http://lkml.kernel.org/r/[email protected]

Fixes: 8076559 ("tracing: Rewrite filter logic to be simpler and faster")
Signed-off-by: Ravi Bangoria <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
  • Loading branch information
Ravi Bangoria authored and rostedt committed Apr 25, 2018
1 parent 1c758a2 commit ba16293
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions kernel/trace/trace_events_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1499,14 +1499,14 @@ static int process_preds(struct trace_event_call *call,
return ret;
}

if (!nr_preds) {
prog = NULL;
} else {
prog = predicate_parse(filter_string, nr_parens, nr_preds,
if (!nr_preds)
return -EINVAL;

prog = predicate_parse(filter_string, nr_parens, nr_preds,
parse_pred, call, pe);
if (IS_ERR(prog))
return PTR_ERR(prog);
}
if (IS_ERR(prog))
return PTR_ERR(prog);

rcu_assign_pointer(filter->prog, prog);
return 0;
}
Expand Down

0 comments on commit ba16293

Please sign in to comment.