tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line
PATCH v4 1/1 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.
Signed-off-by Yang Jihong <[email protected]>
--- kernel/trace/trace.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
kernel/trace/trace.c +14 -1
@@ -6787,7 +6787,20 @@ tracing_read_pipe(struct file *filp, char __user *ubuf, ret =print_trace_line (iter);if (ret ==TRACE_TYPE_PARTIAL_LINE ) { -/* don't print partial lines */ +/* +* If one print_trace_line() fills entire trace_seq in one shot, +* trace_seq_to_user() will returns -EBUSY because save_len == 0, +* In this case, we need to consume it, otherwise, loop will peek +* this event next time, resulting in an infinite loop. +*/ +if (save_len ==0 ) { + iter->seq.full =0 ; +trace_seq_puts (&iter->seq,"[LINE TOO BIG]\n" ); +trace_consume (iter); +break ; + } + +/* In other cases, don't print partial lines */ iter->seq.seq.len = save_len;break ; }
Signature · 1 line
2.30.GIT
Hello,
PING.
Are there any other problems with this patch?
Thanks,
Yang.
Quoted 35 lines · Yang Jihong
print_trace_linemay overflowseq_filebuffer. If the event is not consumed, the while loop keeps peeking this event, causing a infinite loop.Signed-off-by Yang Jihong <[email protected]>--- kernel/trace/trace.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)kernel/trace/trace.c +14
-1@@ -6787,7 +6787,20 @@ tracing_read_pipe(struct file *filp, char __user *ubuf, ret =print_trace_line (iter);if (ret ==TRACE_TYPE_PARTIAL_LINE ) { -/* don't print partial lines */ +/* +* If one print_trace_line() fills entire trace_seq in one shot, +* trace_seq_to_user() will returns -EBUSY because save_len == 0, +* In this case, we need to consume it, otherwise, loop will peek +* this event next time, resulting in an infinite loop. +*/ +if (save_len ==0 ) { + iter->seq.full =0 ; +trace_seq_puts (&iter->seq,"[LINE TOO BIG]\n" ); +trace_consume (iter); +break ; + } + +/* In other cases, don't print partial lines */ iter->seq.seq.len = save_len;break ; }
Steven Rostedt
maintainerQuoted 5 lines · On Mon, 12 Dec 2022 10:57:08 +0800 Yang Jihong <[email protected]> wrote:
Hello,
PING.
Are there any other problems with this patch?
Thanks for the ping, I'll take a look at it. It somehow got lost in the noise of other patches :-/
-- Steve