Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp364004rwb; Fri, 18 Nov 2022 02:33:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ucYCK3o/6+hyDM+x3HsXcnyBzNSwScABu/xjIFVaQnbODnav8dfa250TAm3HcUIQpuR+P X-Received: by 2002:a63:2361:0:b0:45f:f8df:108e with SMTP id u33-20020a632361000000b0045ff8df108emr6043109pgm.127.1668767619629; Fri, 18 Nov 2022 02:33:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668767619; cv=none; d=google.com; s=arc-20160816; b=DKip/1I5Eg81y5PYTYhzNzHDDVsN/0U5wkLMVIkq88IbfOQX/HfqJpIGHTVpJkTOm2 Tmd9Hwv9pJs4Tk91pfX7DntDZ6e4dwdjhganl1dAkunXgMX8Tl1V2fs8eApqK3tw2IMe yM/ka9K3Dw+UGOq4XxD5wKhlVrY5phIR1aU4wCguVv/3wBIVanidXAlNThpwKEt4QnHh j4QUFKQdue2JQL4x7rbYiYuZNG5h1nNTA2fuV8/PFdBmUSQ5374nPJx/ckR/KvkoU4R2 9iICYom+A7SA+URzdWyR8+TpCeSmfjj9nTvdsJIytvYOUNXuq5vYCLsbqU1iZ6yPV6YG 94Sg== 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 :cc:to:subject; bh=OYgP03zM2ukIUH84kIkouOd79aIrevE06xM9lQdlXXY=; b=QnqJUj/DUAdZYwnuu+hlh6Bsw+v0zAj6PWc6GQB92Vjdub2NgWsIbrXsfrfkMiTyBq uK2bm2/wN09eNSAldF13x9Jgss5I2QzzvH0SIt7lGYgu3W1x8tMM8Vw2jFA4uMGdYl2+ RIOgE5jxixSEqT+X9ltEGF3HizgZOcMe0SZYJ/jE6Z3V+DVA6GyiWBU9SkGhuFOiCXz1 qPHIIzS78StjWaW8RC0zH/gwmohjYXYSTT/szu08YaGBqcoSkCSnYyat2I55PUgbDMtm x0IeD71Ns6VAqskrMT9wBOmmxSA6vyp3Pmq/fr6Td7STwzkFpozjB+OYgIIoOVSi3Foo XhiQ== 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 j5-20020a170903028500b00186a8c18856si3309576plr.451.2022.11.18.02.33.24; Fri, 18 Nov 2022 02:33:39 -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 S241621AbiKRKVT (ORCPT + 92 others); Fri, 18 Nov 2022 05:21:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241596AbiKRKVR (ORCPT ); Fri, 18 Nov 2022 05:21:17 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E7F91522 for ; Fri, 18 Nov 2022 02:21:16 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NDCV11VNQzHvrW; Fri, 18 Nov 2022 18:20:41 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 18 Nov 2022 18:21:13 +0800 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.31; Fri, 18 Nov 2022 18:21:13 +0800 Subject: Re: [PATCH] tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line To: Steven Rostedt CC: , References: <20221114022946.66255-1-yangjihong1@huawei.com> <20221117164003.6e655615@gandalf.local.home> From: Yang Jihong Message-ID: <188a48b7-f426-6348-086e-22e56bb07206@huawei.com> Date: Fri, 18 Nov 2022 18:21:12 +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: <20221117164003.6e655615@gandalf.local.home> 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: dggems704-chm.china.huawei.com (10.3.19.181) 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, On 2022/11/18 5:40, Steven Rostedt wrote: > On Mon, 14 Nov 2022 10:29:46 +0800 > 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 | 13 +++++++++++++ >> 1 file changed, 13 insertions(+) >> >> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c >> index 47a44b055a1d..2a8d5c68c29b 100644 >> --- a/kernel/trace/trace.c >> +++ b/kernel/trace/trace.c >> @@ -6788,6 +6788,19 @@ tracing_read_pipe(struct file *filp, char __user *ubuf, >> if (ret == TRACE_TYPE_PARTIAL_LINE) { >> /* don't print partial lines */ >> iter->seq.seq.len = save_len; >> + >> + /* >> + * If one trace_line of the tracer overflows seq_file >> + * buffer, trace_seq_to_user returns -EBUSY because >> + * nothing in the sequence (iter->seq.seq.len = \ >> + * iter->seq.seq.readpos = 0). >> + * In this case, we need to consume, otherwise, >> + * "while" will peek this event next time, resulting >> + * in an infinite loop. >> + */ >> + if (trace_seq_has_overflowed(&iter->seq)) >> + trace_consume(iter); > > Instead of consuming it, I think the right solution is to print the partial > line. Something like: > > if (trace_seq_has_overflowed(&iter->seq)) { > char dots[] = "..."; > > iter->seq.seq.len -= sizeof(dots) + 1; > iter->seq.seq.full = 0; > trace_seq_puts(&iter->seq, dots); > trace_consume(iter); > break; > } > > iter->seq.seq.len = save_len; > break; > > That way we can see the broken trace event and not just silently drop it. > Ok, will change in next version.(Because iter->seq.seq.len may be smaller than strlen(dots), direct subtraction here may not be appropriate.) Thanks, Yang