Skip to content

Commit e6711e3

Browse files
rostedtbwhacks
authored andcommitted
tracing: Move mutex to protect against resetting of seq data
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]>
1 parent 1f53d4c commit e6711e3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

kernel/trace/trace.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3331,13 +3331,6 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
33313331
static struct tracer *old_tracer;
33323332
ssize_t sret;
33333333

3334-
/* return any leftover data */
3335-
sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3336-
if (sret != -EBUSY)
3337-
return sret;
3338-
3339-
trace_seq_init(&iter->seq);
3340-
33413334
/* copy the tracer to avoid using a global lock all around */
33423335
mutex_lock(&trace_types_lock);
33433336
if (unlikely(old_tracer != current_trace && current_trace)) {
@@ -3352,6 +3345,14 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
33523345
* is protected.
33533346
*/
33543347
mutex_lock(&iter->mutex);
3348+
3349+
/* return any leftover data */
3350+
sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
3351+
if (sret != -EBUSY)
3352+
goto out;
3353+
3354+
trace_seq_init(&iter->seq);
3355+
33553356
if (iter->trace->read) {
33563357
sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
33573358
if (sret)

0 commit comments

Comments
 (0)