rcu: Fix buffer overflow in print_cpu_stall_info()
authorNikita Kiryushin <kiryushin@ancud.ru>
Mon, 1 Apr 2024 19:43:15 +0000 (22:43 +0300)
committerUladzislau Rezki (Sony) <urezki@gmail.com>
Mon, 15 Apr 2024 17:43:50 +0000 (19:43 +0200)
commit3758f7d9917bd7ef0482c4184c0ad673b4c4e069
tree79ddac1beff8b0e997fd00abb0e66eaa425c941c
parent80cd613a9ae091dbf52e27a409d58da988ffc8f3
rcu: Fix buffer overflow in print_cpu_stall_info()

The rcuc-starvation output from print_cpu_stall_info() might overflow the
buffer if there is a huge difference in jiffies difference.  The situation
might seem improbable, but computers sometimes get very confused about
time, which can result in full-sized integers, and, in this case,
buffer overflow.

Also, the unsigned jiffies difference is printed using %ld, which is
normally for signed integers.  This is intentional for debugging purposes,
but it is not obvious from the code.

This commit therefore changes sprintf() to snprintf() and adds a
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 <kiryushin@ancud.ru>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
kernel/rcu/tree_stall.h