Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp674893rwb; Tue, 29 Nov 2022 04:02:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf5e7G6ctA1GSOezhzVtOhJihEfqv3fx2tBBZyKx5z39NN0nIYXmX+ObD+DLwS1oZviuSASP X-Received: by 2002:a62:5f81:0:b0:56b:bb06:7dd5 with SMTP id t123-20020a625f81000000b0056bbb067dd5mr37735308pfb.3.1669723375056; Tue, 29 Nov 2022 04:02:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669723375; cv=none; d=google.com; s=arc-20160816; b=FNgOB1mByOAvZufqy+Hau99aNsIlYwjVKwPtslnLjMRkeov6+Pcad02vdo5VfZDuBL eF0WKXgfXFPy2kRW9u/5Zq0HwIV64W5bj18MTvs5PzU/QNwBJHLpSTfCPOPlkbzjPKR1 pYI6i6zvmCAm9lhd7TFbPDEE7RDRwZlBi3yPFBNJPrVtnwtjyVhAEBuyQujP1y1gOMGg 2r2q3C9XQRg3zs8YS4KApObBKvITR2MQSfiaMgSm9zfYsk2bpXJOdvcD92SkhfBAQ1ai Gkdd8yAZVNGRuJ/LgVgwlQr/qJpSwROCqv+7NyWURu1HPfCYxdBle8Jw9qqXZANqU3Xj fkJw== 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=2mKJdBqVN0Us8o+ObnsH4Bn7nyb5TqnmdOabLx8C4WU=; b=zOgnoKNsYePe8LzukZAr1q+O4GR4Gve4t02Ro98bhS7AVd1ukc2+orMqMT50diIiZA SalvKnoxhajn9NSsNylgzdJ2qpsBxj2Prg7NKhvSl8JrVX+wFf9QMkY/+0JpNHCcae/1 NJRSxlfUPpVWYh5s8brX4NQNaLyr+DR+athZAdWW3rXyqHuvsb4LXLfoVcqQJDUqtmdK Gw354a2pyPtjQHK5xVi/t0GmFk9w9ZAu++ecaANsGvN6EGYcbKjpJapySFAnBNRIc9rH LIuMvyIpn9QVoiUspVbETpmIyBL14wRHy7+V4+89MT4Lv755qi3DmBUQiEFLIVnJj/eW 74Tg== 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 e185-20020a6369c2000000b0047711269d75si2018279pgc.516.2022.11.29.04.02.25; Tue, 29 Nov 2022 04:02:55 -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 S229973AbiK2Ldm (ORCPT + 84 others); Tue, 29 Nov 2022 06:33:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233140AbiK2LdV (ORCPT ); Tue, 29 Nov 2022 06:33:21 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEB17D95 for ; Tue, 29 Nov 2022 03:33:09 -0800 (PST) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NM0Vd6S4GzJnyB; Tue, 29 Nov 2022 19:29:45 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 29 Nov 2022 19:33:08 +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; Tue, 29 Nov 2022 19:33:07 +0800 From: Yang Jihong To: , , CC: Subject: [PATCH v4] tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line Date: Tue, 29 Nov 2022 19:30:09 +0800 Message-ID: <20221129113009.182425-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: dggems703-chm.china.huawei.com (10.3.19.180) 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 | 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; } -- 2.30.GIT