Skip to contentSkip to conversation

ftrace: Reject "!!" in front of a set_ftrace_filter command

PATCH In review Yifan Feng 2 participants 2 messages Nov 19 – Nov 20

Subsystems (2)
lore
Share & tools
lore

Yifan Feng

author
#0 lore raw

PATCH v3 1/1 ftrace: Reject "!!" in front of a set_ftrace_filter command

A command written to set_ftrace_filter with two '!' in front of the function glob triggers the WARN_ON() in unregister_ftrace_function_probe_func():

  # echo '!!vfs_read:traceoff' >> set_ftrace_filter
  WARNING: kernel/trace/ftrace.c:5675 at unregister_ftrace_function_probe_func+0x662/0x870

The command callbacks strip the first '!' and pass the rest as the glob of the probe to remove. filter_parse_regex() then reports the second '!' as a negated glob, which function probes do not support.

Return -EINVAL for such input in ftrace_process_regex(), before a command callback is called.

Fixes 23b4ff3aa479 ("ftrace: add traceon traceoff commands to enable/disable the buffers")

---
v3: add the comment above the check that Steven Rostedt asked for. No code change.
v2: https://lore.kernel.org/linux-trace-kernel/[email protected]
QEMU with the v2 code, all 7 probe commands: one WARNING each before, none after. Found and written with the help of an AI coding assistant.

 kernel/trace/ftrace.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/trace/ftrace.c +7 -0
index c7d74b33d36d..4e4337243797 100644
@@ -5846,6 +5846,13 @@ static int ftrace_process_regex(struct ftrace_iterator *iter,
 
 	/* command found */
 
+	/*
+	 * A double "!!" confuses the parser. This isn't a boolean operation,
+	 * simply reject it.
+	 */
+	if (func[0] == '!' && func[1] == '!')
+		return -EINVAL;
+
 	command = strsep(&next, ":");
 
 	guard(mutex)(&ftrace_cmd_mutex);

base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd

Signature · 1 line
2.39.3 (Apple Git-146)
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 11 lines · Yifan Feng

A command written to set_ftrace_filter with two '!' in front of the function glob triggers the WARN_ON() in unregister_ftrace_function_probe_func():

  # echo '!!vfs_read:traceoff' >> set_ftrace_filter
  WARNING: kernel/trace/ftrace.c:5675 at unregister_ftrace_function_probe_func+0x662/0x870

The command callbacks strip the first '!' and pass the rest as the glob of the probe to remove. filter_parse_regex() then reports the second '!' as a negated glob, which function probes do not support.

Quoted 6 lines

Return -EINVAL for such input in ftrace_process_regex(), before a command callback is called.

Fixes 23b4ff3aa479 ("ftrace: add traceon traceoff commands to enable/disable the buffers")

Looks good to me.

Thanks,

Quoted 33 lines

---
v3: add the comment above the check that Steven Rostedt asked for. No code change.
v2: https://lore.kernel.org/linux-trace-kernel/[email protected]
QEMU with the v2 code, all 7 probe commands: one WARNING each before, none after. Found and written with the help of an AI coding assistant.

 kernel/trace/ftrace.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/trace/ftrace.c +7 -0
index c7d74b33d36d..4e4337243797 100644
@@ -5846,6 +5846,13 @@ static int ftrace_process_regex(struct ftrace_iterator *iter,
 
 	/* command found */
 
+	/*
+	 * A double "!!" confuses the parser. This isn't a boolean operation,
+	 * simply reject it.
+	 */
+	if (func[0] == '!' && func[1] == '!')
+		return -EINVAL;
+
 	command = strsep(&next, ":");
 
 	guard(mutex)(&ftrace_cmd_mutex);

base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd

Signature · 1 line
2.39.3 (Apple Git-146)
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>