diff options
author | Steven Rostedt (Red Hat) <rostedt@goodmis.org> | 2016-09-23 22:57:13 -0400 |
---|---|---|
committer | Sasha Levin <alexander.levin@verizon.com> | 2016-10-03 21:42:24 -0400 |
commit | abd91e8b5b0531b34d5e9b5be4a0732068a7c4f5 (patch) | |
tree | c7755aad234b47bff93c475df57acc1e415b565c | |
parent | 7d0e57776d25df67877ec1db8fe61a80a46d0fb1 (diff) | |
download | lwn-abd91e8b5b0531b34d5e9b5be4a0732068a7c4f5.tar.gz lwn-abd91e8b5b0531b34d5e9b5be4a0732068a7c4f5.zip |
tracing: Move mutex to protect against resetting of seq data
[ Upstream commit 1245800c0f96eb6ebb368593e251d66c01e61022 ]
The iter->seq can be reset outside the protection of the mutex. So can
reading of user data. Move the mutex up to the beginning of the function.
Fixes: d7350c3f45694 ("tracing/core: make the read callbacks reentrants")
Cc: stable@vger.kernel.org # 2.6.30+
Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
-rw-r--r-- | kernel/trace/trace.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index de6ea94c41bb..b61e501b4496 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -4694,19 +4694,20 @@ tracing_read_pipe(struct file *filp, char __user *ubuf, struct trace_iterator *iter = filp->private_data; ssize_t sret; - /* return any leftover data */ - sret = trace_seq_to_user(&iter->seq, ubuf, cnt); - if (sret != -EBUSY) - return sret; - - trace_seq_init(&iter->seq); - /* * Avoid more than one consumer on a single file descriptor * This is just a matter of traces coherency, the ring buffer itself * is protected. */ mutex_lock(&iter->mutex); + + /* return any leftover data */ + sret = trace_seq_to_user(&iter->seq, ubuf, cnt); + if (sret != -EBUSY) + goto out; + + trace_seq_init(&iter->seq); + if (iter->trace->read) { sret = iter->trace->read(iter, filp, ubuf, cnt, ppos); if (sret) |