Skip to contentSkip to conversation

sched/core: Replace sprintf() with scnprintf() in init_idle()

PATCH New Ziran Zhang 1 participant 1 message Jun 8 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/core: Replace sprintf() with scnprintf() in init_idle()

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.

---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/core.c +1 -1
index a2f86807f..215b241af 100644
@@ -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,
Signature · 1 line
2.43.0