Skip to content

Commit e30fbc6

Browse files
committed
tracing/histograms: Allow variables to have some modifiers
Modifiers are used to change the behavior of keys. For instance, they can grouped into buckets, converted to syscall names (from the syscall identifier), show task->comm of the current pid, be an array of longs that represent a stacktrace, and more. It was found that nothing stopped a value from taking a modifier. As values are simple counters. If this happened, it would call code that was not expecting a modifier and crash the kernel. This was fixed by having the ___create_val_field() function test if a modifier was present and fail if one was. This fixed the crash. Now there's a problem with variables. Variables are used to pass fields from one event to another. Variables are allowed to have some modifiers, as the processing may need to happen at the time of the event (like stacktraces and comm names of the current pid). The issue is that it too uses __create_val_field(). Now that fails on modifiers, variables can no longer use them (this is a regression). As not all modifiers are for variables, have them use a separate check. Link: https://lore.kernel.org/linux-trace-kernel/20230523221108.064a5d82@rorschach.local.home Cc: stable@vger.kernel.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Tom Zanussi <zanussi@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Fixes: e021343 ("tracing: Do not let histogram values have some modifiers") Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent ff9e163 commit e30fbc6

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

kernel/trace/trace_events_hist.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,13 +4238,19 @@ static int __create_val_field(struct hist_trigger_data *hist_data,
42384238
goto out;
42394239
}
42404240

4241-
/* Some types cannot be a value */
4242-
if (hist_field->flags & (HIST_FIELD_FL_GRAPH | HIST_FIELD_FL_PERCENT |
4243-
HIST_FIELD_FL_BUCKET | HIST_FIELD_FL_LOG2 |
4244-
HIST_FIELD_FL_SYM | HIST_FIELD_FL_SYM_OFFSET |
4245-
HIST_FIELD_FL_SYSCALL | HIST_FIELD_FL_STACKTRACE)) {
4246-
hist_err(file->tr, HIST_ERR_BAD_FIELD_MODIFIER, errpos(field_str));
4247-
ret = -EINVAL;
4241+
/* values and variables should not have some modifiers */
4242+
if (hist_field->flags & HIST_FIELD_FL_VAR) {
4243+
/* Variable */
4244+
if (hist_field->flags & (HIST_FIELD_FL_GRAPH | HIST_FIELD_FL_PERCENT |
4245+
HIST_FIELD_FL_BUCKET | HIST_FIELD_FL_LOG2))
4246+
goto err;
4247+
} else {
4248+
/* Value */
4249+
if (hist_field->flags & (HIST_FIELD_FL_GRAPH | HIST_FIELD_FL_PERCENT |
4250+
HIST_FIELD_FL_BUCKET | HIST_FIELD_FL_LOG2 |
4251+
HIST_FIELD_FL_SYM | HIST_FIELD_FL_SYM_OFFSET |
4252+
HIST_FIELD_FL_SYSCALL | HIST_FIELD_FL_STACKTRACE))
4253+
goto err;
42484254
}
42494255

42504256
hist_data->fields[val_idx] = hist_field;
@@ -4256,6 +4262,9 @@ static int __create_val_field(struct hist_trigger_data *hist_data,
42564262
ret = -EINVAL;
42574263
out:
42584264
return ret;
4265+
err:
4266+
hist_err(file->tr, HIST_ERR_BAD_FIELD_MODIFIER, errpos(field_str));
4267+
return -EINVAL;
42594268
}
42604269

42614270
static int create_val_field(struct hist_trigger_data *hist_data,

0 commit comments

Comments
 (0)