Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2197636iof; Tue, 7 Jun 2022 22:57:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/HelNFgi1T5kiwIDb0Nor946tAkFErUcXdF7301lziqIw6ZYhi+86j1pWYP90k5xVSKZT X-Received: by 2002:a05:6a00:a8b:b0:4e1:52db:9e5c with SMTP id b11-20020a056a000a8b00b004e152db9e5cmr99300631pfl.38.1654667823904; Tue, 07 Jun 2022 22:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667823; cv=none; d=google.com; s=arc-20160816; b=rCyMPR2axCU9nAVpVhnlOD+xHV3tFP6qufrfnug0SRf8Dj8at+egA/eqt/B2wFheDq PkxdzgSSwDetCYUQ5f3zOwDgIktHEZi4ZvSJaKd7B3nJJohbKluuw5/GotRg1gBiCKWc 3XZasine4R2VEaN7jZDjs9DcK6Enxr3wVkSV7c1HlUM7GtykTMaH5U5xfk6S2kMxvIaR an8nMQEpz5G8Tjo5H9X5RKrR1g0eL3D5XDrVZ+MPNhwSGkcwWuNwS+O69UJCF+T3rqJ5 jrMO5Q1u5nwlK5b17jS3ZX6YHb7Ih/eoPIwRPVQPk12fEGyN54u4bBELvTUPG6dUdn/q VNSw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+EX1BG0LmVnshg9YjoCEYSswFamnca/09cnSy+wNtgs=; b=BKFdbNhw8QLPnKglEyPp/KudIbPR9GtmwPYiTD8SekZS0OHRACjVgNEUwNz5PH7+N1 57ZvZB/ZhRiSN7hptySncKToRqV9V3V60A8izE3Dm5o80tyYH5+ujd/D+4WAo6ufSuCW XY1CayevsQAkBSwYWCyYmWmZsRyPxf43ZtOdbJUj5v3ROz/ODYlvnuO6HRVDM7huzGzt hhz2iOi2fuAwkGXIVfaieWXhnj1ePQLGNDyXdpvwZY0jsKJqD8zgCRw87hMDlv/pkCEt m/xu9p6swrs9s632/qpzPPC9C4UDJ8B9ZlsrVCuOYCmPNM1Elpo5AE7tb38z76uVMF1w 0juQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NeIXa9Db; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n10-20020a170902e54a00b00163ab0bd9aesi29458636plf.415.2022.06.07.22.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:57:03 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NeIXa9Db; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 34F744B4174; Tue, 7 Jun 2022 22:23:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387048AbiFHA7y (ORCPT + 99 others); Tue, 7 Jun 2022 20:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383736AbiFGWSX (ORCPT ); Tue, 7 Jun 2022 18:18:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0A5026273B; Tue, 7 Jun 2022 12:20:23 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id E1941B823D5; Tue, 7 Jun 2022 19:20:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 555E8C385A5; Tue, 7 Jun 2022 19:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629607; bh=Tem+o6lhnk3u6n4qq+jmQ3aT0Hf1azAIzJZfIeFJADE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NeIXa9DbexgVV1DXzlCyGSnQYUDu/4NZv+TlKvMvdonWREJhi1ShLaO6/KIcJ9g9P w3w5N+QMirscn5bmaZKB5cs1d52yrSUYayywna25cHoyqgeeCJefqQ5U/EnncMo2Xx 0etH81JtKKtxSV65VaP7eWA/SJ+niPTUv4dqMW7Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ingo Molnar , Baik Song An , Hong Yeon Kim , Taeung Song , linuxgeek@linuxgeek.io, Wonhyuk Yang , "Steven Rostedt (Google)" Subject: [PATCH 5.18 751/879] tracing: Fix return value of trace_pid_write() Date: Tue, 7 Jun 2022 19:04:29 +0200 Message-Id: <20220607165024.659732528@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Wonhyuk Yang commit b27f266f74fbda4ee36c2b2b04d15992860cf23b upstream. Setting set_event_pid with trailing whitespace lead to endless write system calls like below. $ strace echo "123 " > /sys/kernel/debug/tracing/set_event_pid execve("/usr/bin/echo", ["echo", "123 "], ...) = 0 ... write(1, "123 \n", 5) = 4 write(1, "\n", 1) = 0 write(1, "\n", 1) = 0 write(1, "\n", 1) = 0 write(1, "\n", 1) = 0 write(1, "\n", 1) = 0 .... This is because, the result of trace_get_user's are not returned when it read at least one pid. To fix it, update read variable even if parser->idx == 0. The result of applied patch is below. $ strace echo "123 " > /sys/kernel/debug/tracing/set_event_pid execve("/usr/bin/echo", ["echo", "123 "], ...) = 0 ... write(1, "123 \n", 5) = 5 close(1) = 0 Link: https://lkml.kernel.org/r/20220503050546.288911-1-vvghjk1234@gmail.com Cc: Ingo Molnar Cc: Baik Song An Cc: Hong Yeon Kim Cc: Taeung Song Cc: linuxgeek@linuxgeek.io Cc: stable@vger.kernel.org Fixes: 4909010788640 ("tracing: Add set_event_pid directory for future use") Signed-off-by: Wonhyuk Yang Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -721,13 +721,16 @@ int trace_pid_write(struct trace_pid_lis pos = 0; ret = trace_get_user(&parser, ubuf, cnt, &pos); - if (ret < 0 || !trace_parser_loaded(&parser)) + if (ret < 0) break; read += ret; ubuf += ret; cnt -= ret; + if (!trace_parser_loaded(&parser)) + break; + ret = -EINVAL; if (kstrtoul(parser.buffer, 0, &val)) break; @@ -753,7 +756,6 @@ int trace_pid_write(struct trace_pid_lis if (!nr_pids) { /* Cleared the list of pids */ trace_pid_list_free(pid_list); - read = ret; pid_list = NULL; }