From: Steven Rostedt (VMware) Date: Thu, 2 Feb 2017 21:59:06 +0000 (-0500) Subject: ftrace: Have set_graph_functions handle write with RDWR X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ae98d27afc3bde5a48f440d905317602a5cfb0d2;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git ftrace: Have set_graph_functions handle write with RDWR Since reading the set_graph_functions uses seq functions, which sets the file->private_data pointer to a seq_file descriptor. On writes the ftrace_graph_data descriptor is set to file->private_data. But if the file is opened for RDWR, the ftrace_graph_write() will incorrectly use the file->private_data descriptor instead of ((struct seq_file *)file->private_data)->private pointer, and this can crash the kernel. Acked-by: Namhyung Kim Signed-off-by: Steven Rostedt (VMware) --- diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index b7df0dcf8652..0233c8cb45f4 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4842,6 +4842,12 @@ ftrace_graph_write(struct file *file, const char __user *ubuf, if (trace_parser_get_init(&parser, FTRACE_BUFF_MAX)) return -ENOMEM; + /* Read mode uses seq functions */ + if (file->f_mode & FMODE_READ) { + struct seq_file *m = file->private_data; + fgd = m->private; + } + read = trace_get_user(&parser, ubuf, cnt, ppos); if (read >= 0 && trace_parser_loaded((&parser))) {