All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rcu: Fix buffer overlow in print_cpu_stall_info()
@ 2024-03-28 18:19 Nikita Kiryushin
  2024-03-29 17:43 ` Paul E. McKenney
  0 siblings, 1 reply; 10+ messages in thread
From: Nikita Kiryushin @ 2024-03-28 18:19 UTC (permalink / raw)
  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, linux-kernel,
	lvc-project

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 <kiryushin@ancud.ru>
---
 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-04-01 20:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 18:19 [PATCH] rcu: Fix buffer overlow in print_cpu_stall_info() Nikita Kiryushin
2024-03-29 17:43 ` Paul E. McKenney
2024-03-29 17:56   ` Nikita Kiryushin
2024-03-29 18:32     ` Steven Rostedt
2024-03-29 22:21       ` Paul E. McKenney
2024-04-01 18:54         ` [PATCH v2] " Nikita Kiryushin
2024-04-01 19:05           ` Steven Rostedt
2024-04-01 19:43             ` [PATCH v3] " Nikita Kiryushin
2024-04-01 20:03               ` Steven Rostedt
2024-04-01 20:54                 ` Paul E. McKenney

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.