]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.14.108/tracing-use-strncpy-instead-of-memcpy-for-string-keys-in-hist-triggers.patch
Linux 4.14.108
[thirdparty/kernel/stable-queue.git] / releases / 4.14.108 / tracing-use-strncpy-instead-of-memcpy-for-string-keys-in-hist-triggers.patch
CommitLineData
84d167bb
GKH
1From 9f0bbf3115ca9f91f43b7c74e9ac7d79f47fc6c2 Mon Sep 17 00:00:00 2001
2From: Tom Zanussi <tom.zanussi@linux.intel.com>
3Date: Mon, 4 Feb 2019 15:07:24 -0600
4Subject: tracing: Use strncpy instead of memcpy for string keys in hist triggers
5
6From: Tom Zanussi <tom.zanussi@linux.intel.com>
7
8commit 9f0bbf3115ca9f91f43b7c74e9ac7d79f47fc6c2 upstream.
9
10Because there may be random garbage beyond a string's null terminator,
11it's not correct to copy the the complete character array for use as a
12hist trigger key. This results in multiple histogram entries for the
13'same' string key.
14
15So, in the case of a string key, use strncpy instead of memcpy to
16avoid copying in the extra bytes.
17
18Before, using the gdbus entries in the following hist trigger as an
19example:
20
21 # echo 'hist:key=comm' > /sys/kernel/debug/tracing/events/sched/sched_waking/trigger
22 # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist
23
24 ...
25
26 { comm: ImgDecoder #4 } hitcount: 203
27 { comm: gmain } hitcount: 213
28 { comm: gmain } hitcount: 216
29 { comm: StreamTrans #73 } hitcount: 221
30 { comm: mozStorage #3 } hitcount: 230
31 { comm: gdbus } hitcount: 233
32 { comm: StyleThread#5 } hitcount: 253
33 { comm: gdbus } hitcount: 256
34 { comm: gdbus } hitcount: 260
35 { comm: StyleThread#4 } hitcount: 271
36
37 ...
38
39 # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l
40 51
41
42After:
43
44 # cat /sys/kernel/debug/tracing/events/sched/sched_waking/hist | egrep gdbus | wc -l
45 1
46
47Link: http://lkml.kernel.org/r/50c35ae1267d64eee975b8125e151e600071d4dc.1549309756.git.tom.zanussi@linux.intel.com
48
49Cc: Namhyung Kim <namhyung@kernel.org>
50Cc: stable@vger.kernel.org
51Fixes: 79e577cbce4c4 ("tracing: Support string type key properly")
52Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
53Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
54Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
55
56---
57 kernel/trace/trace_events_hist.c | 5 +++--
58 1 file changed, 3 insertions(+), 2 deletions(-)
59
60--- a/kernel/trace/trace_events_hist.c
61+++ b/kernel/trace/trace_events_hist.c
62@@ -872,9 +872,10 @@ static inline void add_to_key(char *comp
63 /* ensure NULL-termination */
64 if (size > key_field->size - 1)
65 size = key_field->size - 1;
66- }
67
68- memcpy(compound_key + key_field->offset, key, size);
69+ strncpy(compound_key + key_field->offset, (char *)key, size);
70+ } else
71+ memcpy(compound_key + key_field->offset, key, size);
72 }
73
74 static void event_hist_trigger(struct event_trigger_data *data, void *rec)