Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6116006rwb; Sun, 11 Dec 2022 19:26:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf4SierKzlWY7euSSn5V2XFRwe68gCas8JodS7CFJBIqpfGCcmr9LjosN7TVPsNccmpf0v0x X-Received: by 2002:a17:902:9891:b0:189:2688:c97f with SMTP id s17-20020a170902989100b001892688c97fmr13632785plp.50.1670815582334; Sun, 11 Dec 2022 19:26:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670815582; cv=none; d=google.com; s=arc-20160816; b=sWLzIq3aBS5F6Q1H0yyW2dgFxFNxRMyXCP211ep/xkHg16HfA3+TZNeSicmSgWLw3b 9CFk760lF6sSM9gbOppChZWMMgCztnChr3BjhNcrdrGq4UUncIvoYcwTu0hh5NE375jM 3RE4J+MlDesA4vdItGy9TctJU1iy9CgPOdXigGAFmVHF5GtWMlBEdYrKqyzVF/z8Db3Q D6idSE86q/TXPlJ9217qHNGjWZnFaowfh2uxcw38uLRb92sgpG93LzpIxK0tXTew863Q C5vGvrrkxHcJiOmNv4GXAkVdr0USmP6CyJOGATi9N+RTSd+0zgHxtoPlw8D18rHqpfNP /Wcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :to:subject; bh=fpXZuGIevgx24G88N+kNx0ISMAQapDoPya7bJVLhMus=; b=d3xdIR8t4mmZxJULPodfjNbbBtYkqJUcYJ1c9T50mtKdIDlS9Ma/s0blJTLLRezWwx A+Y9w7lEttKcAlbQgmjpvaPnExRZls1mIgYVi18err7qEiD3y6gnKJIiSHyfgzDvt8dX os5dVQqpDV+jsK+HYR18jKMdJYpEqbthngqzOjS04YYKWw27Mz3RwuAzt4LtljTxH+ka 5bVIji7NP2//SBdB+LiX8r/Bp+YsM19B3VgyfPLCfLyskAt21ctZENHUWJ2X+dCS5SqZ kdvu4lb+q1Lb3pP3ETXaDUSkWcw+hdychdcn6dREFzxHvefnspABXRzH/IPbXY6K9Rk8 u0jg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g6-20020a636b06000000b00477bf2ebf14si8036620pgc.266.2022.12.11.19.26.12; Sun, 11 Dec 2022 19:26:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230498AbiLLC5O (ORCPT + 76 others); Sun, 11 Dec 2022 21:57:14 -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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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; > } >