From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E241C4332F for ; Mon, 12 Dec 2022 02:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230500AbiLLC5P (ORCPT ); Sun, 11 Dec 2022 21:57:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbiLLC5N (ORCPT ); Sun, 11 Dec 2022 21:57:13 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67C266335 for ; Sun, 11 Dec 2022 18:57:11 -0800 (PST) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NVmV85YHJzJqTF; Mon, 12 Dec 2022 10:56:16 +0800 (CST) Received: from [10.67.111.205] (10.67.111.205) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 12 Dec 2022 10:57:08 +0800 Subject: Re: [PATCH v4] tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line To: , , References: <20221129113009.182425-1-yangjihong1@huawei.com> From: Yang Jihong Message-ID: <46733774-295a-ade9-497d-6e73c6c468de@huawei.com> Date: Mon, 12 Dec 2022 10:57:08 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20221129113009.182425-1-yangjihong1@huawei.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, PING. Are there any other problems with this patch? Thanks, Yang. On 2022/11/29 19:30, Yang Jihong wrote: > 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 > --- > kernel/trace/trace.c | 15 ++++++++++++++- > 1 file changed, 14 insertions(+), 1 deletion(-) > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index a7fe0e115272..de7c99f4b539 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -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; > } >