Re: [PATCH v20 11/11] tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger

From
sashiko-bot@kernel.org
Date
2026-11-16 05:50:30
Also in
linux-perf-users
Reply to
Masami Hiramatsu (Google), 2026-11-16
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] tracing/wprobe: truncated command logged by
  wprobe_trigger_field_parse()
--

commit 2effd66bbdbad9649e094446a260cd6b20b2df1c
Author: Masami Hiramatsu (Google) [off-list ref]

tracing/wprobe: Support BTF struct offset resolution in set_wprobe trigger

This commit adds BTF struct offset resolution support for the target
address field in set_wprobe and clear_wprobe event triggers, along with
documentation and a selftest.

Link: https://lore.kernel.org/all/59637b96946653393a7ad3c7de094094796b39c2.1785067572.git.wangjinchao600@gmail.com/ (local)
quoted hunk ↗ jump to hunk
diff --git a/kernel/trace/trace_wprobe.c b/kernel/trace/trace_wprobe.c
index d2b41aa69cfdf..ad9ab606d3f47 100644
--- a/kernel/trace/trace_wprobe.c
+++ b/kernel/trace/trace_wprobe.c
[ ... ]
quoted hunk ↗ jump to hunk
@@ -1230,6 +1231,223 @@ static void wprobe_trigger_free(struct event_trigger_data *data)
 	}
 }
 
+#ifdef CONFIG_PROBE_EVENTS_BTF_ARGS
[ ... ]
quoted hunk ↗ jump to hunk
+/* parse typecast: (TYPE[,ASGN])EVENT_FIELD->FIELD[.SUBFIELD...][+-OFFS] and set adjust. */
+static int wprobe_trigger_typecast_parse(char *field_str,
+					 struct trace_event_file *file,
+					 struct wprobe_trigger_data *wprobe_data,
+					 const char *glob)
+{
+	struct btf *btf __free(btf_put) = NULL;
+	char *buf __free(kfree) = NULL;
+	struct ftrace_event_field *field;
+	const struct btf_type *type;
+	char *assign_field;
+	char *event_field;
+	char *type_field;
+	char *type_name;
+	char *offs;
+	long val = 0;
+	int base_offset = field_str - glob;
+	int event_field_offset;
+	int id, adjust;
+
+	buf = kstrdup(field_str, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
[ ... ]
quoted hunk ↗ jump to hunk
+static int wprobe_trigger_field_parse(char *field_str, struct trace_event_file *file,
+					struct wprobe_trigger_data *wprobe_data,
+					const char *glob)
+{
+	struct ftrace_event_field *field;
+	char *offs;
+
+	if (field_str[0] == '(')
+		return wprobe_trigger_typecast_parse(field_str, file, wprobe_data, glob);
+
+	offs = strpbrk(field_str, "+-");
+	if (offs) {
+		long val;
+
+		if (kstrtol(offs, 0, &val) < 0) {
+			wprobe_trigger_log_err(file, glob, offs - glob, BAD_DEREF_OFFS);
+			return -EINVAL;
+		}
+		wprobe_data->adjust = val;
+		*offs = '\0';
+	}
+
+	field = trace_find_event_field(file->event_call, field_str);
+	if (!field) {
+		wprobe_trigger_log_err(file, glob, field_str - glob, NO_EVENT_FIELD);
+		return -ENOENT;
+	}
+	if (field->size != sizeof(void *)) {
+		wprobe_trigger_log_err(file, glob, field_str - glob, WPROBE_BAD_FIELD);
+		return -ENOEXEC;
+	}
+	wprobe_data->offset = field->offset;
+	wprobe_data->field = kstrdup(field_str, GFP_KERNEL);
+	if (!wprobe_data->field)
+		return -ENOMEM;
+
+	return 0;
+}
[ ... ]
quoted hunk ↗ jump to hunk
@@ -1306,93 +1522,25 @@ static int wprobe_trigger_cmd_parse(struct event_command *cmd_ops,
 
 	/* clear_wprobe does not need field, but can have optional field. */
 	if (!clear) {
-		char *offs;
+		char *field_str = strsep(&param, ":");
 
-		/* Find target field, which must be equivalent to "void *" */
-		field_str = strsep(&param, ":");
 		if (!field_str) {
 			wprobe_trigger_log_err(file, glob, strlen(glob), WPROBE_NEED_FIELD);
 			ret = -EINVAL;
 			goto out_free;
 		}
-
-		offs = strpbrk(field_str, "+-");
-		if (offs) {
-			long val;
-
-			if (kstrtol(offs, 0, &val) < 0) {
-				wprobe_trigger_log_err(file, glob, offs - glob, BAD_DEREF_OFFS);
-				ret = -EINVAL;
-				goto out_free;
-			}
-			wprobe_data->adjust = val;
-			*offs = '\0';
-		}
-
-		event = file->event_call;
-		field = trace_find_event_field(event, field_str);
-		if (!field) {
-			wprobe_trigger_log_err(file, glob, field_str - glob, NO_EVENT_FIELD);
-			ret = -ENOENT;
-			goto out_free;
-		}
-
-		if (field->size != sizeof(void *)) {
-			wprobe_trigger_log_err(file, glob, field_str - glob, WPROBE_BAD_FIELD);
-			ret = -ENOEXEC;
-			goto out_free;
-		}
-		wprobe_data->offset = field->offset;
-		wprobe_data->field = kstrdup(field_str, GFP_KERNEL);
-		if (!wprobe_data->field) {
-			ret = -ENOMEM;
+		ret = wprobe_trigger_field_parse(field_str, file, wprobe_data, glob);
+		if (ret < 0)
 			goto out_free;
[Severity: Low]
Does wprobe_trigger_log_err() still print a truncated command string when
wprobe_trigger_field_parse() or wprobe_trigger_typecast_parse() fails?

wprobe_trigger_typecast_parse() duplicates field_str to avoid mutating
glob in place, but wprobe_trigger_cmd_parse() has already split event_str
and field_str out of param using strsep(&param, ":"), which overwrites the
colon after event_str inside glob with a NUL byte:

kernel/trace/trace_wprobe.c:wprobe_trigger_cmd_parse() {
    ...
	if (param_and_filter) {
		/* Recover original trigger string to show the error log correctly. */
		if (*(param_and_filter - 1) == '\0')
			*(param_and_filter - 1) = ':';
    ...
	ret = event_trigger_separate_filter(param_and_filter, &param, &filter, true);
    ...
	event_str = strsep(&param, ":");
    ...
}

Because that colon at *(field_str - 1) (and any colon after field_str when
a count follows) is never restored, tracing_log_err() stops printing glob
right after event_str, while the error caret position is still calculated
relative to field_str inside glob and lands past the end of the printed
command.  In the non-typecast path of wprobe_trigger_field_parse(),
*offs = '\0' also truncates glob before logging NO_EVENT_FIELD or
WPROBE_BAD_FIELD.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179480675130.38065.3086970856119381693.stgit@devnote2?part=11
Thread (17 messages) 17 messages, 2 authors, last reply 19h ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help