From patchwork Wed Mar 27 16:36:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Kiryushin X-Patchwork-Id: 13607071 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: rcu@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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),