]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - pending-5.1/tracing-prevent-hist_field_var_ref-from-accessing-nu.patch
move existing queues out of the way for the moment...
[thirdparty/kernel/stable-queue.git] / pending-5.1 / tracing-prevent-hist_field_var_ref-from-accessing-nu.patch
CommitLineData
fb43722c
SL
1From 2c12c95ac8d163b2f5d8e74a65a7b29f3ed81bd5 Mon Sep 17 00:00:00 2001
2From: Tom Zanussi <tom.zanussi@linux.intel.com>
3Date: Thu, 18 Apr 2019 10:18:50 -0500
4Subject: tracing: Prevent hist_field_var_ref() from accessing NULL
5 tracing_map_elts
6
7[ Upstream commit 55267c88c003a3648567beae7c90512d3e2ab15e ]
8
9hist_field_var_ref() is an implementation of hist_field_fn_t(), which
10can be called with a null tracing_map_elt elt param when assembling a
11key in event_hist_trigger().
12
13In the case of hist_field_var_ref() this doesn't make sense, because a
14variable can only be resolved by looking it up using an already
15assembled key i.e. a variable can't be used to assemble a key since
16the key is required in order to access the variable.
17
18Upper layers should prevent the user from constructing a key using a
19variable in the first place, but in case one slips through, it
20shouldn't cause a NULL pointer dereference. Also if one does slip
21through, we want to know about it, so emit a one-time warning in that
22case.
23
24Link: http://lkml.kernel.org/r/64ec8dc15c14d305295b64cdfcc6b2b9dd14753f.1555597045.git.tom.zanussi@linux.intel.com
25
26Reported-by: Vincent Bernat <vincent@bernat.ch>
27Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
28Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
29Signed-off-by: Sasha Levin <sashal@kernel.org>
30---
31 kernel/trace/trace_events_hist.c | 3 +++
32 1 file changed, 3 insertions(+)
33
34diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
35index 0a200d42fa96..f50d57eac875 100644
36--- a/kernel/trace/trace_events_hist.c
37+++ b/kernel/trace/trace_events_hist.c
38@@ -1815,6 +1815,9 @@ static u64 hist_field_var_ref(struct hist_field *hist_field,
39 struct hist_elt_data *elt_data;
40 u64 var_val = 0;
41
42+ if (WARN_ON_ONCE(!elt))
43+ return var_val;
44+
45 elt_data = elt->private_data;
46 var_val = elt_data->var_ref_vals[hist_field->var_ref_idx];
47
48--
492.20.1
50