Received: by 2002:ab2:6991:0:b0:1f2:fff1:ace7 with SMTP id v17csp189995lqo; Wed, 27 Mar 2024 10:12:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVEFpZCwGRed3hmiYnE9rB8/ZgMZh+nrNlz5ObGnVxjsTx6qNQGg1GOunVfGtqv5Qom3S4YOkGw+FinaAmL+k1HkWo12B2A2IqSdOOboQ== X-Google-Smtp-Source: AGHT+IGG2hY04TLWrnpRzF8CWKJlkLZdAETK79YAWG67KDSlb2g6VSQD2pGo95F8RIM+69FsqmNI X-Received: by 2002:a05:6a00:10c2:b0:6ea:b9a1:63d7 with SMTP id d2-20020a056a0010c200b006eab9a163d7mr510822pfu.10.1711559542766; Wed, 27 Mar 2024 10:12:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711559542; cv=pass; d=google.com; s=arc-20160816; b=M0DnJAEdgbbNvd4RYbnulFItJqJcQvXx0nONnkg1d1EA/9P7GXgnrFicl25M4s9hpA KmtUYjAXTb0WsP1oVd7bDWxwV9+tYkRhtMFSpr/HHEn/B1lKsHeD+jwzbta3T9w1gzic ISJriJyudk3XFOhxx9qAmrQMtXZbRLyQZ8cMlHNfee3bnHHRUNiloSMLvjdTufrGSNTk kUb4e/DFBGsC8ZEb0X6JzrSnp82Rgms+2FOcVqdeB5Gcc9afnAzrFz4mFiy4sE9xtvFR 5khDlptB+JV4mOXtYcWEEA9NOlsFkEICeJ8QNQsWs1g7rw0MErtwhT6pL0Kb2R6sZdL6 doUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=DP7QlfEiYJMcII1XUSErJqfTKyL09PW7/nVVxRh/YT8=; fh=6wcIAOV0zFj3GSfUQQIghU6UljCIfOgZO12Z578KSv0=; b=PJRJeyLB27YNgtC/wzbSXBQ3JGx7kk2l4U2CIYtoxIg1OazLqzovGl/XGd5YnNfvTf EFze0vnoCTAhd0NG4Z1f5Vl7a82zTRkqA/c+KAqYFGrytvezk7Hx9ebbJUdSn2moRkJ6 JVsK2U72Oe18IG+0yV4YhcCCp78LhBWjmbTRWvlUH7EupVklMM3NWrv7JwLqEzj+zmdg rdE+UuE6Fap3hbd9cyKBD9cgxZp6pfIAPaO7CwjIQgF7NNEEHLeGfWA45r/pKAuOKsNO G9MzqvtTPhRfYoeSPFaSlsxLmlanje3ae3YJ0uqGH8w0tE7R0Cjga6z4BeuGTY80SdTw CwZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=ancud.ru); spf=pass (google.com: domain of linux-kernel+bounces-121639-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121639-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b22-20020a63cf56000000b005dc498de156si11739988pgj.502.2024.03.27.10.12.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 10:12:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121639-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ancud.ru); spf=pass (google.com: domain of linux-kernel+bounces-121639-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121639-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 02996B27787 for ; Wed, 27 Mar 2024 16:37:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71E8D149E1F; Wed, 27 Mar 2024 16:37:39 +0000 (UTC) Received: from relay164.nicmail.ru (relay164.nicmail.ru [91.189.117.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 765ED12A14C; Wed, 27 Mar 2024 16:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.189.117.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711557459; cv=none; b=hyRE8iFtGQoKOXb/bmuK2VRiIi4bo0k5Ui+zToNjK7NKmcnIcRQcAiFQe9p700AxXZCQeBGB8Q4xhNHpiVkY8eYYhZOBn2ICs1BhssCVyW57t39J+OTkkQB2D15dYzjfzG15Ssl5U1hcoJhwoRgqSXX+EA6Q97vb+kIobW7T+vs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711557459; c=relaxed/simple; bh=5y86N3zhFqoBKloW781o02MUwINs71FpjLgTkfEec/g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W1TwUnc2Tcqs2wCR+/noHnoKkm7kt/hVRUkw17QN0FF41olZ2lP6KWXd7rFOi8MP4F3ridbCBEd3cV8FDuFGRsD7cORmsnWHJ79Y2f2Q4ZxyrKtwcGvABMahgU2LyQDOrfK6BwJwLCvvvyEbeN+bmOYGuVGcszXYEyHmW/GMXp8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ancud.ru; spf=pass smtp.mailfrom=ancud.ru; arc=none smtp.client-ip=91.189.117.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ancud.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ancud.ru Received: from [10.28.138.151] (port=43678 helo=mitx-gfx..) by relay.hosting.mail.nic.ru with esmtp (Exim 5.55) (envelope-from ) id 1rpWHF-0005Cr-Dk; Wed, 27 Mar 2024 19:37:25 +0300 Received: from [87.245.155.195] (account kiryushin@ancud.ru HELO mitx-gfx..) by incarp1103.mail.hosting.nic.ru (Exim 5.55) with id 1rpWHF-007K9y-0T; Wed, 27 Mar 2024 19:37:25 +0300 From: Nikita Kiryushin To: "Paul E. McKenney" Cc: Nikita Kiryushin , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH v2] rcu-tasks: Update show_rcu_tasks_trace_gp_kthread buffer size Date: Wed, 27 Mar 2024 19:36:56 +0300 Message-Id: <20240327163657.606414-1-kiryushin@ancud.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240326152230.3e692d83@gandalf.local.home> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MS-Exchange-Organization-SCL: -1 There is a possibility of buffer overflow in show_rcu_tasks_trace_gp_kthread() if counters, passed to sprintf() are huge. Counter numbers, needed for this are unrealistically high, but buffer overflow is still possible. Use snprintf() with buffer size instead of sprintf(). Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: edf3775f0ad6 ("rcu-tasks: Add count for idle tasks on offline CPUs") Signed-off-by: Nikita Kiryushin --- v2: Use snprintf() as Steven Rostedt suggested. kernel/rcu/tasks.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h index 147b5945d67a..963ecae3c8e6 100644 --- a/kernel/rcu/tasks.h +++ b/kernel/rcu/tasks.h @@ -1994,7 +1994,7 @@ void show_rcu_tasks_trace_gp_kthread(void) { char buf[64]; - sprintf(buf, "N%lu h:%lu/%lu/%lu", + snprintf(buf, ARRAY_SIZE(buf), "N%lu h:%lu/%lu/%lu", data_race(n_trc_holdouts), data_race(n_heavy_reader_ofl_updates), data_race(n_heavy_reader_updates), -- 2.34.1