Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4999851rwb; Sun, 13 Nov 2022 19:13:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf6XEM+D1C+mbzjTPXHCbB77dWO9jiOT9EyPZJGRnZ67yHZt3ipzWkpRlRn+xx8U/bz6ojNJ X-Received: by 2002:a17:906:3956:b0:7a3:fc74:7fb4 with SMTP id g22-20020a170906395600b007a3fc747fb4mr9440825eje.17.1668395601217; Sun, 13 Nov 2022 19:13:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668395601; cv=none; d=google.com; s=arc-20160816; b=XVkoC8IgdgKHq4dd/TCqpROuW6rh9DbK5bKnGs/1nNG/1+0jar0GHBT9/f8e+w9Hr9 jVvuP2cEIc5KHdwK0c7OU6Sv+Tqa5kErKv6ulYVyEroY3Z6yEC7Xv0ZGmM69KEtnUtd6 hUKD5TYvcsvBRQSGVa2Avah944Kgbc2jJdGYtGXpaUaowrzoCi5V9Vq0Dv4lEK56bedd rU/E3NKh0Gz0JFaiZIbhcDOVymkN5irwhUNYo/wRqu1zsLbFWlYhcFJSObTCJtDIAHnQ LNd4IDgZd0n2X5Xxqjxn2jwbExCMbb0DW/v6MrgS7caVhtNmrdDuwNBedwbx2lsrl/3u YgQg== 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 :message-id:date:subject:cc:to:from; bh=M6NhVjbalKg1NhuI+EvCeLZxeM6a0eXsfKIjzZyB1vE=; b=Y5615aMpw+ydtytmWHSHXE5CymFCgqwLLKZyWqyHm7EB3QBAOzFkeJgdXx+cUlinfx Yg08grYHwMo2vE2IGIzZkIo6kMqGFiRjDsfRR+4Q2onHwsHpUoja4Jl290V/C5K0qbth TW5OTnSffyLMpr8m2aehn5V1oRfqUSPz1BSUdzvKeRNUbTHyJw4fBtJQYsevoSX9A9w3 unabbxeDvbhI4MWVN4SnOdZNfL8CmmNO7tpRN0jJe+AH51zxy2gNqWVZAy1LzIWXARm8 WOa3P215E6px73aclTUXE52970fcuaKcK8sBPi2izxjslmbhEE4XzYg7qYeFQ7bwCX3/ rhcA== 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 d25-20020a05640208d900b0046360343debsi7360103edz.153.2022.11.13.19.12.53; Sun, 13 Nov 2022 19:13:21 -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 S235551AbiKNCdB (ORCPT + 89 others); Sun, 13 Nov 2022 21:33:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbiKNCdA (ORCPT ); Sun, 13 Nov 2022 21:33:00 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53ACBDE94 for ; Sun, 13 Nov 2022 18:32:56 -0800 (PST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N9YHp35T5zRp2l; Mon, 14 Nov 2022 10:32:38 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 14 Nov 2022 10:32:54 +0800 Received: from ubuntu1804.huawei.com (10.67.174.61) 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; Mon, 14 Nov 2022 10:32:54 +0800 From: Yang Jihong To: , , CC: Subject: [PATCH] tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line Date: Mon, 14 Nov 2022 10:29:46 +0800 Message-ID: <20221114022946.66255-1-yangjihong1@huawei.com> X-Mailer: git-send-email 2.30.GIT MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.61] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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,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 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); + break; } if (ret != TRACE_TYPE_NO_CONSUME) -- 2.30.GIT