Skip to content

Commit b2aca8d

Browse files
mhiramatgregkh
authored andcommitted
tracing: Reject string operand in the histogram expression
commit a9d10ca upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b10ccc2 commit b2aca8d

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
@@ -2140,6 +2141,13 @@ static struct hist_field *parse_unary(struct hist_trigger_data *hist_data,
21402141
ret = PTR_ERR(operand1);
21412142
goto free;
21422143
}
2144+
if (operand1->flags & HIST_FIELD_FL_STRING) {
2145+
/* String type can not be the operand of unary operator. */
2146+
hist_err(file->tr, HIST_ERR_INVALID_STR_OPERAND, errpos(str));
2147+
destroy_hist_field(operand1, 0);
2148+
ret = -EINVAL;
2149+
goto free;
2150+
}
21432151

21442152
expr->flags |= operand1->flags &
21452153
(HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS);
@@ -2241,6 +2249,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
22412249
operand1 = NULL;
22422250
goto free;
22432251
}
2252+
if (operand1->flags & HIST_FIELD_FL_STRING) {
2253+
hist_err(file->tr, HIST_ERR_INVALID_STR_OPERAND, errpos(operand1_str));
2254+
ret = -EINVAL;
2255+
goto free;
2256+
}
22442257

22452258
/* rest of string could be another expression e.g. b+c in a+b+c */
22462259
operand_flags = 0;
@@ -2250,6 +2263,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
22502263
operand2 = NULL;
22512264
goto free;
22522265
}
2266+
if (operand2->flags & HIST_FIELD_FL_STRING) {
2267+
hist_err(file->tr, HIST_ERR_INVALID_STR_OPERAND, errpos(str));
2268+
ret = -EINVAL;
2269+
goto free;
2270+
}
22532271

22542272
ret = check_expr_operands(file->tr, operand1, operand2);
22552273
if (ret)

0 commit comments

Comments
 (0)