Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp501413imn; Wed, 27 Jul 2022 12:00:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u01kCd9vBzrcuqG0zAdv+Pvnuf1fMMAR+61WouTL+6WNsLFYcHmHqV/hVNsRI9t9W65mWc X-Received: by 2002:a17:907:8a28:b0:72e:cef6:eba0 with SMTP id sc40-20020a1709078a2800b0072ecef6eba0mr18378927ejc.765.1658948407506; Wed, 27 Jul 2022 12:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658948407; cv=none; d=google.com; s=arc-20160816; b=T3Ci2jpqD3W54y8MyQjYvrdHESUxS2DwfZHlTYA6yggoxD4/5OGu58KkOkSJMI6jN3 aGBkHGtuO0LbvkdVS1PxAcoU8l8HS2T5MBkWdliUimE5sFnIhhZfr/awFTvOSuBIe9mL yTzX+wSzEEOOhLqK0qhsfULZx59AEkA0a/RWcZtUV9rlexy82XGvYYWiSeh80dOY4hU9 JW/tR/kvgNI6T0ojaEojptiH5hdGPSibOjoOV+9BdibylT0mdkKKotFeKZSDLijekSiO ArDcWATMJ/MXsYFmpHEFnzpDM/dC4lNIjTHwuarh1b+5DLmh7Y1qBUAiMEozIGTHztHy fmlA== 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=dAYrha8If4ziGJlKlbTvw5ehthEz4yr9ueuv3HZmkps=; b=z9RNzJ+38TXd75ytesln4tYdhwjxqlcoEc+iJAuoqALAyUbKPPbxpDJVWjxjPDZPaQ 5kXp4YBMDtl/uiOXy1NHyiR+GcpkU60sebLGRkBLExdcJjMGQA5ZQB28OWIR67gOPBKQ 3J2PZSMZ9ma7WY5vx2k0xe9A0WXkFY4l38BTR40Zqo/yJ5/FC+4fcvmQ+MqVw157b5c/ 7weZo3cqMhxEPVwDiRpoiWIp30xqH24NJXP/UZ/AQnbazplMk/NQln20JQFecIr7wB0y N47dmJM91Icd0e68GlXtb9F9PdKXb1PUbSOl6i6ptiIXWlyLxc4zSAOeXmpfenqea1H5 Z+4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="nt29/CD3"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw20-20020a170906c79400b007122fe7f49csi5046207ejb.424.2022.07.27.11.59.42; Wed, 27 Jul 2022 12:00:07 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="nt29/CD3"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242075AbiG0R1T (ORCPT + 99 others); Wed, 27 Jul 2022 13:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242070AbiG0R06 (ORCPT ); Wed, 27 Jul 2022 13:26:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 508FF7E312; Wed, 27 Jul 2022 09:46:53 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B7547600BE; Wed, 27 Jul 2022 16:46:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C318EC433C1; Wed, 27 Jul 2022 16:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658940394; bh=9lAlWYIreBqMVyYbmM7NsAPiX5t/podqVbEtNIGuWOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nt29/CD3lMsOaC7XQ01+TL2DCw64rgEuOx4FArQC+mjNUqeC3gyXZWfPQ31doaZ73 0/RvGjA2IJujX32jsSgE1raeKZdhcLLzNxwD6mdg3lBjlaP2k65o2IyhCE8hPGkgqR DRjtPLvZVdj8xlCuYqK/T/+uOuaoFuCqMAVD1UAQ= 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)" , Sasha Levin Subject: [PATCH 5.15 171/201] tracing: Fix return value of trace_pid_write() Date: Wed, 27 Jul 2022 18:11:15 +0200 Message-Id: <20220727161034.910245226@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161026.977588183@linuxfoundation.org> References: <20220727161026.977588183@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 From: Wonhyuk Yang [ Upstream commit b27f266f74fbda4ee36c2b2b04d15992860cf23b ] 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: Sasha Levin --- kernel/trace/trace.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index abbe8489faae..d93f9c59f50e 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -711,13 +711,16 @@ int trace_pid_write(struct trace_pid_list *filtered_pids, 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; @@ -743,7 +746,6 @@ int trace_pid_write(struct trace_pid_list *filtered_pids, if (!nr_pids) { /* Cleared the list of pids */ trace_pid_list_free(pid_list); - read = ret; pid_list = NULL; } -- 2.35.1