Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tracing: Fix partial reading of trace event's id file
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 golang/go#29399 This code was mentioned as problematic in commit cd458ba ("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/[email protected] Cc: Orit Wasserman <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: [email protected] Fixes: 23725ae ("ftrace: provide an id file for each event") Signed-off-by: Elazar Leibovich <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
- Loading branch information