Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1651410lqz; Mon, 1 Apr 2024 12:43:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXdGjvs6/rBdFz0FYPeJVBagBLYL+cWtjWyS9RNLV4OZHAEwKtiOg4oJmi8GNUoa4KBEK2VGlqAhtvvJtJA8H+JYaHuOTcj80mloisjSA== X-Google-Smtp-Source: AGHT+IEePB0F/Hhd80lU+NzB8vhJXkveBMB9FSFhEHyxff3+SHVJMccW+pdUS5tPFJY5ShcE0PZX X-Received: by 2002:a05:6402:2693:b0:56b:dd24:7b41 with SMTP id w19-20020a056402269300b0056bdd247b41mr10870604edd.3.1712000617366; Mon, 01 Apr 2024 12:43:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712000617; cv=pass; d=google.com; s=arc-20160816; b=kNOdck8rAoqmIYxjRTlHLgiU57/byNJBRbMfOPiEg18yNMJ3VJ6orR4gb4CUmPBo6f oDLhLFtnr3RaKpSZDOd1Icb9Ht8Jn2Q+zrBApDSCeJDEU27SOWv+oLbIb82iAf7sdPpY NYMr3IRJfhYNtWKP+BaLvcIqWvRawk3aeAw7CBN5CLhEHDYaqkosvyFsJssnBJPUqVa4 20OTvGTgtkpBOABozqoiI+d0lwzJOPY3bIq87ebxvhvF8HznJoNSX3z1nI3z7A/rCEzd wSzfuOj6j2KsPmeoQU3EI5W+xk7FcR1d2V6rv5Bl3onLgprxr2tuRVpFVQDrkVLvPBPv M+2Q== 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=fp1XFx9wO2kNp3TV7kOLCNVL2L6P6JOfv7ZDXp8CGvU=; fh=6wcIAOV0zFj3GSfUQQIghU6UljCIfOgZO12Z578KSv0=; b=lQ+ziHZ/96EfGStltxLZivVxWQd/Q8iad7aWoXrhdx980rw8mS5/AivvUlWOaoA0AR rIwja/BU2terh6iPq3D64HbVCCVnAwKoHJUbTrNDhjRJlSmVFgwFxFQ3QVxk2Vi7P6gE CucOXFIKCh4XWqzC4ssCWUPZtcN2lNDWvhK4eZQ2Nz7dsq3OMnQWffwQP7eWUENXV9Kl uMAMEcd3aZwpQsSVfMox4tMEoJpu3hRZ3lfF1e5w/e7MBmQY3MHncxsx6TR/W+bvoAWx WdASsC5vRM3E+3xyRxKjc1U4xtmzQTcxFRqwZmPOBADHWjzprCOZbwNYVwKXrZrFNqfe 8k8g==; 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-127002-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127002-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dz8-20020a0564021d4800b0056dc9260ac5si2007702edb.300.2024.04.01.12.43.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 12:43:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127002-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=ancud.ru); spf=pass (google.com: domain of linux-kernel+bounces-127002-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127002-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0D0981F21E1D for ; Mon, 1 Apr 2024 19:43:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04E195337E; Mon, 1 Apr 2024 19:43:30 +0000 (UTC) Received: from relay161.nicmail.ru (relay161.nicmail.ru [91.189.117.5]) (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 64A9217552; Mon, 1 Apr 2024 19:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.189.117.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712000609; cv=none; b=SyRQJnEkIO3cCOkSBxV7q6KSI4aF77o1mRRTL1DqHFe2sZBmAxWU3Mhk9jmFUQafq4Nocsbr6OkFrKScr6KvCcNjCq2X7nzWpMGvtfI/NMjPDEF0EY66OZzT6zC7272/EJljNYz79iyxaaK3GdpluAvAIji4ru5mKg0Mo4qPTpE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712000609; c=relaxed/simple; bh=1hhXYXzpBlVTWwZr+xCZLOOAx+sHm9NyPBQON64e5yI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CyRnEX193EPNHBDhY9ksBQLoC9+iM1FDlKSjJJP/5JjZaksz8WuRGHYLrFcBRdjiqrztI8XCUXpWsx0e0s8EVS6V68UOtJ2dOvN0ifaQtJtw2fLrAQgNjLQER2glUKTILiZmQj1J16BbdMyC3stDbLLSfAx+WD9LnP0boSfHBiI= 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.5 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=35640 helo=mitx-gfx..) by relay.hosting.mail.nic.ru with esmtp (Exim 5.55) (envelope-from ) id 1rrNYs-0004ov-5a; Mon, 01 Apr 2024 22:43:19 +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 1rrNYs-00FCtG-20; Mon, 01 Apr 2024 22:43:18 +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 v3] rcu: Fix buffer overlow in print_cpu_stall_info() Date: Mon, 1 Apr 2024 22:43:15 +0300 Message-Id: <20240401194315.362090-1-kiryushin@ancud.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240401150540.6dab14fc@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 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. This is intentional for debugging purposes, but it is not obvious from the code. Change sprintf to snprintf and add clarifying comment about intention of %ld 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 --- v3: Change intention comment wording as Steven Rostedt suggested v2: Remove signed to unsigned print format change as Paul E. McKenney suggested, add format intention clarification comment kernel/rcu/tree_stall.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h index 5d666428546b..320440b8384e 100644 --- a/kernel/rcu/tree_stall.h +++ b/kernel/rcu/tree_stall.h @@ -504,7 +504,8 @@ 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); + /* Print signed value, as negative means it is likely a bug */ + snprintf(buf, sizeof(buf), " rcuc=%ld 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