reset_trigger_file() cuts a trigger line at its first '[' to discard the
histogram state suffix. A filter such as prev_comm ~ "[ab]" is truncated
inside its quoted string, producing an invalid removal command.

This also breaks the first pass that removes action histograms before
their variable providers. If an action histogram cannot be removed and
its provider is visited first in the second pass, the provider is busy
and remains installed after reset.

Remove only the trailing [active] or [paused] annotation. Quote the line
while extracting the command so that repeated spaces inside the filter
also survive, allowing the action histogram to match and be removed.

Fixes: 5675fd4ef51f ("tools/bootconfig: Add --init option for bconf2ftrace.sh")
Signed-off-by: Eduardo Mucelli Rezende Oliveira <[email protected]>
---
I tested reset_trigger_file in a temporary tracefs instance on my Ubuntu
machine, running kernel 7.0.0-38-generic, with recording disabled.
With an action histogram depending on a provider that comes first in
the event-directory order, the original helper left the provider behind.
This happened with a bracketed filter and with repeated spaces inside
a string. The spaced-string case even returned success.

With the fix, both histograms were removed. I also checked active and
paused histograms, onmax actions, and ordinary filter controls.

 tools/bootconfig/scripts/ftrace.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/bootconfig/scripts/ftrace.sh 
b/tools/bootconfig/scripts/ftrace.sh
index cc5250c64699..c2b993f8e366 100644
--- a/tools/bootconfig/scripts/ftrace.sh
+++ b/tools/bootconfig/scripts/ftrace.sh
@@ -21,13 +21,13 @@ reset_trigger_file() {
     # remove action triggers first
     grep -H ':on[^:]*(' $@ |
     while read line; do
-        cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`
+       cmd=`echo "$line" | cut -f2- -d: | sed -e 's/ \[active\]$//' -e 's/ 
\[paused\]$//'`
        file=`echo $line | cut -f1 -d:`
        echo "!$cmd" >> $file
     done
     grep -Hv ^# $@ |
     while read line; do
-        cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`
+       cmd=`echo "$line" | cut -f2- -d: | sed -e 's/ \[active\]$//' -e 's/ 
\[paused\]$//'`
        file=`echo $line | cut -f1 -d:`
        echo "!$cmd" > $file
     done
-- 
2.53.0


Reply via email to