Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2635021rwb; Thu, 17 Nov 2022 13:47:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf6C2GitKI20VSjSzjtDVFOISWs8hNJP09XhQudNjWdr51b5Slhf+UIpRJpCJsTanOrOAmp8 X-Received: by 2002:a17:90a:19cb:b0:205:fa0b:798c with SMTP id 11-20020a17090a19cb00b00205fa0b798cmr10528929pjj.179.1668721667584; Thu, 17 Nov 2022 13:47:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668721667; cv=none; d=google.com; s=arc-20160816; b=02Eu1kPQY9IB13UHJQbxHDngbi3utGoNZp2TBJq5TPoxGYj8tvBGerHO0RftsxIfzQ K7W/8zzWz2NkPKSX/MB18k6LLUPhYX6LjMm63itRvymvsEnEY6fdPEfbRGS33gvbo9FK y6+erBxvfBx0qpEJDQG0mQbZKRRkdnO31EjlEY8FdMM8X1CXhUfmSF3ZY5hv202yZ3aM YfRIiejjMgURHFE4eMDYWGfynua+BotemGKlUQAyGmEf+Zgqq/5uJ+qD3GNjlasTEwkf eLT7GaILn+80ryMQ49tYsMwGHAC2TL8K2fPk52iGfpUNntLTNL8VC64ClF+DMSPa15da o62Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=qt7lFHxJGrtq01FXziOK6mid7x58kOtxhLjlMdDxifc=; b=jf7Dti+zkMQ8ucmpxDVLplnp7sR5LLWBzf49RY7FZzo7ZvUTiYkVoFPxH8vM6hD+WJ Cl5d111Alp6iOteDP3F+WNhl9RhC+3Dw68qCAPXDL5W7tJAbY70FWBfsY1d+thmRWQmc 5n+a0RykHXkrysGmp4HBFwvcxX35Nw2zVINJ7MRehsryO36Y/38yCs8LP7vWE7Flg3yK cZJwkfzv2IaYgsSeUS3pCsAS9d8PHoH3PGCTeXHKIpdXREx/iqNobRRle7XwPbLRobdm /1pYHe4SBXqRXjthcYf/sXBAZWx7MvmGrK9nw8ukEimpKMdcorofoMW16OOCXHR/pIjQ hFDA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z1-20020a1709028f8100b001871b8770d3si1693523plo.599.2022.11.17.13.47.35; Thu, 17 Nov 2022 13:47:47 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240219AbiKQVkP (ORCPT + 92 others); Thu, 17 Nov 2022 16:40:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240096AbiKQVkJ (ORCPT ); Thu, 17 Nov 2022 16:40:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D3276829A for ; Thu, 17 Nov 2022 13:40:07 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ED4C162281 for ; Thu, 17 Nov 2022 21:40:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7AA6C433D6; Thu, 17 Nov 2022 21:40:05 +0000 (UTC) Date: Thu, 17 Nov 2022 16:40:03 -0500 From: Steven Rostedt To: Yang Jihong Cc: , Subject: Re: [PATCH] tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line Message-ID: <20221117164003.6e655615@gandalf.local.home> In-Reply-To: <20221114022946.66255-1-yangjihong1@huawei.com> References: <20221114022946.66255-1-yangjihong1@huawei.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,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 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. -- Steve > + > break; > } > if (ret != TRACE_TYPE_NO_CONSUME)