[PATCH] sched/core: Replace sprintf() with scnprintf() in init_idle()
From: Ziran Zhang
Date: Mon Jun 08 2026 - 04:54:26 EST
The kernel documentation notes that sprintf() is deprecated and unsafe.
Replace the deprecated sprintf() with the bounded scnprintf() when
formatting the idle task's comm. This prevents a potential buffer
overflow if INIT_TASK_COMM or the CPU number ever grow beyond the
remaining space in the 16‑byte comm field.
Signed-off-by: Ziran Zhang <zhangcoder@xxxxxxxx>
---
kernel/sched/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a2f86807f..215b241af 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8302,7 +8302,7 @@ void __init init_idle(struct task_struct *idle, int cpu)
idle->sched_class = &idle_sched_class;
ftrace_graph_init_idle_task(idle, cpu);
vtime_init_idle(idle, cpu);
- sprintf(idle->comm, "%s/%d", INIT_TASK_COMM, cpu);
+ scnprintf(idle->comm, sizeof(idle->comm), "%s/%d", INIT_TASK_COMM, cpu);
}
int cpuset_cpumask_can_shrink(const struct cpumask *cur,
--
2.43.0