All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ziran Zhang <zhangcoder@yeah.net>
To: Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	linux-kernel@vger.kernel.org, Ziran Zhang <zhangcoder@yeah.net>
Subject: [PATCH] sched/core: Replace sprintf() with scnprintf() in init_idle()
Date: Mon,  8 Jun 2026 16:40:32 +0800	[thread overview]
Message-ID: <20260608084032.6883-1-zhangcoder@yeah.net> (raw)

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


                 reply	other threads:[~2026-06-08  8:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260608084032.6883-1-zhangcoder@yeah.net \
    --to=zhangcoder@yeah.net \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.