ftrace2bconf.sh emits event filters without enclosing bootconfig quotes.
A filter such as prev_comm == "a,b" is therefore parsed as an array,
while a # truncates the value and a semicolon or closing brace can make
the exported configuration invalid.

Quote filters containing bootconfig delimiters so that the complete
expression remains one value. Choose the enclosing quote in the same
way as the bootconfig utility. Leave filters without delimiters as they
are, including expressions that contain both kinds of quote.

Fixes: 2b86062a34a8 ("tools/bootconfig: Add a script to generates bootconfig 
from ftrace")
Signed-off-by: Eduardo Mucelli Rezende Oliveira <[email protected]>
---
I tested event filters containing a comma, semicolon, # and closing
brace in a temporary tracefs instance on my Ubuntu machine, running
kernel 7.0.0-38-generic, with recording disabled.

The original export split or truncated these filters, or produced a
config that could not be parsed. With the fix, each expression remained
one value and was restored unchanged. A filter containing an ordinary
space worked in both versions.

 tools/bootconfig/scripts/ftrace2bconf.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/bootconfig/scripts/ftrace2bconf.sh 
b/tools/bootconfig/scripts/ftrace2bconf.sh
index b01297217cf3..8c5889d0420c 100755
--- a/tools/bootconfig/scripts/ftrace2bconf.sh
+++ b/tools/bootconfig/scripts/ftrace2bconf.sh
@@ -126,6 +126,14 @@ per_event_options() { # event-dir
        fi
        val=`cat $evdir/filter`
        if [ "$val" != "none" ]; then
+               case "$val" in
+               *[',;#}']*)
+                       case "$val" in
+                       *\"*) val="'$val'";;
+                       *) val="\"$val\"";;
+                       esac
+                       ;;
+               esac
                emit_kv $PREFIX.event.$group.$event.filter = "$val"
        fi
 }
-- 
2.53.0


Reply via email to