[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211013102346.179642-6-laoar.shao@gmail.com>
Date: Wed, 13 Oct 2021 10:23:46 +0000
From: Yafang Shao <laoar.shao@...il.com>
To: keescook@...omium.org, rostedt@...dmis.org, peterz@...radead.org,
pmladek@...e.com, viro@...iv.linux.org.uk,
akpm@...ux-foundation.org, valentin.schneider@....com,
mathieu.desnoyers@...icios.com, qiang.zhang@...driver.com,
robdclark@...omium.org, christian@...uner.io,
dietmar.eggemann@....com, mingo@...hat.com, juri.lelli@...hat.com,
vincent.guittot@...aro.org, bsegall@...gle.com, mgorman@...e.de,
bristot@...hat.com, davem@...emloft.net, kuba@...nel.org
Cc: linux-kernel@...r.kernel.org, Yafang Shao <laoar.shao@...il.com>
Subject: [PATCH v4 5/5] kernel/kthread: show a warning if kthread's comm is truncated
Show a warning if task comm is truncated. Below is the result
of my test case:
truncated kthread comm:I-am-a-kthread-with-lon, pid:14 by 6 characters
Suggested-by: Petr Mladek <pmladek@...e.com>
Signed-off-by: Yafang Shao <laoar.shao@...il.com>
Reviewed-by: Kees Cook <keescook@...omium.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: Al Viro <viro@...iv.linux.org.uk>
Cc: Petr Mladek <pmladek@...e.com>
---
kernel/kthread.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 5b37a8567168..46b924c92078 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -399,12 +399,17 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
if (!IS_ERR(task)) {
static const struct sched_param param = { .sched_priority = 0 };
char name[TASK_COMM_LEN];
+ int len;
/*
* task is already visible to other tasks, so updating
* COMM must be protected.
*/
- vsnprintf(name, sizeof(name), namefmt, args);
+ len = vsnprintf(name, sizeof(name), namefmt, args);
+ if (len >= TASK_COMM_LEN) {
+ pr_warn("truncated kthread comm:%s, pid:%d by %d characters\n",
+ name, task->pid, len - TASK_COMM_LEN + 1);
+ }
set_task_comm(task, name);
/*
* root may have changed our (kthreadd's) priority or CPU mask.
--
2.17.1
Powered by blists - more mailing lists