]>
Commit | Line | Data |
---|---|---|
53722911 GKH |
1 | From cbe08bcbbe787315c425dde284dcb715cfbf3f39 Mon Sep 17 00:00:00 2001 |
2 | From: Elazar Leibovich <elazar@lightbitslabs.com> | |
3 | Date: Mon, 31 Dec 2018 13:58:37 +0200 | |
4 | Subject: tracing: Fix partial reading of trace event's id file | |
5 | ||
6 | From: Elazar Leibovich <elazar@lightbitslabs.com> | |
7 | ||
8 | commit cbe08bcbbe787315c425dde284dcb715cfbf3f39 upstream. | |
9 | ||
10 | When reading only part of the id file, the ppos isn't tracked correctly. | |
11 | This is taken care by simple_read_from_buffer. | |
12 | ||
13 | Reading a single byte, and then the next byte would result EOF. | |
14 | ||
15 | While this seems like not a big deal, this breaks abstractions that | |
16 | reads information from files unbuffered. See for example | |
17 | https://github.com/golang/go/issues/29399 | |
18 | ||
19 | This code was mentioned as problematic in | |
20 | commit cd458ba9d5a5 | |
21 | ("tracing: Do not (ab)use trace_seq in event_id_read()") | |
22 | ||
23 | An 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 | ||
44 | Then run with, e.g. | |
45 | ||
46 | sudo ./a.out /sys/kernel/debug/tracing/events/tcp/tcp_set_state/id | |
47 | ||
48 | You'll notice you're getting the first character twice, instead of the | |
49 | first two characters in the id file. | |
50 | ||
51 | Link: http://lkml.kernel.org/r/20181231115837.4932-1-elazar@lightbitslabs.com | |
52 | ||
53 | Cc: Orit Wasserman <orit.was@gmail.com> | |
54 | Cc: Oleg Nesterov <oleg@redhat.com> | |
55 | Cc: Ingo Molnar <mingo@redhat.com> | |
56 | Cc: stable@vger.kernel.org | |
57 | Fixes: 23725aeeab10b ("ftrace: provide an id file for each event") | |
58 | Signed-off-by: Elazar Leibovich <elazar@lightbitslabs.com> | |
59 | Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> | |
60 | Signed-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 | @@ -1288,9 +1288,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 |