Re: [PATCH v2] rcu: Fix buffer overlow in print_cpu_stall_info()

From: Steven Rostedt
Date: Mon Apr 01 2024 - 15:03:31 EST


On Mon, 1 Apr 2024 21:54:54 +0300
Nikita Kiryushin <kiryushin@xxxxxxxx> wrote:

> --- 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);
> + /* %ld is intentional, for easier bug detection */

The above still has assumptions of what is going on for the reviewer.
I would suggest something a bit more obvious like:

/* 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",

-- Steve