Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp130248lqz; Fri, 29 Mar 2024 10:44:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVpkCD1Z0JJeTJw7/9nU2skA3YU3CBMTScod/X6c19JRgmUd6f+N4Zrp4ZfL6sVw+zVEyWn/nhBh48VMhKD2h3+wnwrZ7rvnBDvvMd+5w== X-Google-Smtp-Source: AGHT+IHFs9rQPsyy7dYJ9Fysqo8vwceueGrF5UAiTx6A9tHGacqSBWGGtD1amqe6nYhp4UqGrfPv X-Received: by 2002:a05:6a20:7d9f:b0:1a3:6817:1b02 with SMTP id v31-20020a056a207d9f00b001a368171b02mr2858146pzj.55.1711734253056; Fri, 29 Mar 2024 10:44:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711734253; cv=pass; d=google.com; s=arc-20160816; b=L3semxd0BjHmZkSGWqo0/z+Qpi8eQAsUYFaGvtFA/4wflE3oLgqJtmhK2y7DT5DUeE 9BmxqRUpMhRlxVv7jafTNtc5PD3RZ8FO+f56nqE7RqWGd7h+1cGgG34NMcCIRKpY2bXD 4HQXAe4smK58NiGe2ovbHylhjkcytR4meBk9X/ss24l6LyQa3Lh3b4v7PNyEMEsdGXKE LZQ0zSwjC6EwR3aFW7l7uxZwIH9/af5Suc0lAUj/6+WG+WvzQzsmG0pqf1YezTFbG90Y Z7dH+DI0KL+p0+v0SriM2D+qYypOSvps8YYolbjNyWBxQiqIpSHTg8yAdRuacVS8F9PA tpAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=myPFNu7gaHO9cKT/1GF4YIZn33+Hk0qB+eVGjnbTXLU=; fh=0iV7TnsrjKTXS/CVhj51GeJuqs7vPEXJ46rHhCo1Fqk=; b=I1Yw775130l06p8IwJK19kmnG8SQvXDRzGJbVFoVgkiUv2YxYJtziEI3IRwFb1XWAz k4W67vxYI0WbjKvAazBY8GwiKaKnMFGGBtXVaj1HtrbwsWsi8PUcROCcTAaRrqYBhb6i Z/fNOKGIzPZ14B5n5NKBU6bhlYhRFiL1eAjfn9k0fhPe8BB2c69XCUOUX/n7CEjutCFc Y16hyKBuJwgqrrA3voNh2YCi+jVJJn2nx8f1Ocd7N0u5KMvs/3YKEtn/gJu1HvFwNapi XcTtBdlOQFuIJtuO6kywRNp/XytHoy30usBT/yHzROn+xVpg7S/Tn4Wf3DoAU1Zh0HJH GdFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FDbRbDvt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-125260-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125260-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e1-20020a17090a6f8100b002a0ce297d75si6080678pjk.151.2024.03.29.10.44.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 10:44:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-125260-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FDbRbDvt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-125260-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125260-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E63E3289607 for ; Fri, 29 Mar 2024 17:43:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A4EA136E07; Fri, 29 Mar 2024 17:43:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FDbRbDvt" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A827B134735; Fri, 29 Mar 2024 17:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711734215; cv=none; b=IlaUpTHwN4jqN3wnT1dB+j5rLst9iBBqlzrBmjpZxMCpaZDHuSCBzz2Cq5BddZdZtLdofDn2moUV72tIeHXtdyV6EI7ZsI8XTH5bL9rMSq+sIn7lFA/ZMAGo33V6mKN9dryHC23ZQEzXntj655PwhARrl+dmWRjIF82aaS8MjZ4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711734215; c=relaxed/simple; bh=i7ypJ+h9Bw+WA9umKwnPpvNeTvx1AFolPnPPaG1KPlY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=naQTjwNaloEphCWYkd74bCrKht2c6XLjp9y1M/3HCBQVo2qSTUSzkSTCyuI546cWL/rEcUhgaFguOnaCGJ3oG07hBc2XuYTIAu1AcqR/hG2dKxluYqHcMH11XW2QCh0qq4+17DeGjXY7mE3FCBu7NodnY7Ou74WUArmpl3lzf3o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FDbRbDvt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2525BC43390; Fri, 29 Mar 2024 17:43:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711734215; bh=i7ypJ+h9Bw+WA9umKwnPpvNeTvx1AFolPnPPaG1KPlY=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=FDbRbDvtrWVzbVluRY9xqDd86vF2Hw4E8XTZXXbd7UF+Rq5CARUVXAEiBZrP2CRD3 nVA+VB37mCCvd/swJiRSjsuX/GNjZ03BupMizhW+Rwkta0Kon+23YVfZt2U/7xAcQH VhLaUZe2JkcTDn49GzTKtbwVXm422j+1XLrBfaRkn8WYQN3OE+bASor1Fj4WpTmeyI OBg5Xyink4NwiQdrgtbJLGZAYZiCQIgeWf1rHmiqeeXCHgtuBha6YwgZXrm60biuWN g+SgucBDdi0nfL4ZoXWdVJ8bD2V/9AfdgUlKNAjkWd5AusiBlTlKHqpa+OHiDVf8OY lDQ77v7gnQbog== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 9B63FCE0EE1; Fri, 29 Mar 2024 10:43:33 -0700 (PDT) Date: Fri, 29 Mar 2024 10:43:33 -0700 From: "Paul E. McKenney" To: Nikita Kiryushin Cc: 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: Re: [PATCH] rcu: Fix buffer overlow in print_cpu_stall_info() Message-ID: Reply-To: paulmck@kernel.org References: <20240328181914.869332-1-kiryushin@ancud.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240328181914.869332-1-kiryushin@ancud.ru> On Thu, Mar 28, 2024 at 09:19:14PM +0300, Nikita Kiryushin wrote: > rcuc info output in print_cpu_stall_info() contains > posiible buffer overflow in the case of huge jiffies > difference. The situation seems improbable, but, buffer > overflow, still. Also, unsigned jiffies difference printed > as (signed) %ld (which can be a bad format, if the values > are huge). > > Change sprintf to snprintf and change %ld to %lu in format. Good catch!!! However, the signed output is intentional. The idea is that if the timekeeping code is confused enough to run the jiffies counter backwards, we see a small negative number rather than a huge positive number. For example, -132 is immediately obvious, while the 64-bit unsigned equivalent of 18446744073709551484 might not be. would you like to resend keeping the buffer-overflow fix but leaving out the signed-to-unsigned conversion? Thanx, Paul > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Fixes: 245a62982502 ("rcu: Dump rcuc kthread status for CPUs not reporting quiescent state") > Signed-off-by: Nikita Kiryushin > --- > kernel/rcu/tree_stall.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h > index 5d666428546b..d4542c6e7c60 100644 > --- a/kernel/rcu/tree_stall.h > +++ b/kernel/rcu/tree_stall.h > @@ -504,7 +504,7 @@ static void print_cpu_stall_info(int cpu) > rcu_dynticks_in_eqs(rcu_dynticks_snap(cpu)); > rcuc_starved = rcu_is_rcuc_kthread_starving(rdp, &j); > if (rcuc_starved) > - sprintf(buf, " rcuc=%ld jiffies(starved)", j); > + snprintf(buf, sizeof(buf), " rcuc=%lu jiffies(starved)", j); > pr_err("\t%d-%c%c%c%c: (%lu %s) idle=%04x/%ld/%#lx softirq=%u/%u fqs=%ld%s%s\n", > cpu, > "O."[!!cpu_online(cpu)], > -- > 2.34.1 >