android_kernel_samsung_a7y1.../kernel/trace
Elazar Leibovich 14abb5143d tracing: Fix partial reading of trace event's id file
commit cbe08bcbbe787315c425dde284dcb715cfbf3f39 upstream.

When reading only part of the id file, the ppos isn't tracked correctly.
This is taken care by simple_read_from_buffer.

Reading a single byte, and then the next byte would result EOF.

While this seems like not a big deal, this breaks abstractions that
reads information from files unbuffered. See for example
https://github.com/golang/go/issues/29399

This code was mentioned as problematic in
commit cd458ba9d5a5
("tracing: Do not (ab)use trace_seq in event_id_read()")

An example C code that show this bug is:

  #include <stdio.h>
  #include <stdint.h>

  #include <sys/types.h>
  #include <sys/stat.h>
  #include <fcntl.h>
  #include <unistd.h>

  int main(int argc, char **argv) {
    if (argc < 2)
      return 1;
    int fd = open(argv[1], O_RDONLY);
    char c;
    read(fd, &c, 1);
    printf("First  %c\n", c);
    read(fd, &c, 1);
    printf("Second %c\n", c);
  }

Then run with, e.g.

  sudo ./a.out /sys/kernel/debug/tracing/events/tcp/tcp_set_state/id

You'll notice you're getting the first character twice, instead of the
first two characters in the id file.

Link: http://lkml.kernel.org/r/20181231115837.4932-1-elazar@lightbitslabs.com

Cc: Orit Wasserman <orit.was@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 23725aeeab10b ("ftrace: provide an id file for each event")
Signed-off-by: Elazar Leibovich <elazar@lightbitslabs.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-04-06 18:14:00 +02:00
..
blktrace.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
bpf_trace.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ftrace.c kprobes: Mark ftrace mcount handler functions nokprobe 2020-04-06 15:57:02 +02:00
gpu-traces.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
Kconfig A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
Makefile A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
power-traces.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ring_buffer_benchmark.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ring_buffer.c trace: Fix preempt_enable_no_resched() abuse 2020-04-06 16:38:41 +02:00
rpm-traces.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_benchmark.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_benchmark.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_branch.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_clock.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_entries.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_event_perf.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_events_filter_test.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_events_filter.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_events_trigger.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_events.c tracing: Fix partial reading of trace event's id file 2020-04-06 18:14:00 +02:00
trace_export.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_functions_graph.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_functions.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_irqsoff.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_kdb.c tracing: kdb: Fix ftdump to not sleep 2020-04-06 14:21:40 +02:00
trace_kprobe.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_mmiotrace.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_nop.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_output.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_output.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_printk.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_probe.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_probe.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_sched_switch.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_sched_wakeup.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_selftest_dynamic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_selftest.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_seq.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_stack.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_stat.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_stat.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_syscalls.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace_uprobe.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
trace.c tracing: kdb: Fix ftdump to not sleep 2020-04-06 14:21:40 +02:00
trace.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30