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
6 From: Elazar Leibovich <elazar@lightbitslabs.com>
8 commit cbe08bcbbe787315c425dde284dcb715cfbf3f39 upstream.
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.
13 Reading a single byte, and then the next byte would result EOF.
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
19 This code was mentioned as problematic in
21 ("tracing: Do not (ab)use trace_seq in event_id_read()")
23 An example C code that show this bug is:
28 #include <sys/types.h>
33 int main(int argc, char **argv) {
36 int fd = open(argv[1], O_RDONLY);
39 printf("First %c\n", c);
41 printf("Second %c\n", c);
46 sudo ./a.out /sys/kernel/debug/tracing/events/tcp/tcp_set_state/id
48 You'll notice you're getting the first character twice, instead of the
49 first two characters in the id file.
51 Link: http://lkml.kernel.org/r/20181231115837.4932-1-elazar@lightbitslabs.com
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>
63 kernel/trace/trace_events.c | 3 ---
64 1 file changed, 3 deletions(-)
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 __