Skip to content

Commit c1ac03a

Browse files
Yang Jihongrostedt
authored andcommitted
tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line
print_trace_line may overflow seq_file buffer. If the event is not consumed, the while loop keeps peeking this event, causing a infinite loop. Link: https://lkml.kernel.org/r/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: [email protected] Fixes: 088b1e4 ("ftrace: pipe fixes") Signed-off-by: Yang Jihong <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent d358dfe commit c1ac03a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

kernel/trace/trace.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6802,7 +6802,20 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
68026802

68036803
ret = print_trace_line(iter);
68046804
if (ret == TRACE_TYPE_PARTIAL_LINE) {
6805-
/* don't print partial lines */
6805+
/*
6806+
* If one print_trace_line() fills entire trace_seq in one shot,
6807+
* trace_seq_to_user() will returns -EBUSY because save_len == 0,
6808+
* In this case, we need to consume it, otherwise, loop will peek
6809+
* this event next time, resulting in an infinite loop.
6810+
*/
6811+
if (save_len == 0) {
6812+
iter->seq.full = 0;
6813+
trace_seq_puts(&iter->seq, "[LINE TOO BIG]\n");
6814+
trace_consume(iter);
6815+
break;
6816+
}
6817+
6818+
/* In other cases, don't print partial lines */
68066819
iter->seq.seq.len = save_len;
68076820
break;
68086821
}

0 commit comments

Comments
 (0)