]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/5.0.19/tracing-fix-partial-reading-of-trace-event-s-id-file.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 5.0.19 / tracing-fix-partial-reading-of-trace-event-s-id-file.patch
CommitLineData
dc13a30d
GKH
1From cbe08bcbbe787315c425dde284dcb715cfbf3f39 Mon Sep 17 00:00:00 2001
2From: Elazar Leibovich <elazar@lightbitslabs.com>
3Date: Mon, 31 Dec 2018 13:58:37 +0200
4Subject: tracing: Fix partial reading of trace event's id file
5
6From: Elazar Leibovich <elazar@lightbitslabs.com>
7
8commit cbe08bcbbe787315c425dde284dcb715cfbf3f39 upstream.
9
10When reading only part of the id file, the ppos isn't tracked correctly.
11This is taken care by simple_read_from_buffer.
12
13Reading a single byte, and then the next byte would result EOF.
14
15While this seems like not a big deal, this breaks abstractions that
16reads information from files unbuffered. See for example
17https://github.com/golang/go/issues/29399
18
19This code was mentioned as problematic in
20commit cd458ba9d5a5
21("tracing: Do not (ab)use trace_seq in event_id_read()")
22
23An example C code that show this bug is:
24
25 #include <stdio.h>
26 #include <stdint.h>
27
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <unistd.h>
32
33 int main(int argc, char **argv) {
34 if (argc < 2)
35 return 1;
36 int fd = open(argv[1], O_RDONLY);
37 char c;
38 read(fd, &c, 1);
39 printf("First %c\n", c);
40 read(fd, &c, 1);
41 printf("Second %c\n", c);
42 }
43
44Then run with, e.g.
45
46 sudo ./a.out /sys/kernel/debug/tracing/events/tcp/tcp_set_state/id
47
48You'll notice you're getting the first character twice, instead of the
49first two characters in the id file.
50
51Link: http://lkml.kernel.org/r/20181231115837.4932-1-elazar@lightbitslabs.com
52
53Cc: Orit Wasserman <orit.was@gmail.com>
54Cc: Oleg Nesterov <oleg@redhat.com>
55Cc: Ingo Molnar <mingo@redhat.com>
56Cc: stable@vger.kernel.org
57Fixes: 23725aeeab10b ("ftrace: provide an id file for each event")
58Signed-off-by: Elazar Leibovich <elazar@lightbitslabs.com>
59Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
60Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
61
62---
63 kernel/trace/trace_events.c | 3 ---
64 1 file changed, 3 deletions(-)
65
66--- a/kernel/trace/trace_events.c
67+++ b/kernel/trace/trace_events.c
68@@ -1318,9 +1318,6 @@ event_id_read(struct file *filp, char __
69 char buf[32];
70 int len;
71
72- if (*ppos)
73- return 0;
74-
75 if (unlikely(!id))
76 return -ENODEV;
77