Skip to content

Commit 3758f7d

Browse files
nkiryushinurezki
authored andcommitted
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: 245a629 ("rcu: Dump rcuc kthread status for CPUs not reporting quiescent state") Signed-off-by: Nikita Kiryushin <[email protected]> Reviewed-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Signed-off-by: Uladzislau Rezki (Sony) <[email protected]>
1 parent 80cd613 commit 3758f7d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/rcu/tree_stall.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ static void print_cpu_stall_info(int cpu)
504504
rcu_dynticks_in_eqs(rcu_dynticks_snap(cpu));
505505
rcuc_starved = rcu_is_rcuc_kthread_starving(rdp, &j);
506506
if (rcuc_starved)
507-
sprintf(buf, " rcuc=%ld jiffies(starved)", j);
507+
// Print signed value, as negative values indicate a probable bug.
508+
snprintf(buf, sizeof(buf), " rcuc=%ld jiffies(starved)", j);
508509
pr_err("\t%d-%c%c%c%c: (%lu %s) idle=%04x/%ld/%#lx softirq=%u/%u fqs=%ld%s%s\n",
509510
cpu,
510511
"O."[!!cpu_online(cpu)],

0 commit comments

Comments
 (0)