stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] tracing/filter: Do not WARN on operand count going below zero
       [not found] <20150626150024.270253464@goodmis.org>
@ 2015-06-26 15:00 ` Steven Rostedt
  2015-06-26 15:00 ` [PATCH 2/3] tracing/filter: Do not allow infix to exceed end of string Steven Rostedt
  2015-06-26 15:00 ` [PATCH 3/3] tracing: Fix typo from "static inlin" to "static inline" Steven Rostedt
  2 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2015-06-26 15:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: Linus Torvalds, Ingo Molnar, Andrew Morton, Vince Weaver,
	Sasha Levin, stable

[-- Attachment #1: 0001-tracing-filter-Do-not-WARN-on-operand-count-going-be.patch --]
[-- Type: text/plain, Size: 1542 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

When testing the fix for the trace filter, I could not come up with
a scenario where the operand count goes below zero, so I added a
WARN_ON_ONCE(cnt < 0) to the logic. But there is legitimate case
that it can happen (although the filter would be wrong).

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

That is, a single operation without any operands will hit the path
where the WARN_ON_ONCE() can trigger. Although this is harmless,
and the filter is reported as a error. But instead of spitting out
a warning to the kernel dmesg, just fail nicely and report it via
the proper channels.

Link: http://lkml.kernel.org/r/558C6082.90608@oracle.com

Reported-by: Vince Weaver <vincent.weaver@maine.edu>
Reported-by: Sasha Levin <sasha.levin@oracle.com>
Cc: stable@vger.kernel.org # 2.6.33+
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace_events_filter.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 7f2e97ce71a7..2900d7723d97 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1385,7 +1385,9 @@ static int check_preds(struct filter_parse_state *ps)
 		if (elt->op != OP_NOT)
 			cnt--;
 		n_normal_preds++;
-		WARN_ON_ONCE(cnt < 0);
+		/* all ops should have operands */
+		if (cnt < 0)
+			break;
 	}
 
 	if (cnt != 1 || !n_normal_preds || n_logical_preds >= n_normal_preds) {
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/3] tracing/filter: Do not allow infix to exceed end of string
       [not found] <20150626150024.270253464@goodmis.org>
  2015-06-26 15:00 ` [PATCH 1/3] tracing/filter: Do not WARN on operand count going below zero Steven Rostedt
@ 2015-06-26 15:00 ` Steven Rostedt
  2015-06-26 15:00 ` [PATCH 3/3] tracing: Fix typo from "static inlin" to "static inline" Steven Rostedt
  2 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2015-06-26 15:00 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Ingo Molnar, Andrew Morton, stable

[-- Attachment #1: 0002-tracing-filter-Do-not-allow-infix-to-exceed-end-of-s.patch --]
[-- Type: text/plain, Size: 1880 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

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.

Cc: stable@vger.kernel.org # 2.6.33+
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace_events_filter.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 2900d7723d97..52adf02d7619 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1056,6 +1056,9 @@ static void parse_init(struct filter_parse_state *ps,
 
 static char infix_next(struct filter_parse_state *ps)
 {
+	if (!ps->infix.cnt)
+		return 0;
+
 	ps->infix.cnt--;
 
 	return ps->infix.string[ps->infix.tail++];
@@ -1071,6 +1074,9 @@ static char infix_peek(struct filter_parse_state *ps)
 
 static void infix_advance(struct filter_parse_state *ps)
 {
+	if (!ps->infix.cnt)
+		return;
+
 	ps->infix.cnt--;
 	ps->infix.tail++;
 }
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 3/3] tracing: Fix typo from "static inlin" to "static inline"
       [not found] <20150626150024.270253464@goodmis.org>
  2015-06-26 15:00 ` [PATCH 1/3] tracing/filter: Do not WARN on operand count going below zero Steven Rostedt
  2015-06-26 15:00 ` [PATCH 2/3] tracing/filter: Do not allow infix to exceed end of string Steven Rostedt
@ 2015-06-26 15:00 ` Steven Rostedt
  2 siblings, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2015-06-26 15:00 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Ingo Molnar, Andrew Morton, stable

[-- Attachment #1: 0003-tracing-Fix-typo-from-static-inlin-to-static-inline.patch --]
[-- Type: text/plain, Size: 967 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

The trace.h header when called without CONFIG_EVENT_TRACING enabled
(seldom done), will not compile because of a typo in the protocol
of trace_event_enum_update().

Cc: stable@vger.kernel.org # 4.1+
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index d2612016de94..3d2ad5f83e94 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1312,7 +1312,7 @@ void trace_event_init(void);
 void trace_event_enum_update(struct trace_enum_map **map, int len);
 #else
 static inline void __init trace_event_init(void) { }
-static inlin void trace_event_enum_update(struct trace_enum_map **map, int len) { }
+static inline void trace_event_enum_update(struct trace_enum_map **map, int len) { }
 #endif
 
 extern struct trace_iterator *tracepoint_print_iter;
-- 
2.1.4



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-26 15:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20150626150024.270253464@goodmis.org>
2015-06-26 15:00 ` [PATCH 1/3] tracing/filter: Do not WARN on operand count going below zero Steven Rostedt
2015-06-26 15:00 ` [PATCH 2/3] tracing/filter: Do not allow infix to exceed end of string Steven Rostedt
2015-06-26 15:00 ` [PATCH 3/3] tracing: Fix typo from "static inlin" to "static inline" Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).