Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp629131lqh; Thu, 28 Mar 2024 11:20:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVpEgaCDN+kY2r3QgvkCRfzVEC0GUucgS/ox3k3Xal0bYFfUzouWsUlY5nb7DxnDlO9cIzVfdwKevJUuAwbASlchkmVnKEpnt+hKIcKUA== X-Google-Smtp-Source: AGHT+IGpwV4qAWXn29bRW7ddV6kkgUR2YIgtdzsVVUGYsJDEfvvKapXiJNrz+jaLWX7+plXpyPyq X-Received: by 2002:a05:620a:468e:b0:78a:64b4:95ee with SMTP id bq14-20020a05620a468e00b0078a64b495eemr435253qkb.37.1711649999809; Thu, 28 Mar 2024 11:19:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711649999; cv=pass; d=google.com; s=arc-20160816; b=wG5uZOhNzU+xxSoZExCA9j3/0VeKhimBFurHVBAr4g4E9rf5Oazs/+TzRv+uI2BorB SynbOf7yPXTKCmvZZgRWrjiFY40B0K/u+gYOL9A6NS+DydN0VzXABo4qU7IdK9euRgtH OF6WtLQGZUagSNoaHLOVBuw4WRB47rCBTiPbPzVFWGjXO65Qseqa2ZsVBn11z+Mt7ySW ZAn2GwmTNMGJq8MlSw4cRY4ac0GrL5oXCLZR79BQ3aZU0OdTj3A3+eI46pONdZev9w3k e+PC4TyG3cNy8zqfceJDaSxArpA+UsB0KmeDUsEr0Zleh01V2g7PbcXc4o9xulD7labw 9qUw== 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:message-id:date:subject:cc:to :from; bh=lYPglVly/bAn0gZULr64bKGgGmQJ5I14hmsAw610w+U=; fh=6wcIAOV0zFj3GSfUQQIghU6UljCIfOgZO12Z578KSv0=; b=dY8eSq48ZWWyPczgWjndD2la3UvZC4yTIwbDUiQhNo5nJ3YadJCduf32sNkgaJsAt6 eH8qE/2NCZ2x+MW3lLfE0t2dhLSrUae9NgabhL71Hr5cvd9Qn9vQsJesVVluUiwCRvIr qJYsN9/l76QGi/eeQbmt4yypg9gcJ3BZPMbT8qULDzF8QXnOK68sqNUVdFLKoMuQ6z9c 5xVUXcOZ6dTYehkj0i8qI5qLTtMg/lzyygWXfZE5zwdjUA3o/R+xAwIrimsgWFHmydUO AWZ7HvjOyuGldEbVJeEJu53+3I5ssDjDQo6y5wa0yiEzqDGgRLOSbL4hHuV4Ks9S43D2 CPqg==; 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-123409-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123409-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pc4-20020a05620a840400b00789f61e3e39si1892181qkn.74.2024.03.28.11.19.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 11:19:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123409-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ancud.ru); spf=pass (google.com: domain of linux-kernel+bounces-123409-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123409-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8606E1C241ED for ; Thu, 28 Mar 2024 18:19:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 616C81304B9; Thu, 28 Mar 2024 18:19:54 +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 0709B1879; Thu, 28 Mar 2024 18:19:48 +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=1711649993; cv=none; b=dUy5oMO5YFvV6C4rRPekf3naXWfH0lt2RNLurq13k58Ic0CCCycj1//2xIQXeXbQKwuTC/8XdO1UuitV7Wcc6M6k4Z7PYdRlyw6OS/FpL8wvJX0bw+Iy6MyA2xh2YT48hh+Mb02MqwSHi2kLTqdlBeCnqkD/9XcXh2ZwlWKVWRU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711649993; c=relaxed/simple; bh=/0iYGmx0+L/9J0BF+wBfl+vJ657RoLBgKRvZRDBFOQw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=oDUZcuyF2Wlvhnq26a6ibYd2DfOJggRLjlutMeCXjk/R3cF3wGIaPjyT23Vhfy/f3xT/tUTeWMLUriuHtunvg97kiKZpAWcStV2PxLZ+4I61AK6a76Ve2rETqm9R7gEioBHFHi86zMtntHVUGtmL9Dt4byUX5gf/r/muD9IlJ2M= 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.149] (port=41536 helo=mitx-gfx..) by relay.hosting.mail.nic.ru with esmtp (Exim 5.55) (envelope-from ) id 1rpuLh-0004jl-D2; Thu, 28 Mar 2024 21:19:37 +0300 Received: from [87.245.155.195] (account kiryushin@ancud.ru HELO mitx-gfx..) by incarp1102.mail.hosting.nic.ru (Exim 5.55) with id 1rpuLg-00BqTj-30; Thu, 28 Mar 2024 21:19:37 +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] rcu: Fix buffer overlow in print_cpu_stall_info() Date: Thu, 28 Mar 2024 21:19:14 +0300 Message-Id: <20240328181914.869332-1-kiryushin@ancud.ru> X-Mailer: git-send-email 2.34.1 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 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. 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