Skip to content

Commit

Permalink
tracing: Move mutex to protect against resetting of seq data
Browse files Browse the repository at this point in the history
commit 1245800 upstream.

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: d7350c3 ("tracing/core: make the read callbacks reentrants")
Reported-by: Al Viro <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <[email protected]>
  • Loading branch information
rostedt authored and bwhacks committed Nov 20, 2016
1 parent 1f53d4c commit e6711e3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -3331,13 +3331,6 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
static struct tracer *old_tracer;
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);

/* copy the tracer to avoid using a global lock all around */
mutex_lock(&trace_types_lock);
if (unlikely(old_tracer != current_trace && current_trace)) {
Expand All @@ -3352,6 +3345,14 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
* 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)
Expand Down

0 comments on commit e6711e3

Please sign in to comment.