ftrace: Handle commands when closing set_ftrace_filter file
authorSteven Rostedt (VMware) <rostedt@goodmis.org>
Wed, 5 May 2021 14:38:24 +0000 (10:38 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 May 2021 08:40:19 +0000 (10:40 +0200)
commite9cb474de7ff7a970c2a3951c12ec7e3113c0c35
tree586ebf88b4c2afcddfbe5e8efcab454c47e7dea0
parenta1eb878265b8ad200037fabe467d12d712445e1d
ftrace: Handle commands when closing set_ftrace_filter file

commit 8c9af478c06bb1ab1422f90d8ecbc53defd44bc3 upstream.

 # echo switch_mm:traceoff > /sys/kernel/tracing/set_ftrace_filter

will cause switch_mm to stop tracing by the traceoff command.

 # echo -n switch_mm:traceoff > /sys/kernel/tracing/set_ftrace_filter

does nothing.

The reason is that the parsing in the write function only processes
commands if it finished parsing (there is white space written after the
command). That's to handle:

 write(fd, "switch_mm:", 10);
 write(fd, "traceoff", 8);

cases, where the command is broken over multiple writes.

The problem is if the file descriptor is closed, then the write call is
not processed, and the command needs to be processed in the release code.
The release code can handle matching of functions, but does not handle
commands.

Cc: stable@vger.kernel.org
Fixes: eda1e32855656 ("tracing: handle broken names in ftrace filter")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/trace/ftrace.c