Commit 6cc99fc4 authored by Steven Rostedt (Red Hat)'s avatar Steven Rostedt (Red Hat) Committed by Luis Henriques

tracing/filter: Do not allow infix to exceed end of string

commit 6b88f44e upstream.

While debugging a WARN_ON() for filtering, I found that it is possible
for the filter string to be referenced after its end. With the filter:

 # echo '>' > /sys/kernel/debug/events/ext4/ext4_truncate_exit/filter

The filter_parse() function can call infix_get_op() which calls
infix_advance() that updates the infix filter pointers for the cnt
and tail without checking if the filter is already at the end, which
will put the cnt to zero and the tail beyond the end. The loop then calls
infix_next() that has

	ps->infix.cnt--;
	return ps->infix.string[ps->infix.tail++];

The cnt will now be below zero, and the tail that is returned is
already passed the end of the filter string. So far the allocation
of the filter string usually has some buffer that is zeroed out, but
if the filter string is of the exact size of the allocated buffer
there's no guarantee that the charater after the nul terminating
character will be zero.

Luckily, only root can write to the filter.
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 6880d046
...@@ -1086,6 +1086,9 @@ static void parse_init(struct filter_parse_state *ps, ...@@ -1086,6 +1086,9 @@ static void parse_init(struct filter_parse_state *ps,
static char infix_next(struct filter_parse_state *ps) static char infix_next(struct filter_parse_state *ps)
{ {
if (!ps->infix.cnt)
return 0;
ps->infix.cnt--; ps->infix.cnt--;
return ps->infix.string[ps->infix.tail++]; return ps->infix.string[ps->infix.tail++];
...@@ -1101,6 +1104,9 @@ static char infix_peek(struct filter_parse_state *ps) ...@@ -1101,6 +1104,9 @@ static char infix_peek(struct filter_parse_state *ps)
static void infix_advance(struct filter_parse_state *ps) static void infix_advance(struct filter_parse_state *ps)
{ {
if (!ps->infix.cnt)
return;
ps->infix.cnt--; ps->infix.cnt--;
ps->infix.tail++; ps->infix.tail++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment