* [PATCH] sched/core: Replace sprintf() with scnprintf() in init_idle()
@ 2026-06-08 8:40 Ziran Zhang
0 siblings, 0 replies; only message in thread
From: Ziran Zhang @ 2026-06-08 8:40 UTC (permalink / raw)
To: Ingo Molnar, Peter Zijlstra
Cc: Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
linux-kernel, Ziran Zhang
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@yeah.net>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-06-08 8:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-08 8:40 [PATCH] sched/core: Replace sprintf() with scnprintf() in init_idle() Ziran Zhang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.