Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1658679lqz; Mon, 1 Apr 2024 13:01:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVD5+CoYjKUAI+Q2XVW9jffZ3oEpI2g+eLt25ZEIkr1SL7sWjdE57D8AJOKIlW6x+e0BjraXbB2/Hrvf85Slnlf3X9rz6whY8xqdCsrJQ== X-Google-Smtp-Source: AGHT+IHVH7E5ApehR1l2dVl7aMJv/Swm/zEDRq2YpPJBXX9ooh7dUw9nW5svUZ6/iW8dP5ddaeeW X-Received: by 2002:a17:906:f10c:b0:a4e:3a09:4854 with SMTP id gv12-20020a170906f10c00b00a4e3a094854mr5681085ejb.61.1712001665985; Mon, 01 Apr 2024 13:01:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712001665; cv=pass; d=google.com; s=arc-20160816; b=nc+TKk9cjB/+meXyZ/9sst/+2OpBKM2gL7XO0ryI7fiGl+k6OFN1ye3yEGe6B36uSm C4L2slOYX3ngRMZ0FfGfB1JFXwmK50IV+3rUR7MGAzv+cpN+ByngmOFOvA3YLzSIBFrG 0BjsIwvuMCoG5vcOUJDnpHSuixzbIIw4OOvVsJn7Z3Ikr0YsvBqSuiNGwm8CJD1+erDS 6RBZ1I3OpAZfpazdQbTEn59CrT8E11x6gZvLuLPjRyR7lve08uHZaAv4gdw9fozDaFAS boikJ9t6ifIfaJW5B8JPIAoQhKjpUGfAcTPJ/m8b3ATKkt584GqdoFGGUxV4Vl+KCJuF QJDg== 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 :subject:cc:to:from:date; bh=ClMM4xiiH/vM6Sldm+Aj73hsH4ySAj2Q/Bgiu8Z44YY=; fh=zAUkigIGTTE7dxx1DJDd9oZxIPWaYZ/TEN69uW81kbs=; b=hqsikdx/av2l97pwuvzgkEi4AbhPCCbeLaZb6zR/kC+Nkwl5Z4GGcws54GxIWwt2zq 3mQyO5+jjeeyRVVHdXHW6kxmnO5M6fNpkToKnJylRgaRQXgtR6dOM6tmSmfGUG7xXAZs vl+5R77oybvIYp/QrMapBwmOBe2G3T10ybx8vS2mDFu/jAwVcTGjRWfPh8vG9hddPLnd N8z5F5SIoGnLVb9jCJYLXBnkGXQF9CnbQZQY6V6G7KyvAuJsYB78cVdkPzE6CybJCe8l Uz/Rirup6hSyMPFVcx6pIw9zFD8dJpLZH+cboluuAFzcnqdSFBPj72PtNrw6LpMEQvOQ CDgw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-127015-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127015-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 ko11-20020a170906aa0b00b00a4649541994si4844610ejb.654.2024.04.01.13.01.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 13:01:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127015-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 (google.com: domain of linux-kernel+bounces-127015-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127015-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 B38991F21A1C for ; Mon, 1 Apr 2024 20:01:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 574E553819; Mon, 1 Apr 2024 20:00:59 +0000 (UTC) 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 D2E713D9E; Mon, 1 Apr 2024 20:00:58 +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=1712001658; cv=none; b=V+q5mATktvSGNj9izHL8YJJbMIdAqq1oHN0z8MQHfC1/JJAbHtrvEP8yqF28KI6Vtk3JHUOc/L1zNfHLu2MF003nV0EN5HXsnxMFLnEd9G2Ku703KCprVxtSOFUQk1NNKNPtfOf277rAi456Cn8p1MoICGpukou8+8vi6Dmgtt8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712001658; c=relaxed/simple; bh=VOBnvpteYLOm2apkTlbfYOwoE5UU50XDzaYsVhOdiwM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uwZzNqils3Czf8XEe3xWYyEha0YmsZfvFPEB/5fz3oX9Cil1d9jf2zgyfT0MKP5bTSL1Qh9b6m+jdWBFIM6UfIYcgH3BfC1eS/9h3VpCVidhaltZiNBfeENa72HSCr5XkRtlAmUi6pjZbBcn5B0S5zVQlIIutd6Mh+Vz0uoOG/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 062C2C433F1; Mon, 1 Apr 2024 20:00:56 +0000 (UTC) Date: Mon, 1 Apr 2024 16:03:12 -0400 From: Steven Rostedt To: Nikita Kiryushin Cc: "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Mathieu Desnoyers , Lai Jiangshan , Zqiang , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: Re: [PATCH v3] rcu: Fix buffer overlow in print_cpu_stall_info() Message-ID: <20240401160312.7b03e568@gandalf.local.home> In-Reply-To: <20240401194315.362090-1-kiryushin@ancud.ru> References: <20240401150540.6dab14fc@gandalf.local.home> <20240401194315.362090-1-kiryushin@ancud.ru> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Mon, 1 Apr 2024 22:43:15 +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. 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)], Reviewed-by: Steven Rostedt (Google) -- Steve