Skip to content

Commit a9d10ca

Browse files
mhiramatrostedt
authored andcommitted
tracing: Reject string operand in the histogram expression
Since the string type can not be the target of the addition / subtraction operation, it must be rejected. Without this fix, the string type silently converted to digits. Link: https://lkml.kernel.org/r/162742654278.290973.1523000673366456634.stgit@devnote2 Cc: stable@vger.kernel.org Fixes: 100719d ("tracing: Add simple expression support to hist triggers") Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 2c05caa commit a9d10ca

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎kernel/trace/trace_events_hist.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
C(INVALID_SORT_MODIFIER,"Invalid sort modifier"), \
6666
C(EMPTY_SORT_FIELD, "Empty sort field"), \
6767
C(TOO_MANY_SORT_FIELDS, "Too many sort fields (Max = 2)"), \
68-
C(INVALID_SORT_FIELD, "Sort field must be a key or a val"),
68+
C(INVALID_SORT_FIELD, "Sort field must be a key or a val"), \
69+
C(INVALID_STR_OPERAND, "String type can not be an operand in expression"),
6970

7071
#undef C
7172
#define C(a, b) HIST_ERR_##a
@@ -2156,6 +2157,13 @@ static struct hist_field *parse_unary(struct hist_trigger_data *hist_data,
21562157
ret = PTR_ERR(operand1);
21572158
goto free;
21582159
}
2160+
if (operand1->flags & HIST_FIELD_FL_STRING) {
2161+
/* String type can not be the operand of unary operator. */
2162+
hist_err(file->tr, HIST_ERR_INVALID_STR_OPERAND, errpos(str));
2163+
destroy_hist_field(operand1, 0);
2164+
ret = -EINVAL;
2165+
goto free;
2166+
}
21592167

21602168
expr->flags |= operand1->flags &
21612169
(HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS);
@@ -2257,6 +2265,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
22572265
operand1 = NULL;
22582266
goto free;
22592267
}
2268+
if (operand1->flags & HIST_FIELD_FL_STRING) {
2269+
hist_err(file->tr, HIST_ERR_INVALID_STR_OPERAND, errpos(operand1_str));
2270+
ret = -EINVAL;
2271+
goto free;
2272+
}
22602273

22612274
/* rest of string could be another expression e.g. b+c in a+b+c */
22622275
operand_flags = 0;
@@ -2266,6 +2279,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
22662279
operand2 = NULL;
22672280
goto free;
22682281
}
2282+
if (operand2->flags & HIST_FIELD_FL_STRING) {
2283+
hist_err(file->tr, HIST_ERR_INVALID_STR_OPERAND, errpos(str));
2284+
ret = -EINVAL;
2285+
goto free;
2286+
}
22692287

22702288
ret = check_expr_operands(file->tr, operand1, operand2);
22712289
if (ret)

0 commit comments

Comments
 (0)