]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - pending-4.19/tracing-prevent-hist_field_var_ref-from-accessing-nu.patch
Fix up backported ptrace patch
[thirdparty/kernel/stable-queue.git] / pending-4.19 / tracing-prevent-hist_field_var_ref-from-accessing-nu.patch
1 From 9d5ad9072bd55982fef63a2e02fcbdd0399600b0 Mon Sep 17 00:00:00 2001
2 From: Tom Zanussi <tom.zanussi@linux.intel.com>
3 Date: Thu, 18 Apr 2019 10:18:50 -0500
4 Subject: tracing: Prevent hist_field_var_ref() from accessing NULL
5 tracing_map_elts
6
7 [ Upstream commit 55267c88c003a3648567beae7c90512d3e2ab15e ]
8
9 hist_field_var_ref() is an implementation of hist_field_fn_t(), which
10 can be called with a null tracing_map_elt elt param when assembling a
11 key in event_hist_trigger().
12
13 In the case of hist_field_var_ref() this doesn't make sense, because a
14 variable can only be resolved by looking it up using an already
15 assembled key i.e. a variable can't be used to assemble a key since
16 the key is required in order to access the variable.
17
18 Upper layers should prevent the user from constructing a key using a
19 variable in the first place, but in case one slips through, it
20 shouldn't cause a NULL pointer dereference. Also if one does slip
21 through, we want to know about it, so emit a one-time warning in that
22 case.
23
24 Link: http://lkml.kernel.org/r/64ec8dc15c14d305295b64cdfcc6b2b9dd14753f.1555597045.git.tom.zanussi@linux.intel.com
25
26 Reported-by: Vincent Bernat <vincent@bernat.ch>
27 Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
28 Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
29 Signed-off-by: Sasha Levin <sashal@kernel.org>
30 ---
31 kernel/trace/trace_events_hist.c | 3 +++
32 1 file changed, 3 insertions(+)
33
34 diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
35 index 11853e90b649..3f34cfb66a85 100644
36 --- a/kernel/trace/trace_events_hist.c
37 +++ b/kernel/trace/trace_events_hist.c
38 @@ -1632,6 +1632,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 --
49 2.20.1
50